2011-03-28 14:21:28 +00:00
|
|
|
<?
|
2013-05-01 08:00:16 +00:00
|
|
|
if (!check_perms('torrents_edit')) {
|
|
|
|
error(403);
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
$GroupID = $_POST['groupid'];
|
|
|
|
$OldGroupID = $GroupID;
|
|
|
|
$NewGroupID = db_string($_POST['targetgroupid']);
|
|
|
|
|
2013-05-01 08:00:16 +00:00
|
|
|
if (!$GroupID || !is_number($GroupID)) {
|
|
|
|
error(404);
|
|
|
|
}
|
|
|
|
if (!$NewGroupID || !is_number($NewGroupID)) {
|
|
|
|
error(404);
|
|
|
|
}
|
|
|
|
if ($NewGroupID == $GroupID) {
|
2011-03-28 14:21:28 +00:00
|
|
|
error('Old group ID is the same as new group ID!');
|
|
|
|
}
|
2013-07-04 08:00:56 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT CategoryID, Name
|
|
|
|
FROM torrents_group
|
|
|
|
WHERE ID = '$NewGroupID'");
|
2013-07-10 00:08:53 +00:00
|
|
|
if (!$DB->has_results()) {
|
2011-03-28 14:21:28 +00:00
|
|
|
error('Target group does not exist.');
|
|
|
|
}
|
2011-05-22 08:00:06 +00:00
|
|
|
list($CategoryID, $NewName) = $DB->next_record();
|
2013-05-01 08:00:16 +00:00
|
|
|
if ($Categories[$CategoryID - 1] != 'Music') {
|
2011-05-22 08:00:06 +00:00
|
|
|
error('Only music groups can be merged.');
|
|
|
|
}
|
2012-01-24 08:00:19 +00:00
|
|
|
|
2013-07-04 08:00:56 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT Name
|
|
|
|
FROM torrents_group
|
|
|
|
WHERE ID = $GroupID");
|
2012-01-24 08:00:19 +00:00
|
|
|
list($Name) = $DB->next_record();
|
|
|
|
|
2013-07-04 08:00:56 +00:00
|
|
|
// Everything is legit, let's just confim they're not retarded
|
2013-05-01 08:00:16 +00:00
|
|
|
if (empty($_POST['confirm'])) {
|
2012-10-11 08:00:15 +00:00
|
|
|
$Artists = Artists::get_artists(array($GroupID, $NewGroupID));
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2012-10-11 08:00:15 +00:00
|
|
|
View::show_header();
|
2011-03-28 14:21:28 +00:00
|
|
|
?>
|
|
|
|
<div class="center thin">
|
2012-08-19 08:00:19 +00:00
|
|
|
<div class="header">
|
|
|
|
<h2>Merge Confirm!</h2>
|
|
|
|
</div>
|
2011-03-28 14:21:28 +00:00
|
|
|
<div class="box pad">
|
2012-09-15 08:00:25 +00:00
|
|
|
<form class="confirm_form" name="torrent_group" action="torrents.php" method="post">
|
2011-03-28 14:21:28 +00:00
|
|
|
<input type="hidden" name="action" value="merge" />
|
|
|
|
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
|
|
|
|
<input type="hidden" name="confirm" value="true" />
|
|
|
|
<input type="hidden" name="groupid" value="<?=$GroupID?>" />
|
|
|
|
<input type="hidden" name="targetgroupid" value="<?=$NewGroupID?>" />
|
2012-08-19 08:00:19 +00:00
|
|
|
<h3>You are attempting to merge the group:</h3>
|
2013-07-04 08:00:56 +00:00
|
|
|
<ul>
|
|
|
|
<li><?= Artists::display_artists($Artists[$GroupID], true, false)?> - <a href="torrents.php?id=<?=$GroupID?>"><?=$Name?></a></li>
|
|
|
|
</ul>
|
2012-08-19 08:00:19 +00:00
|
|
|
<h3>Into the group:</h3>
|
2013-07-04 08:00:56 +00:00
|
|
|
<ul>
|
|
|
|
<li><?= Artists::display_artists($Artists[$NewGroupID], true, false)?> - <a href="torrents.php?id=<?=$NewGroupID?>"><?=$NewName?></a></li>
|
|
|
|
</ul>
|
2011-03-28 14:21:28 +00:00
|
|
|
<input type="submit" value="Confirm" />
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<?
|
2012-10-11 08:00:15 +00:00
|
|
|
View::show_footer();
|
2011-03-28 14:21:28 +00:00
|
|
|
} else {
|
|
|
|
authorize();
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-02-07 08:00:47 +00:00
|
|
|
// Votes ninjutsu. This is so annoyingly complicated.
|
2012-10-30 08:00:18 +00:00
|
|
|
// 1. Get a list of everybody who voted on the old group and clear their cache keys
|
2013-07-04 08:00:56 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT UserID
|
|
|
|
FROM users_votes
|
|
|
|
WHERE GroupID = '$GroupID'");
|
2012-10-30 08:00:18 +00:00
|
|
|
while (list($UserID) = $DB->next_record()) {
|
2013-07-04 08:00:56 +00:00
|
|
|
$Cache->delete_value("voted_albums_$UserID");
|
2012-10-30 08:00:18 +00:00
|
|
|
}
|
|
|
|
// 2. Update the existing votes where possible, clear out the duplicates left by key
|
|
|
|
// conflicts, and update the torrents_votes table
|
2013-07-04 08:00:56 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE IGNORE users_votes
|
|
|
|
SET GroupID = '$NewGroupID'
|
|
|
|
WHERE GroupID = '$GroupID'");
|
|
|
|
$DB->query("
|
|
|
|
DELETE FROM users_votes
|
|
|
|
WHERE GroupID = '$GroupID'");
|
|
|
|
$DB->query("
|
|
|
|
INSERT INTO torrents_votes (GroupID, Ups, Total, Score)
|
|
|
|
SELECT $NewGroupID, UpVotes, TotalVotes, VoteScore
|
|
|
|
FROM (
|
|
|
|
SELECT
|
|
|
|
IFNULL(SUM(IF(Type = 'Up', 1, 0)), 0) As UpVotes,
|
|
|
|
COUNT(1) AS TotalVotes,
|
|
|
|
binomial_ci(IFNULL(SUM(IF(Type = 'Up', 1, 0)), 0), COUNT(1)) AS VoteScore
|
|
|
|
FROM users_votes
|
|
|
|
WHERE GroupID = $NewGroupID
|
|
|
|
GROUP BY GroupID
|
|
|
|
) AS a
|
|
|
|
ON DUPLICATE KEY UPDATE
|
|
|
|
Ups = a.UpVotes,
|
|
|
|
Total = a.TotalVotes,
|
|
|
|
Score = a.VoteScore;");
|
2012-10-30 08:00:18 +00:00
|
|
|
// 3. Clear the votes_pairs keys!
|
2013-07-04 08:00:56 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT v2.GroupID
|
|
|
|
FROM users_votes AS v1
|
|
|
|
INNER JOIN users_votes AS v2 USING (UserID)
|
|
|
|
WHERE (v1.Type = 'Up' OR v2.Type = 'Up')
|
|
|
|
AND (v1.GroupID IN($GroupID, $NewGroupID))
|
|
|
|
AND (v2.GroupID NOT IN($GroupID, $NewGroupID));");
|
2012-10-30 08:00:18 +00:00
|
|
|
while (list($CacheGroupID) = $DB->next_record()) {
|
2013-07-04 08:00:56 +00:00
|
|
|
$Cache->delete_value("vote_pairs_$CacheGroupID");
|
2012-10-30 08:00:18 +00:00
|
|
|
}
|
|
|
|
// 4. Clear the new groups vote keys
|
2013-07-04 08:00:56 +00:00
|
|
|
$Cache->delete_value("votes_$NewGroupID");
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2013-07-04 08:00:56 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE torrents
|
|
|
|
SET GroupID = '$NewGroupID'
|
|
|
|
WHERE GroupID = '$GroupID'");
|
|
|
|
$DB->query("
|
|
|
|
UPDATE wiki_torrents
|
|
|
|
SET PageID = '$NewGroupID'
|
|
|
|
WHERE PageID = '$GroupID'");
|
|
|
|
$DB->query("
|
|
|
|
UPDATE torrents_comments
|
|
|
|
SET GroupID = '$NewGroupID'
|
|
|
|
WHERE GroupID = '$GroupID'");
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2012-10-11 08:00:15 +00:00
|
|
|
Torrents::delete_group($GroupID);
|
2012-01-24 08:00:19 +00:00
|
|
|
|
2013-07-04 08:00:56 +00:00
|
|
|
Torrents::write_group_log($NewGroupID, 0, $LoggedUser['ID'], "Merged Group $GroupID ($Name) to $NewGroupID ($NewName)", 0);
|
|
|
|
$DB->query("
|
|
|
|
UPDATE group_log
|
|
|
|
SET GroupID = $NewGroupID
|
|
|
|
WHERE GroupID = $GroupID");
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-07-04 08:00:56 +00:00
|
|
|
$GroupID = $NewGroupID;
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
//Collages
|
2013-07-04 08:00:56 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT CollageID
|
|
|
|
FROM collages_torrents
|
|
|
|
WHERE GroupID = '$OldGroupID'"); // Select all collages that contain edited group
|
2013-05-06 08:00:32 +00:00
|
|
|
while (list($CollageID) = $DB->next_record()) {
|
2013-07-04 08:00:56 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE IGNORE collages_torrents
|
|
|
|
SET GroupID = '$NewGroupID'
|
|
|
|
WHERE GroupID = '$OldGroupID'
|
|
|
|
AND CollageID = '$CollageID'"); // Change collage group ID to new ID
|
|
|
|
$DB->query("
|
|
|
|
DELETE FROM collages_torrents
|
|
|
|
WHERE GroupID = '$OldGroupID'
|
|
|
|
AND CollageID = '$CollageID'");
|
|
|
|
$Cache->delete_value("collage_$CollageID");
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
2013-07-04 08:00:56 +00:00
|
|
|
$Cache->delete_value("torrent_collages_$NewGroupID");
|
|
|
|
$Cache->delete_value("torrent_collages_personal_$NewGroupID");
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-07-04 08:00:56 +00:00
|
|
|
// Requests
|
|
|
|
$DB->query("
|
|
|
|
SELECT ID
|
|
|
|
FROM requests
|
|
|
|
WHERE GroupID = '$OldGroupID'");
|
2012-02-20 08:00:22 +00:00
|
|
|
$Requests = $DB->collect('ID');
|
2013-07-04 08:00:56 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE requests
|
|
|
|
SET GroupID = 'NewGroupID'
|
|
|
|
WHERE GroupID = '$OldGroupID'");
|
2012-02-20 08:00:22 +00:00
|
|
|
foreach ($Requests as $RequestID) {
|
2013-07-04 08:00:56 +00:00
|
|
|
$Cache->delete_value("request_$RequestID");
|
2012-02-20 08:00:22 +00:00
|
|
|
}
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-07-04 08:00:56 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT ID
|
|
|
|
FROM torrents
|
|
|
|
WHERE GroupID = '$OldGroupID'");
|
2013-05-06 08:00:32 +00:00
|
|
|
while (list($TorrentID) = $DB->next_record()) {
|
2013-07-04 08:00:56 +00:00
|
|
|
$Cache->delete_value("torrent_download_$TorrentID");
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
2013-07-04 08:00:56 +00:00
|
|
|
$Cache->delete_value("torrents_details_$GroupID");
|
|
|
|
$Cache->delete_value("torrent_comments_{$GroupID}_catalogue_0");
|
|
|
|
$Cache->delete_value("torrent_comments_$GroupID");
|
|
|
|
$Cache->delete_value("groups_artists_$GroupID");
|
2012-10-11 08:00:15 +00:00
|
|
|
Torrents::update_hash($GroupID);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-07-04 08:00:56 +00:00
|
|
|
header("Location: torrents.php?id=" . $GroupID);
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
2013-02-07 08:00:47 +00:00
|
|
|
?>
|