Oppaitime'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.

delete_dead_torrents.php 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?
  2. //------------- Delete dead torrents ------------------------------------//
  3. $DB->query("
  4. SELECT
  5. t.ID,
  6. t.GroupID,
  7. tg.Name,
  8. t.UserID,
  9. t.Media,
  10. HEX(t.info_hash) AS InfoHash
  11. FROM torrents AS t
  12. JOIN torrents_group AS tg ON tg.ID = t.GroupID
  13. WHERE
  14. (t.last_action < '".time_minus(3600 * 24 * 28)."' AND t.last_action != 0)
  15. OR
  16. (t.Time < '".time_minus(3600 * 24 * 2)."' AND t.last_action = 0)");
  17. $Torrents = $DB->to_array(false, MYSQLI_NUM, false);
  18. echo 'Found '.count($Torrents)." inactive torrents to be deleted.\n";
  19. $LogEntries = $DeleteNotes = array();
  20. // Exceptions for inactivity deletion
  21. $InactivityExceptionsMade = array(); //UserID => expiry time of exception
  22. $i = 0;
  23. foreach ($Torrents as $Torrent) {
  24. list($ID, $GroupID, $Name, $UserID, $Media, $InfoHash) = $Torrent;
  25. if (array_key_exists($UserID, $InactivityExceptionsMade) && (time() < $InactivityExceptionsMade[$UserID])) {
  26. // don't delete the torrent!
  27. continue;
  28. }
  29. $ArtistName = Artists::display_artists(Artists::get_artist($GroupID), false, false, false);
  30. if ($ArtistName) {
  31. $Name = "$ArtistName - $Name";
  32. }
  33. Torrents::delete_torrent($ID, $GroupID);
  34. $LogEntries[] = db_string("Torrent $ID ($Name) (".strtoupper($InfoHash).") was deleted for inactivity (unseeded)");
  35. if (!array_key_exists($UserID, $DeleteNotes)) {
  36. $DeleteNotes[$UserID] = array('Count' => 0, 'Msg' => '');
  37. }
  38. $DeleteNotes[$UserID]['Msg'] .= "\n$Name";
  39. $DeleteNotes[$UserID]['Count']++;
  40. ++$i;
  41. if ($i % 500 == 0) {
  42. echo "$i inactive torrents removed.\n";
  43. }
  44. }
  45. echo "$i torrents deleted for inactivity.\n";
  46. foreach ($DeleteNotes as $UserID => $MessageInfo) {
  47. $Singular = ($MessageInfo['Count'] == 1);
  48. Misc::send_pm($UserID, 0, $MessageInfo['Count'].' of your torrents '.($Singular ? 'has' : 'have').' been deleted for inactivity', ($Singular ? 'One' : 'Some').' of your uploads '.($Singular ? 'has' : 'have').' been deleted for being unseeded. Since '.($Singular ? 'it' : 'they').' didn\'t break any rules (we hope), please feel free to re-upload '.($Singular ? 'it' : 'them').".\n\nThe following torrent".($Singular ? ' was' : 's were').' deleted:'.$MessageInfo['Msg']);
  49. }
  50. unset($DeleteNotes);
  51. if (count($LogEntries) > 0) {
  52. $Values = "('".implode("', '$sqltime'), ('", $LogEntries) . "', '$sqltime')";
  53. $DB->query("
  54. INSERT INTO log (Message, Time)
  55. VALUES $Values");
  56. echo "\nDeleted $i torrents for inactivity\n";
  57. }
  58. $DB->query("
  59. SELECT SimilarID
  60. FROM artists_similar_scores
  61. WHERE Score <= 0");
  62. $SimilarIDs = implode(',', $DB->collect('SimilarID'));
  63. if ($SimilarIDs) {
  64. $DB->query("
  65. DELETE FROM artists_similar
  66. WHERE SimilarID IN($SimilarIDs)");
  67. $DB->query("
  68. DELETE FROM artists_similar_scores
  69. WHERE SimilarID IN($SimilarIDs)");
  70. $DB->query("
  71. DELETE FROM artists_similar_votes
  72. WHERE SimilarID IN($SimilarIDs)");
  73. }
  74. ?>