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

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