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

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