BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

change_artistid.php 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. #declare(strict_types=1);
  3. authorize();
  4. if (!check_perms('torrents_edit')) {
  5. error(403);
  6. }
  7. if (!empty($_POST['newartistid']) && !empty($_POST['newartistname'])) {
  8. error('Please enter a valid artist ID number or a valid artist name.');
  9. }
  10. $ArtistID = (int)$_POST['artistid'];
  11. $NewArtistID = (int)$_POST['newartistid'];
  12. $NewArtistName = $_POST['newartistname'];
  13. if (!is_number($ArtistID) || !$ArtistID) {
  14. error('Please select a valid artist to change.');
  15. }
  16. if (empty($NewArtistName) && (!$NewArtistID || !is_number($NewArtistID))) {
  17. error('Please enter a valid artist ID number or a valid artist name.');
  18. }
  19. $DB->query("
  20. SELECT Name
  21. FROM artists_group
  22. WHERE ArtistID = $ArtistID
  23. LIMIT 1");
  24. if (!(list($ArtistName) = $DB->next_record(MYSQLI_NUM, false))) {
  25. error('An error has occurred.');
  26. }
  27. if ($NewArtistID > 0) {
  28. // Make sure that's a real artist ID number, and grab the name
  29. $DB->query("
  30. SELECT Name
  31. FROM artists_group
  32. WHERE ArtistID = $NewArtistID
  33. LIMIT 1");
  34. if (!(list($NewArtistName) = $DB->next_record())) {
  35. error('Please enter a valid artist ID number.');
  36. }
  37. } else {
  38. // Didn't give an ID, so try to grab based on the name
  39. $DB->query("
  40. SELECT ArtistID
  41. FROM artists_alias
  42. WHERE Name = '".db_string($NewArtistName)."'
  43. LIMIT 1");
  44. if (!(list($NewArtistID) = $DB->next_record())) {
  45. error('No artist by that name was found.');
  46. }
  47. }
  48. if ($ArtistID == $NewArtistID) {
  49. error('You cannot merge an artist with itself.');
  50. }
  51. if (isset($_POST['confirm'])) {
  52. // Get the information for the cache update
  53. $DB->query("
  54. SELECT DISTINCT GroupID
  55. FROM torrents_artists
  56. WHERE ArtistID = $ArtistID");
  57. $Groups = $DB->collect('GroupID');
  58. $DB->query("
  59. SELECT DISTINCT RequestID
  60. FROM requests_artists
  61. WHERE ArtistID = $ArtistID");
  62. $Requests = $DB->collect('RequestID');
  63. $DB->query("
  64. SELECT DISTINCT UserID
  65. FROM bookmarks_artists
  66. WHERE ArtistID = $ArtistID");
  67. $BookmarkUsers = $DB->collect('UserID');
  68. $DB->query("
  69. SELECT DISTINCT ct.CollageID
  70. FROM collages_torrents AS ct
  71. JOIN torrents_artists AS ta ON ta.GroupID = ct.GroupID
  72. WHERE ta.ArtistID = $ArtistID");
  73. $Collages = $DB->collect('CollageID');
  74. // And the info to avoid double-listing an artist if it and the target are on the same group
  75. $DB->query("
  76. SELECT DISTINCT GroupID
  77. FROM torrents_artists
  78. WHERE ArtistID = $NewArtistID");
  79. $NewArtistGroups = $DB->collect('GroupID');
  80. $NewArtistGroups[] = '0';
  81. $NewArtistGroups = implode(',', $NewArtistGroups);
  82. $DB->query("
  83. SELECT DISTINCT RequestID
  84. FROM requests_artists
  85. WHERE ArtistID = $NewArtistID");
  86. $NewArtistRequests = $DB->collect('RequestID');
  87. $NewArtistRequests[] = '0';
  88. $NewArtistRequests = implode(',', $NewArtistRequests);
  89. $DB->query("
  90. SELECT DISTINCT UserID
  91. FROM bookmarks_artists
  92. WHERE ArtistID = $NewArtistID");
  93. $NewArtistBookmarks = $DB->collect('UserID');
  94. $NewArtistBookmarks[] = '0';
  95. $NewArtistBookmarks = implode(',', $NewArtistBookmarks);
  96. // Merge all of this artist's aliases onto the new artist
  97. $DB->query("
  98. UPDATE artists_alias
  99. SET ArtistID = $NewArtistID
  100. WHERE ArtistID = $ArtistID");
  101. // Update the torrent groups, requests, and bookmarks
  102. $DB->query("
  103. UPDATE IGNORE torrents_artists
  104. SET ArtistID = $NewArtistID
  105. WHERE ArtistID = $ArtistID
  106. AND GroupID NOT IN ($NewArtistGroups)");
  107. $DB->query("
  108. DELETE FROM torrents_artists
  109. WHERE ArtistID = $ArtistID");
  110. $DB->query("
  111. UPDATE IGNORE requests_artists
  112. SET ArtistID = $NewArtistID
  113. WHERE ArtistID = $ArtistID
  114. AND RequestID NOT IN ($NewArtistRequests)");
  115. $DB->query("
  116. DELETE FROM requests_artists
  117. WHERE ArtistID = $ArtistID");
  118. $DB->query("
  119. UPDATE IGNORE bookmarks_artists
  120. SET ArtistID = $NewArtistID
  121. WHERE ArtistID = $ArtistID
  122. AND UserID NOT IN ($NewArtistBookmarks)");
  123. $DB->query("
  124. DELETE FROM bookmarks_artists
  125. WHERE ArtistID = $ArtistID");
  126. // Cache clearing
  127. if (!empty($Groups)) {
  128. foreach ($Groups as $GroupID) {
  129. $Cache->delete_value("groups_artists_$GroupID");
  130. Torrents::update_hash($GroupID);
  131. }
  132. }
  133. if (!empty($Requests)) {
  134. foreach ($Requests as $RequestID) {
  135. $Cache->delete_value("request_artists_$RequestID");
  136. Requests::update_sphinx_requests($RequestID);
  137. }
  138. }
  139. if (!empty($BookmarkUsers)) {
  140. foreach ($BookmarkUsers as $UserID) {
  141. $Cache->delete_value("notify_artists_$UserID");
  142. }
  143. }
  144. if (!empty($Collages)) {
  145. foreach ($Collages as $CollageID) {
  146. $Cache->delete_value("collage_$CollageID");
  147. }
  148. }
  149. $Cache->delete_value("artist_$ArtistID");
  150. $Cache->delete_value("artist_$NewArtistID");
  151. $Cache->delete_value("artist_groups_$ArtistID");
  152. $Cache->delete_value("artist_groups_$NewArtistID");
  153. // Delete the old artist
  154. $DB->query("
  155. DELETE FROM artists_group
  156. WHERE ArtistID = $ArtistID");
  157. Misc::write_log("The artist $ArtistID ($ArtistName) was made into a non-redirecting alias of artist $NewArtistID ($NewArtistName) by user ".$LoggedUser['ID']." (".$LoggedUser['Username'].')');
  158. header("Location: artist.php?action=edit&artistid=$NewArtistID");
  159. } else {
  160. View::show_header('Merging Artists'); ?>
  161. <div class="header">
  162. <h2>Confirm merge</h2>
  163. </div>
  164. <form class="merge_form" name="artist" action="artist.php" method="post">
  165. <input type="hidden" name="action" value="change_artistid" />
  166. <input type="hidden" name="auth"
  167. value="<?=$LoggedUser['AuthKey']?>" />
  168. <input type="hidden" name="artistid" value="<?=$ArtistID?>" />
  169. <input type="hidden" name="newartistid"
  170. value="<?=$NewArtistID?>" />
  171. <input type="hidden" name="confirm" value="1" />
  172. <div style="text-align: center;">
  173. <p>Please confirm that you wish to make <a
  174. href="artist.php?id=<?=$ArtistID?>"><?=display_str($ArtistName)?> (<?=$ArtistID?>)</a> into a non-redirecting alias of <a
  175. href="artist.php?id=<?=$NewArtistID?>"><?=display_str($NewArtistName)?> (<?=$NewArtistID?>)</a>.</p>
  176. <br />
  177. <input type="submit" value="Confirm" />
  178. </div>
  179. </form>
  180. <?php
  181. View::show_footer();
  182. }