2013-07-13 08:00:46 +00:00
|
|
|
<?php
|
2011-03-28 14:21:28 +00:00
|
|
|
/****************************************************************
|
|
|
|
*--------------[ Rename artist ]-----------------------------*
|
2013-07-13 08:00:46 +00:00
|
|
|
* This page handles the backend of the 'rename artist' *
|
|
|
|
* feature. It is quite resource intensive, which is okay *
|
|
|
|
* since it's rarely used. *
|
|
|
|
* *
|
|
|
|
* If there is no artist with the target name, it simply *
|
|
|
|
* renames the artist. However, if there is an artist with the *
|
|
|
|
* target name, things gut funky - the artists must be merged, *
|
|
|
|
* along with their torrents. *
|
|
|
|
* *
|
|
|
|
* In the event of a merger, the description of THE TARGET *
|
|
|
|
* ARTIST will be used as the description of the final result. *
|
|
|
|
* The same applies for torrents. *
|
|
|
|
* *
|
|
|
|
* Tags are not merged along with the torrents. *
|
|
|
|
* Neither are similar artists. *
|
|
|
|
* *
|
|
|
|
* We can add these features eventually. *
|
2011-03-28 14:21:28 +00:00
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
authorize();
|
|
|
|
|
|
|
|
$ArtistID = $_POST['artistid'];
|
2012-10-11 08:00:15 +00:00
|
|
|
$NewName = Artists::normalise_artist_name($_POST['name']);
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2013-05-05 08:00:31 +00:00
|
|
|
if (!$ArtistID || !is_number($ArtistID)) {
|
|
|
|
error(404);
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2013-05-05 08:00:31 +00:00
|
|
|
if (!check_perms('torrents_edit')) {
|
|
|
|
error(403);
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2013-07-13 08:00:46 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT Name
|
|
|
|
FROM artists_group
|
|
|
|
WHERE ArtistID = '$ArtistID'");
|
2013-07-10 00:08:53 +00:00
|
|
|
if (!$DB->has_results()) {
|
2013-05-05 08:00:31 +00:00
|
|
|
error(404);
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
list($OldName) = $DB->next_record(MYSQLI_NUM, false);
|
2013-05-05 08:00:31 +00:00
|
|
|
if ($OldName == $NewName) {
|
|
|
|
error('The new name is identical to the old name.');
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2013-05-05 08:00:31 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT AliasID
|
|
|
|
FROM artists_alias
|
2013-07-13 08:00:46 +00:00
|
|
|
WHERE Name = '".db_string($OldName)."'
|
|
|
|
AND ArtistID = '$ArtistID'");
|
2011-03-28 14:21:28 +00:00
|
|
|
list($OldAliasID) = $DB->next_record(MYSQLI_NUM, false);
|
2013-05-05 08:00:31 +00:00
|
|
|
if (!$OldAliasID) {
|
|
|
|
error('Could not find old alias ID');
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2013-05-05 08:00:31 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT AliasID, ArtistID
|
|
|
|
FROM artists_alias
|
|
|
|
WHERE name LIKE '".db_string($NewName, true)."'");
|
2011-03-28 14:21:28 +00:00
|
|
|
list($TargetAliasID, $TargetArtistID) = $DB->next_record(MYSQLI_NUM, false);
|
|
|
|
|
2013-07-13 08:00:46 +00:00
|
|
|
if (!$TargetAliasID || $TargetAliasID == $OldAliasID) {
|
2011-03-28 14:21:28 +00:00
|
|
|
// no merge, just rename
|
2013-05-05 08:00:31 +00:00
|
|
|
$DB->query("
|
2013-07-13 08:00:46 +00:00
|
|
|
INSERT INTO artists_alias
|
|
|
|
(ArtistID, Name, Redirect, UserID)
|
|
|
|
VALUES
|
|
|
|
($ArtistID, '".db_string($NewName)."', '0', '$LoggedUser[ID]')");
|
2011-03-28 14:21:28 +00:00
|
|
|
$TargetAliasID = $DB->inserted_id();
|
|
|
|
|
2013-07-13 08:00:46 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE artists_alias
|
|
|
|
SET Redirect = '$TargetAliasID'
|
|
|
|
WHERE AliasID = '$OldAliasID'");
|
|
|
|
$DB->query("
|
|
|
|
UPDATE artists_group
|
|
|
|
SET Name = '".db_string($NewName)."'
|
|
|
|
WHERE ArtistID = '$ArtistID'");
|
2011-11-12 08:00:15 +00:00
|
|
|
|
2013-07-13 08:00:46 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT GroupID
|
|
|
|
FROM torrents_artists
|
|
|
|
WHERE AliasID = '$OldAliasID'");
|
2011-03-28 14:21:28 +00:00
|
|
|
$Groups = $DB->collect('GroupID');
|
2013-07-13 08:00:46 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE IGNORE torrents_artists
|
|
|
|
SET AliasID = '$TargetAliasID'
|
|
|
|
WHERE AliasID = '$OldAliasID'");
|
|
|
|
$DB->query("
|
|
|
|
DELETE FROM torrents_artists
|
|
|
|
WHERE AliasID = '$OldAliasID'");
|
2013-05-05 08:00:31 +00:00
|
|
|
if (!empty($Groups)) {
|
|
|
|
foreach ($Groups as $GroupID) {
|
2013-07-13 08:00:46 +00:00
|
|
|
$Cache->delete_value("groups_artists_$GroupID"); // Delete group artist cache
|
2012-10-11 08:00:15 +00:00
|
|
|
Torrents::update_hash($GroupID);
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-12 08:00:15 +00:00
|
|
|
|
2013-07-13 08:00:46 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT RequestID
|
|
|
|
FROM requests_artists
|
|
|
|
WHERE AliasID = '$OldAliasID'");
|
2011-11-12 08:00:15 +00:00
|
|
|
$Requests = $DB->collect('RequestID');
|
2013-07-13 08:00:46 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE IGNORE requests_artists
|
|
|
|
SET AliasID = '$TargetAliasID'
|
|
|
|
WHERE AliasID = '$OldAliasID'");
|
|
|
|
$DB->query("
|
|
|
|
DELETE FROM requests_artists
|
|
|
|
WHERE AliasID = '$OldAliasID'");
|
2013-05-05 08:00:31 +00:00
|
|
|
if (!empty($Requests)) {
|
|
|
|
foreach ($Requests as $RequestID) {
|
2013-07-13 08:00:46 +00:00
|
|
|
$Cache->delete_value("request_artists_$RequestID"); // Delete request artist cache
|
2012-10-11 08:00:15 +00:00
|
|
|
Requests::update_sphinx_requests($RequestID);
|
2011-11-12 08:00:15 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
$TargetArtistID = $ArtistID;
|
|
|
|
|
|
|
|
} else { // Merge stuff
|
2013-05-05 08:00:31 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE artists_alias
|
2013-07-13 08:00:46 +00:00
|
|
|
SET Redirect = '$TargetAliasID', ArtistID = '$TargetArtistID'
|
|
|
|
WHERE AliasID = '$OldAliasID'");
|
|
|
|
$DB->query("
|
|
|
|
UPDATE artists_alias
|
|
|
|
SET Redirect = '0'
|
|
|
|
WHERE AliasID = '$TargetAliasID'");
|
2013-05-05 08:00:31 +00:00
|
|
|
if ($ArtistID != $TargetArtistID) {
|
2013-07-13 08:00:46 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE artists_alias
|
|
|
|
SET ArtistID = '$TargetArtistID'
|
|
|
|
WHERE ArtistID = '$ArtistID'");
|
|
|
|
$DB->query("
|
|
|
|
DELETE FROM artists_group
|
|
|
|
WHERE ArtistID = '$ArtistID'");
|
2011-03-28 14:21:28 +00:00
|
|
|
} else {
|
2013-07-13 08:00:46 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE artists_group
|
|
|
|
SET Name = '".db_string($NewName)."'
|
|
|
|
WHERE ArtistID = '$ArtistID'");
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-07-13 08:00:46 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT GroupID
|
|
|
|
FROM torrents_artists
|
|
|
|
WHERE AliasID = '$OldAliasID'");
|
2011-03-28 14:21:28 +00:00
|
|
|
$Groups = $DB->collect('GroupID');
|
2013-05-05 08:00:31 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE IGNORE torrents_artists
|
2013-07-13 08:00:46 +00:00
|
|
|
SET AliasID = '$TargetAliasID', ArtistID = '$TargetArtistID'
|
|
|
|
WHERE AliasID = '$OldAliasID'");
|
|
|
|
$DB->query("
|
|
|
|
DELETE FROM torrents_artists
|
|
|
|
WHERE AliasID = '$OldAliasID'");
|
2013-05-05 08:00:31 +00:00
|
|
|
if (!empty($Groups)) {
|
|
|
|
foreach ($Groups as $GroupID) {
|
2013-07-13 08:00:46 +00:00
|
|
|
$Cache->delete_value("groups_artists_$GroupID");
|
2012-10-11 08:00:15 +00:00
|
|
|
Torrents::update_hash($GroupID);
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-12 08:00:15 +00:00
|
|
|
|
2013-07-13 08:00:46 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT RequestID
|
|
|
|
FROM requests_artists
|
|
|
|
WHERE AliasID = '$OldAliasID'");
|
2011-11-12 08:00:15 +00:00
|
|
|
$Requests = $DB->collect('RequestID');
|
2013-05-05 08:00:31 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE IGNORE requests_artists
|
2013-07-13 08:00:46 +00:00
|
|
|
SET AliasID = '$TargetAliasID', ArtistID = '$TargetArtistID'
|
|
|
|
WHERE AliasID = '$OldAliasID'");
|
|
|
|
$DB->query("
|
|
|
|
DELETE FROM requests_artists
|
|
|
|
WHERE AliasID = '$OldAliasID'");
|
2013-05-05 08:00:31 +00:00
|
|
|
if (!empty($Requests)) {
|
|
|
|
foreach ($Requests as $RequestID) {
|
2013-07-13 08:00:46 +00:00
|
|
|
$Cache->delete_value("request_artists_$RequestID");
|
2012-10-11 08:00:15 +00:00
|
|
|
Requests::update_sphinx_requests($RequestID);
|
2011-11-12 08:00:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-05 08:00:31 +00:00
|
|
|
if ($ArtistID != $TargetArtistID) {
|
2013-07-13 08:00:46 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT GroupID
|
|
|
|
FROM torrents_artists
|
|
|
|
WHERE ArtistID = '$ArtistID'");
|
2011-03-28 14:21:28 +00:00
|
|
|
$Groups = $DB->collect('GroupID');
|
2013-05-05 08:00:31 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE IGNORE torrents_artists
|
2013-07-13 08:00:46 +00:00
|
|
|
SET ArtistID = '$TargetArtistID'
|
|
|
|
WHERE ArtistID = '$ArtistID'");
|
|
|
|
$DB->query("
|
|
|
|
DELETE FROM torrents_artists
|
|
|
|
WHERE ArtistID = '$ArtistID'");
|
2013-05-05 08:00:31 +00:00
|
|
|
if (!empty($Groups)) {
|
|
|
|
foreach ($Groups as $GroupID) {
|
2013-07-13 08:00:46 +00:00
|
|
|
$Cache->delete_value("groups_artists_$GroupID");
|
2012-10-11 08:00:15 +00:00
|
|
|
Torrents::update_hash($GroupID);
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-12 08:00:15 +00:00
|
|
|
|
2013-07-13 08:00:46 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT RequestID
|
|
|
|
FROM requests_artists
|
|
|
|
WHERE ArtistID = '$ArtistID'");
|
2011-11-12 08:00:15 +00:00
|
|
|
$Requests = $DB->collect('RequestID');
|
2013-05-05 08:00:31 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE IGNORE requests_artists
|
2013-07-13 08:00:46 +00:00
|
|
|
SET ArtistID = '$TargetArtistID'
|
|
|
|
WHERE ArtistID = '$ArtistID'");
|
|
|
|
$DB->query("
|
|
|
|
DELETE FROM requests_artists
|
|
|
|
WHERE ArtistID = '$ArtistID'");
|
2013-05-05 08:00:31 +00:00
|
|
|
if (!empty($Requests)) {
|
|
|
|
foreach ($Requests as $RequestID) {
|
2013-07-13 08:00:46 +00:00
|
|
|
$Cache->delete_value("request_artists_$RequestID");
|
2012-10-11 08:00:15 +00:00
|
|
|
Requests::update_sphinx_requests($RequestID);
|
2011-11-12 08:00:15 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-28 23:08:41 +00:00
|
|
|
|
|
|
|
Comments::merge('artist', $ArtistID, $TargetArtistID);
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear torrent caches
|
2013-07-13 08:00:46 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT GroupID
|
|
|
|
FROM torrents_artists
|
|
|
|
WHERE ArtistID = '$ArtistID'");
|
2013-05-05 08:00:31 +00:00
|
|
|
while (list($GroupID) = $DB->next_record()) {
|
2013-07-13 08:00:46 +00:00
|
|
|
$Cache->delete_value("torrents_details_$GroupID");
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
|
2013-07-13 08:00:46 +00:00
|
|
|
$Cache->delete_value("artist_$ArtistID");
|
|
|
|
$Cache->delete_value("artist_$TargetArtistID");
|
|
|
|
$Cache->delete_value("artists_requests_$TargetArtistID");
|
|
|
|
$Cache->delete_value("artists_requests_$ArtistID");
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2013-07-13 08:00:46 +00:00
|
|
|
header("Location: artist.php?id=$TargetArtistID");
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
?>
|