2012-04-02 08:00:21 +00:00
< ?
authorize ();
if ( ! check_perms ( 'torrents_edit' )) { error ( 403 ); }
if ( ! empty ( $_POST [ 'newartistid' ]) && ! empty ( $_POST [ 'newartistname' ])) {
2012-09-23 08:00:25 +00:00
error ( " Please enter a valid artist ID number or a valid artist name. " );
2012-04-02 08:00:21 +00:00
}
$ArtistID = ( int ) $_POST [ 'artistid' ];
$NewArtistID = ( int ) $_POST [ 'newartistid' ];
$NewArtistName = $_POST [ 'newartistname' ];
if ( ! is_number ( $ArtistID ) || ! $ArtistID ) {
error ( 'Please select a valid artist to change.' );
}
if ( empty ( $NewArtistName ) && ( ! $NewArtistID || ! is_number ( $NewArtistID ))) {
error ( 'Please enter a valid artist ID number or a valid artist name.' );
}
$DB -> query ( " SELECT Name FROM artists_group WHERE ArtistID = $ArtistID LIMIT 1 " );
2012-07-25 08:00:15 +00:00
if ( ! ( list ( $ArtistName ) = $DB -> next_record ( MYSQLI_NUM , false ))) {
2012-04-02 08:00:21 +00:00
error ( 'An error has occured.' );
}
if ( $NewArtistID > 0 ) {
2012-09-23 08:00:25 +00:00
// Make sure that's a real artist ID number, and grab the name
2013-02-22 08:00:24 +00:00
$DB -> query ( " SELECT Name FROM artists_group WHERE ArtistID = $NewArtistID LIMIT 1 " );
2012-04-02 08:00:21 +00:00
if ( ! ( list ( $NewArtistName ) = $DB -> next_record ())) {
error ( 'Please enter a valid artist ID number.' );
}
} else {
// Didn't give an ID, so try to grab based on the name
2013-02-22 08:00:24 +00:00
$DB -> query ( " SELECT ArtistID FROM artists_alias WHERE Name = ' " . db_string ( $NewArtistName ) . " ' LIMIT 1 " );
2012-04-02 08:00:21 +00:00
if ( ! ( list ( $NewArtistID ) = $DB -> next_record ())) {
error ( 'No artist by that name was found.' );
}
}
if ( $ArtistID == $NewArtistID ) {
2012-09-23 08:00:25 +00:00
error ( " You cannot merge an artist with itself. " );
2012-04-02 08:00:21 +00:00
}
if ( isset ( $_POST [ 'confirm' ])) {
// Get the information for the cache update
$DB -> query ( " SELECT DISTINCT GroupID FROM torrents_artists WHERE ArtistID = $ArtistID " );
$Groups = $DB -> collect ( 'GroupID' );
$DB -> query ( " SELECT DISTINCT RequestID FROM requests_artists WHERE ArtistID = $ArtistID " );
$Requests = $DB -> collect ( 'RequestID' );
$DB -> query ( " SELECT DISTINCT UserID FROM bookmarks_artists WHERE ArtistID = $ArtistID " );
$BookmarkUsers = $DB -> collect ( 'UserID' );
$DB -> query ( " SELECT DISTINCT ct.CollageID
FROM collages_torrents AS ct
JOIN torrents_artists AS ta ON ta . GroupID = ct . GroupID
WHERE ta . ArtistID = $ArtistID " );
$Collages = $DB -> collect ( 'CollageID' );
// And the info to avoid double-listing an artist if it and the target are on the same group
$DB -> query ( " SELECT DISTINCT GroupID FROM torrents_artists WHERE ArtistID = $NewArtistID " );
$NewArtistGroups = $DB -> collect ( 'GroupID' );
$NewArtistGroups [] = '0' ;
$NewArtistGroups = implode ( ',' , $NewArtistGroups );
2013-02-22 08:00:24 +00:00
2012-04-02 08:00:21 +00:00
$DB -> query ( " SELECT DISTINCT RequestID FROM requests_artists WHERE ArtistID = $NewArtistID " );
$NewArtistRequests = $DB -> collect ( 'RequestID' );
$NewArtistRequests [] = '0' ;
$NewArtistRequests = implode ( ',' , $NewArtistRequests );
2013-02-22 08:00:24 +00:00
2012-04-02 08:00:21 +00:00
$DB -> query ( " SELECT DISTINCT UserID from bookmarks_artists WHERE ArtistID = $NewArtistID " );
$NewArtistBookmarks = $DB -> collect ( 'UserID' );
$NewArtistBookmarks [] = '0' ;
2013-02-22 08:00:24 +00:00
$NewArtistBookmarks = implode ( ',' , $NewArtistBookmarks );
2012-04-02 08:00:21 +00:00
// Merge all of this artist's aliases onto the new artist
$DB -> query ( " UPDATE artists_alias SET ArtistID = $NewArtistID WHERE ArtistID = $ArtistID " );
2013-02-22 08:00:24 +00:00
2012-04-02 08:00:21 +00:00
// Update the torrent groups, requests, and bookmarks
$DB -> query ( " UPDATE IGNORE torrents_artists SET ArtistID = $NewArtistID
2013-02-22 08:00:24 +00:00
WHERE ArtistID = $ArtistID
2012-04-02 08:00:21 +00:00
AND GroupID NOT IN ( $NewArtistGroups ) " );
$DB -> query ( " DELETE FROM torrents_artists WHERE ArtistID = $ArtistID " );
$DB -> query ( " UPDATE IGNORE requests_artists SET ArtistID = $NewArtistID
WHERE ArtistID = $ArtistID
AND RequestID NOT IN ( $NewArtistRequests ) " );
$DB -> query ( " DELETE FROM requests_artists WHERE ArtistID = $ArtistID " );
$DB -> query ( " UPDATE IGNORE bookmarks_artists SET ArtistID = $NewArtistID
WHERE ArtistID = $ArtistID
AND UserID NOT IN ( $NewArtistBookmarks ) " );
$DB -> query ( " DELETE FROM bookmarks_artists WHERE ArtistID = $ArtistID " );
2013-02-22 08:00:24 +00:00
2012-04-02 08:00:21 +00:00
// Cache clearing
if ( ! empty ( $Groups )) {
foreach ( $Groups as $GroupID ) {
$Cache -> delete_value ( 'groups_artists_' . $GroupID );
2012-10-11 08:00:15 +00:00
Torrents :: update_hash ( $GroupID );
2012-04-02 08:00:21 +00:00
}
}
if ( ! empty ( $Requests )) {
foreach ( $Requests as $RequestID ) {
$Cache -> delete_value ( 'request_artist_' . $RequestID );
2012-10-11 08:00:15 +00:00
Requests :: update_sphinx_requests ( $RequestID );
2012-04-02 08:00:21 +00:00
}
}
if ( ! empty ( $BookmarkUsers )) {
foreach ( $BookmarkUsers as $UserID ) {
$Cache -> delete_value ( 'notify_artists_' . $UserID );
}
}
if ( ! empty ( $Collages )) {
foreach ( $Collages as $CollageID ) {
$Cache -> delete_value ( 'collage_' . $CollageID );
}
}
$Cache -> delete_value ( 'artist_' . $ArtistID );
$Cache -> delete_value ( 'artist_' . $NewArtistID );
2012-11-20 08:00:19 +00:00
$Cache -> delete_value ( 'artist_groups_' . $ArtistID );
$Cache -> delete_value ( 'artist_groups_' . $NewArtistID );
2012-04-02 08:00:21 +00:00
// Delete the old artist
$DB -> query ( " DELETE FROM artists_group WHERE ArtistID = $ArtistID " );
2012-10-11 08:00:15 +00:00
Misc :: write_log ( " The artist " . $ArtistID . " ( " . $ArtistName . " ) was made into a non-redirecting alias of artist " . $NewArtistID . " ( " . $NewArtistName . " ) by user " . $LoggedUser [ 'ID' ] . " ( " . $LoggedUser [ 'Username' ] . " ) " );
2012-04-02 08:00:21 +00:00
header ( " Location: artist.php?action=edit&artistid= $NewArtistID " );
} else {
2012-10-11 08:00:15 +00:00
View :: show_header ( 'Merging Artists' );
2012-04-02 08:00:21 +00:00
?>
2012-08-19 08:00:19 +00:00
< div class = " header " >
< h2 > Confirm merge </ h2 >
</ div >
2012-09-15 08:00:25 +00:00
< form class = " merge_form " name = " artist " action = " artist.php " method = " post " >
2012-04-02 08:00:21 +00:00
< input type = " hidden " name = " action " value = " change_artistid " />
< input type = " hidden " name = " auth " value = " <?= $LoggedUser['AuthKey'] ?> " />
< input type = " hidden " name = " artistid " value = " <?= $ArtistID ?> " />
< input type = " hidden " name = " newartistid " value = " <?= $NewArtistID ?> " />
< input type = " hidden " name = " confirm " value = " 1 " />
< div style = " text-align: center; " >
< p > Please confirm that you wish to make < a href = " artist.php?id=<?= $ArtistID ?> " >< ? = display_str ( $ArtistName ) ?> (<?=$ArtistID?>)</a> into a non-redirecting alias of <a href="artist.php?id=<?=$NewArtistID?>"><?=display_str($NewArtistName)?> (<?=$NewArtistID?>)</a>.</p>
2012-09-23 08:00:25 +00:00
< br />
2012-04-02 08:00:21 +00:00
< input type = " submit " value = " Confirm " />
</ div >
</ form >
< ?
2012-10-11 08:00:15 +00:00
View :: show_footer ();
2012-04-02 08:00:21 +00:00
}
2012-09-23 08:00:25 +00:00
?>