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.

delete_dead_torrents.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. // The SQL query's line below controls the deletion clock
  3. // (t.last_action < (NOW() - INTERVAL 28 DAY) AND t.last_action IS NOT NULL)
  4. $DB->query("
  5. SELECT
  6. t.ID,
  7. t.GroupID,
  8. tg.Name,
  9. t.UserID,
  10. t.Media,
  11. HEX(t.info_hash) AS InfoHash
  12. FROM torrents AS t
  13. JOIN torrents_group AS tg ON tg.ID = t.GroupID
  14. WHERE
  15. (t.last_action < (NOW() - INTERVAL 365 DAY) AND t.last_action IS NOT NULL)
  16. OR
  17. (t.Time < (NOW() - INTERVAL 2 DAY) AND t.last_action IS NULL)");
  18. $Torrents = $DB->to_array(false, MYSQLI_NUM, false);
  19. echo 'Found '.count($Torrents)." inactive torrents to be deleted.\n";
  20. $LogEntries = $DeleteNotes = [];
  21. // Exceptions for inactivity deletion
  22. $InactivityExceptionsMade = []; // UserID => expiry time of exception
  23. $i = 0;
  24. foreach ($Torrents as $Torrent) {
  25. list($ID, $GroupID, $Name, $UserID, $Media, $InfoHash) = $Torrent;
  26. if (array_key_exists($UserID, $InactivityExceptionsMade) && (time() < $InactivityExceptionsMade[$UserID])) {
  27. // Don't delete the torrent!
  28. continue;
  29. }
  30. $ArtistName = Artists::display_artists(Artists::get_artist($GroupID), false, false, false);
  31. if ($ArtistName) {
  32. $Name = "$ArtistName - $Name";
  33. }
  34. Torrents::delete_torrent($ID, $GroupID);
  35. $LogEntries[] = db_string("Torrent $ID ($Name) (".strtoupper($InfoHash).") was deleted for inactivity (unseeded)");
  36. if (!array_key_exists($UserID, $DeleteNotes)) {
  37. $DeleteNotes[$UserID] = array('Count' => 0, 'Msg' => '');
  38. }
  39. $DeleteNotes[$UserID]['Msg'] .= "\n$Name";
  40. $DeleteNotes[$UserID]['Count']++;
  41. ++$i;
  42. if ($i % 500 === 0) {
  43. echo "$i inactive torrents removed.\n";
  44. }
  45. }
  46. echo "$i torrents deleted for inactivity.\n";
  47. foreach ($DeleteNotes as $UserID => $MessageInfo) {
  48. $Singular = ($MessageInfo['Count'] === 1);
  49. 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']);
  50. }
  51. unset($DeleteNotes);
  52. if (count($LogEntries) > 0) {
  53. $Values = "('".implode("', '$sqltime'), ('", $LogEntries) . "', '$sqltime')";
  54. $DB->query("
  55. INSERT INTO log (Message, Time)
  56. VALUES $Values");
  57. echo "\nDeleted $i torrents for inactivity\n";
  58. }