| 14 | | if ( empty($_REQUEST['explain']) && defined('DEBUG_EXTRA') ) { |
|---|
| 15 | | redirect( append_sid('docleanup.php?explain=1')); |
|---|
| 16 | | } |
|---|
| 17 | | //begin sync tables, delete some old shit |
|---|
| 18 | | $db->sql_query('DELETE c.* FROM ' . COMMENTS_TABLE . ' c LEFT JOIN ' . TORRENTS_TABLE . ' t ON ( c.comment_for_id = t.fid ) WHERE t.name IS NULL AND c.comment_type = ' . TYPE_TORRENT); |
|---|
| 19 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned comments from torrents deleted', LOG_VIEW_SYSOP); |
|---|
| 20 | | $db->sql_query('DELETE f.* FROM ' . FILES_TABLE . ' f LEFT JOIN ' . TORRENTS_TABLE . ' t ON f.torrent = t.fid WHERE t.name IS NULL'); |
|---|
| 21 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned files from torrents deleted', LOG_VIEW_SYSOP); |
|---|
| 22 | | $db->sql_query('DELETE s.* FROM ' . SOS_TABLE . ' s LEFT JOIN ' . TORRENTS_TABLE . ' t ON s.torrentid = t.fid WHERE t.name IS NULL'); |
|---|
| 23 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned sos requests deleted', LOG_VIEW_SYSOP); |
|---|
| 24 | | $db->sql_query('DELETE t1.* FROM ' . THANKS_TABLE . ' t1 LEFT JOIN ' . TORRENTS_TABLE . ' t ON t1.torrentid = t.fid WHERE t.name IS NULL'); |
|---|
| 25 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned thankses deleted', LOG_VIEW_SYSOP); |
|---|
| 26 | | $db->sql_query('DELETE s.* FROM ' . SNATCHED_TABLE . ' s LEFT JOIN ' . TORRENTS_TABLE . ' t ON s.torrentid = t.fid WHERE t.name IS NULL'); |
|---|
| 27 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned snatched rows deleted', LOG_VIEW_SYSOP); |
|---|
| 28 | | $db->sql_query('DELETE r.* FROM ' . RATINGS_TABLE . ' r LEFT JOIN ' . TORRENTS_TABLE . ' t ON r.torrent = t.fid WHERE t.name IS NULL'); |
|---|
| 29 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned ratings deleted', LOG_VIEW_SYSOP); |
|---|
| 30 | | $db->sql_query('DELETE i.* FROM ' . INDEXRELEASES_TABLE . ' i LEFT JOIN ' . TORRENTS_TABLE . ' t ON i.torrent_id = t.fid WHERE t.name IS NULL'); |
|---|
| 31 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned indexreleases deleted', LOG_VIEW_SYSOP); |
|---|
| 32 | | $db->sql_query('DELETE c.* FROM ' . COMMENTS_NOTIFY_TABLE . ' c LEFT JOIN ' . TORRENTS_TABLE . ' t ON ( c.checkcomm_for_id = t.fid ) WHERE t.name IS NULL AND c.checkcomm_type = ' . TYPE_TORRENT); |
|---|
| 33 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned comments notifis deleted', LOG_VIEW_SYSOP); |
|---|
| 34 | | $db->sql_query('DELETE b.* FROM ' . BOOKMARKS_TABLE . ' b LEFT JOIN ' . TORRENTS_TABLE . ' t ON b.torrentid = t.fid WHERE t.name IS NULL'); |
|---|
| 35 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned bookmarks deleted', LOG_VIEW_SYSOP); |
|---|
| 36 | | $db->sql_query('DELETE s.* FROM ' . SNATCHED_TABLE . ' s LEFT JOIN ' . TORRENTS_TABLE . ' t ON s.torrentid = t.fid WHERE t.name IS NULL'); |
|---|
| 37 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned snatched deleted', LOG_VIEW_SYSOP); |
|---|
| 38 | | $db->sql_query('DELETE r.* FROM ' . REPORTS_TABLE . ' r LEFT JOIN ' . TORRENTS_TABLE . ' t ON r.votedfor = t.fid WHERE t.name IS NULL AND r.type = 2'); |
|---|
| 39 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned reports deleted', LOG_VIEW_SYSOP); |
|---|
| 41 | | $db->sql_query('DELETE c.* FROM ' . COMMENTS_TABLE . ' c LEFT JOIN ' . REQUESTS_TABLE . ' r ON ( c.comment_for_id = r.id ) WHERE r.request IS NULL AND c.comment_type = ' . TYPE_REQUEST); |
|---|
| 42 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned comments from requests deleted', LOG_VIEW_SYSOP); |
|---|
| 43 | | $db->sql_query('DELETE c.* FROM ' . COMMENTS_TABLE . ' c LEFT JOIN ' . OFFERS_TABLE . ' o ON ( c.comment_for_id = o.id ) WHERE o.name IS NULL AND c.comment_type = ' . TYPE_OFFER); |
|---|
| 44 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned comments from offers deleted', LOG_VIEW_SYSOP); |
|---|
| 45 | | $db->sql_query('DELETE v.* FROM ' . REQUESTS_VOTES_TABLE . ' v LEFT JOIN ' . REQUESTS_TABLE . ' r ON v.requestid = r.id WHERE r.request IS NULL'); |
|---|
| 46 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned requests votes deleted', LOG_VIEW_SYSOP); |
|---|
| 47 | | $db->sql_query('DELETE ov.* FROM ' . OFFERS_VOTES_TABLE . ' ov LEFT JOIN ' . OFFERS_TABLE . ' o ON ov.offerid = o.id WHERE o.name IS NULL'); |
|---|
| 48 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned offers votes deleted', LOG_VIEW_SYSOP); |
|---|
| | 17 | switch($step) { |
|---|
| | 18 | case 0: |
|---|
| | 19 | $db->sql_query('DELETE c.* FROM ' . COMMENTS_TABLE . ' c LEFT JOIN ' . TORRENTS_TABLE . ' t ON ( c.comment_for_id = t.fid ) WHERE t.name IS NULL AND c.comment_type = ' . TYPE_TORRENT); |
|---|
| | 20 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned comments from torrents deleted', LOG_VIEW_SYSOP); |
|---|
| | 21 | $db->sql_query('DELETE f.* FROM ' . FILES_TABLE . ' f LEFT JOIN ' . TORRENTS_TABLE . ' t ON f.torrent = t.fid WHERE t.name IS NULL'); |
|---|
| | 22 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned files from torrents deleted', LOG_VIEW_SYSOP); |
|---|
| | 23 | $db->sql_query('DELETE s.* FROM ' . SOS_TABLE . ' s LEFT JOIN ' . TORRENTS_TABLE . ' t ON s.torrentid = t.fid WHERE t.name IS NULL'); |
|---|
| | 24 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned sos requests deleted', LOG_VIEW_SYSOP); |
|---|
| | 25 | $db->sql_query('DELETE t1.* FROM ' . THANKS_TABLE . ' t1 LEFT JOIN ' . TORRENTS_TABLE . ' t ON t1.torrentid = t.fid WHERE t.name IS NULL'); |
|---|
| | 26 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned thankses deleted', LOG_VIEW_SYSOP); |
|---|
| | 27 | $db->sql_query('DELETE s.* FROM ' . SNATCHED_TABLE . ' s LEFT JOIN ' . TORRENTS_TABLE . ' t ON s.torrentid = t.fid WHERE t.name IS NULL'); |
|---|
| | 28 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned snatched rows deleted', LOG_VIEW_SYSOP); |
|---|
| | 29 | $db->sql_query('DELETE r.* FROM ' . RATINGS_TABLE . ' r LEFT JOIN ' . TORRENTS_TABLE . ' t ON r.torrent = t.fid WHERE t.name IS NULL'); |
|---|
| | 30 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned ratings deleted', LOG_VIEW_SYSOP); |
|---|
| | 31 | $db->sql_query('DELETE i.* FROM ' . INDEXRELEASES_TABLE . ' i LEFT JOIN ' . TORRENTS_TABLE . ' t ON i.torrent_id = t.fid WHERE t.name IS NULL'); |
|---|
| | 32 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned indexreleases deleted', LOG_VIEW_SYSOP); |
|---|
| | 33 | $db->sql_query('DELETE c.* FROM ' . COMMENTS_NOTIFY_TABLE . ' c LEFT JOIN ' . TORRENTS_TABLE . ' t ON ( c.checkcomm_for_id = t.fid ) WHERE t.name IS NULL AND c.checkcomm_type = ' . TYPE_TORRENT); |
|---|
| | 34 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned comments notifis deleted', LOG_VIEW_SYSOP); |
|---|
| | 35 | $db->sql_query('DELETE b.* FROM ' . BOOKMARKS_TABLE . ' b LEFT JOIN ' . TORRENTS_TABLE . ' t ON b.torrentid = t.fid WHERE t.name IS NULL'); |
|---|
| | 36 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned bookmarks deleted', LOG_VIEW_SYSOP); |
|---|
| | 37 | $db->sql_query('DELETE s.* FROM ' . SNATCHED_TABLE . ' s LEFT JOIN ' . TORRENTS_TABLE . ' t ON s.torrentid = t.fid WHERE t.name IS NULL'); |
|---|
| | 38 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned snatched deleted', LOG_VIEW_SYSOP); |
|---|
| | 39 | $db->sql_query('DELETE r.* FROM ' . REPORTS_TABLE . ' r LEFT JOIN ' . TORRENTS_TABLE . ' t ON r.votedfor = t.fid WHERE t.name IS NULL AND r.type = 2'); |
|---|
| | 40 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned reports deleted', LOG_VIEW_SYSOP); |
|---|
| | 41 | break; |
|---|
| 50 | | $db->sql_query('DELETE m.* FROM ' . PRIVATE_MESSAGES_TABLE . ' m LEFT JOIN ' . USERS_TABLE . ' u ON m.sender = u.uid WHERE u.uid IS NULL'); |
|---|
| 51 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned private messages deleted', LOG_VIEW_SYSOP); |
|---|
| 52 | | $db->sql_query('DELETE m.* FROM ' . PRIVATE_MESSAGES_TABLE . ' m LEFT JOIN ' . USERS_TABLE . ' u ON m.receiver = u.uid WHERE u.uid IS NULL'); |
|---|
| 53 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned private messages deleted', LOG_VIEW_SYSOP); |
|---|
| 54 | | $db->sql_query('DELETE s.* FROM ' . SNATCHED_TABLE . ' s LEFT JOIN ' . USERS_TABLE . ' u ON s.userid = u.uid WHERE u.uid IS NULL'); |
|---|
| 55 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned snatched deleted', LOG_VIEW_SYSOP); |
|---|
| 56 | | $db->sql_query('DELETE f.* FROM ' . FRIENDS_TABLE . ' f LEFT JOIN ' . USERS_TABLE . ' u ON f.userid = u.uid WHERE u.uid IS NULL'); |
|---|
| 57 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned friends deleted', LOG_VIEW_SYSOP); |
|---|
| 58 | | $db->sql_query('DELETE f.* FROM ' . FRIENDS_TABLE . ' f LEFT JOIN ' . USERS_TABLE . ' u ON f.friendid = u.uid WHERE u.uid IS NULL'); |
|---|
| 59 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned friends deleted', LOG_VIEW_SYSOP); |
|---|
| 60 | | $db->sql_query('DELETE f.* FROM ' . FRIENDS_TABLE . ' f LEFT JOIN ' . USERS_TABLE . ' u ON f.blockid = u.uid WHERE u.uid IS NULL'); |
|---|
| 61 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned friends deleted', LOG_VIEW_SYSOP); |
|---|
| 62 | | $db->sql_query('DELETE r.* FROM ' . REPORTS_TABLE . ' r LEFT JOIN ' . USERS_TABLE . ' u ON r.addedby = u.uid WHERE u.uid IS NULL'); |
|---|
| 63 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned reports deleted', LOG_VIEW_SYSOP); |
|---|
| 64 | | $db->sql_query('DELETE r.* FROM ' . REPORTS_TABLE . ' r LEFT JOIN ' . USERS_TABLE . ' u ON r.votedfor = u.uid WHERE u.uid IS NULL AND r.type = 1'); |
|---|
| 65 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned reports deleted', LOG_VIEW_SYSOP); |
|---|
| 66 | | $db->sql_query('DELETE s.* FROM ' . SESSIONS_TABLE . ' s LEFT JOIN ' . USERS_TABLE . ' u ON s.session_user_id = u.uid WHERE u.uid IS NULL'); |
|---|
| 67 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned sessions deleted', LOG_VIEW_SYSOP); |
|---|
| 68 | | $db->sql_query('DELETE s.* FROM ' . SESSIONS_KEYS_TABLE . ' s LEFT JOIN ' . USERS_TABLE . ' u ON s.user_id = u.uid WHERE u.uid IS NULL'); |
|---|
| 69 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned session keys deleted', LOG_VIEW_SYSOP); |
|---|
| 70 | | //end sync tables, delete some old shit |
|---|
| | 43 | case 1: |
|---|
| | 44 | $db->sql_query('DELETE c.* FROM ' . COMMENTS_TABLE . ' c LEFT JOIN ' . REQUESTS_TABLE . ' r ON ( c.comment_for_id = r.id ) WHERE r.request IS NULL AND c.comment_type = ' . TYPE_REQUEST); |
|---|
| | 45 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned comments from requests deleted', LOG_VIEW_SYSOP); |
|---|
| | 46 | $db->sql_query('DELETE c.* FROM ' . COMMENTS_TABLE . ' c LEFT JOIN ' . OFFERS_TABLE . ' o ON ( c.comment_for_id = o.id ) WHERE o.name IS NULL AND c.comment_type = ' . TYPE_OFFER); |
|---|
| | 47 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned comments from offers deleted', LOG_VIEW_SYSOP); |
|---|
| | 48 | $db->sql_query('DELETE v.* FROM ' . REQUESTS_VOTES_TABLE . ' v LEFT JOIN ' . REQUESTS_TABLE . ' r ON v.requestid = r.id WHERE r.request IS NULL'); |
|---|
| | 49 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned requests votes deleted', LOG_VIEW_SYSOP); |
|---|
| | 50 | $db->sql_query('DELETE ov.* FROM ' . OFFERS_VOTES_TABLE . ' ov LEFT JOIN ' . OFFERS_TABLE . ' o ON ov.offerid = o.id WHERE o.name IS NULL'); |
|---|
| | 51 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned offers votes deleted', LOG_VIEW_SYSOP); |
|---|
| | 52 | break; |
|---|
| 72 | | //begin delete some old torrent-files and not torrent files from torrents dir |
|---|
| 73 | | $sql = 'SELECT fid FROM ' . TORRENTS_TABLE; |
|---|
| 74 | | $result = $db->sql_query($sql); |
|---|
| 75 | | $torrents = $files = $delete_files = array(); |
|---|
| 76 | | while ($row = $db->sql_fetchrow($result)) { |
|---|
| 77 | | $torrents[$row['fid']] = 1; |
|---|
| 78 | | } |
|---|
| 79 | | $torrent_dir = $root_path . ( !empty($config['torrent_dir']) ? $config['torrent_dir'] : 'torrents'); |
|---|
| | 54 | case 2: |
|---|
| | 55 | $db->sql_query('DELETE m.* FROM ' . PRIVATE_MESSAGES_TABLE . ' m LEFT JOIN ' . USERS_TABLE . ' u ON m.sender = u.uid WHERE u.uid IS NULL'); |
|---|
| | 56 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned private messages deleted', LOG_VIEW_SYSOP); |
|---|
| | 57 | $db->sql_query('DELETE m.* FROM ' . PRIVATE_MESSAGES_TABLE . ' m LEFT JOIN ' . USERS_TABLE . ' u ON m.receiver = u.uid WHERE u.uid IS NULL'); |
|---|
| | 58 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned private messages deleted', LOG_VIEW_SYSOP); |
|---|
| | 59 | $db->sql_query('DELETE s.* FROM ' . SNATCHED_TABLE . ' s LEFT JOIN ' . USERS_TABLE . ' u ON s.userid = u.uid WHERE u.uid IS NULL'); |
|---|
| | 60 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned snatched deleted', LOG_VIEW_SYSOP); |
|---|
| | 61 | $db->sql_query('DELETE f.* FROM ' . FRIENDS_TABLE . ' f LEFT JOIN ' . USERS_TABLE . ' u ON f.userid = u.uid WHERE u.uid IS NULL'); |
|---|
| | 62 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned friends deleted', LOG_VIEW_SYSOP); |
|---|
| | 63 | $db->sql_query('DELETE f.* FROM ' . FRIENDS_TABLE . ' f LEFT JOIN ' . USERS_TABLE . ' u ON f.friendid = u.uid WHERE u.uid IS NULL'); |
|---|
| | 64 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned friends deleted', LOG_VIEW_SYSOP); |
|---|
| | 65 | $db->sql_query('DELETE f.* FROM ' . FRIENDS_TABLE . ' f LEFT JOIN ' . USERS_TABLE . ' u ON f.blockid = u.uid WHERE u.uid IS NULL'); |
|---|
| | 66 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned friends deleted', LOG_VIEW_SYSOP); |
|---|
| | 67 | $db->sql_query('DELETE r.* FROM ' . REPORTS_TABLE . ' r LEFT JOIN ' . USERS_TABLE . ' u ON r.addedby = u.uid WHERE u.uid IS NULL'); |
|---|
| | 68 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned reports deleted', LOG_VIEW_SYSOP); |
|---|
| | 69 | $db->sql_query('DELETE r.* FROM ' . REPORTS_TABLE . ' r LEFT JOIN ' . USERS_TABLE . ' u ON r.votedfor = u.uid WHERE u.uid IS NULL AND r.type = 1'); |
|---|
| | 70 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned reports deleted', LOG_VIEW_SYSOP); |
|---|
| | 71 | $db->sql_query('DELETE s.* FROM ' . SESSIONS_TABLE . ' s LEFT JOIN ' . USERS_TABLE . ' u ON s.session_user_id = u.uid WHERE u.uid IS NULL'); |
|---|
| | 72 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned sessions deleted', LOG_VIEW_SYSOP); |
|---|
| | 73 | $db->sql_query('DELETE s.* FROM ' . SESSIONS_KEYS_TABLE . ' s LEFT JOIN ' . USERS_TABLE . ' u ON s.user_id = u.uid WHERE u.uid IS NULL'); |
|---|
| | 74 | write_log('docleanup - ' . $db->sql_affectedrows() . ' orphaned session keys deleted', LOG_VIEW_SYSOP); |
|---|
| | 75 | break; |
|---|
| 81 | | if ( $dp = opendir($torrent_dir . DIRECTORY_SEPARATOR) ) { |
|---|
| 82 | | while ( ( $file = readdir($dp) ) !== false ) { |
|---|
| 83 | | if ( $file != '.' && $file != '..' && !is_dir($torrent_dir . DIRECTORY_SEPARATOR . $file) ) { |
|---|
| 84 | | if ( !preg_match('/^(\d+)\.torrent$/', $file, $matches) ) { |
|---|
| 85 | | $delete_files[] = $file; |
|---|
| 86 | | } |
|---|
| 87 | | else { |
|---|
| 88 | | if ( !isset($torrents[$matches[1]]) ) { |
|---|
| 89 | | $delete_files[] = $file; |
|---|
| | 77 | case 3: |
|---|
| | 78 | //begin delete some old torrent-files and not torrent files from torrents dir |
|---|
| | 79 | $sql = 'SELECT fid FROM ' . TORRENTS_TABLE; |
|---|
| | 80 | $result = $db->sql_query($sql); |
|---|
| | 81 | $torrents = $files = $delete_files = array(); |
|---|
| | 82 | while ($row = $db->sql_fetchrow($result)) { |
|---|
| | 83 | $torrents[$row['fid']] = 1; |
|---|
| | 84 | } |
|---|
| | 85 | $torrent_dir = $root_path . ( !empty($config['torrent_dir']) ? $config['torrent_dir'] : 'torrents'); |
|---|
| | 86 | |
|---|
| | 87 | if ( $dp = opendir($torrent_dir . DIRECTORY_SEPARATOR) ) { |
|---|
| | 88 | while ( ( $file = readdir($dp) ) !== false ) { |
|---|
| | 89 | if ( $file != '.' && $file != '..' && !is_dir($torrent_dir . DIRECTORY_SEPARATOR . $file) ) { |
|---|
| | 90 | if ( !preg_match('/^(\d+)\.torrent$/', $file, $matches) ) { |
|---|
| | 91 | $delete_files[] = $file; |
|---|
| | 92 | } |
|---|
| | 93 | else { |
|---|
| | 94 | if ( !isset($torrents[$matches[1]]) ) { |
|---|
| | 95 | $delete_files[] = $file; |
|---|
| | 96 | } |
|---|
| | 97 | } |
|---|
| 93 | | } |
|---|
| 94 | | closedir($dp); |
|---|
| 95 | | } |
|---|
| 96 | | if ( sizeof($delete_files) ) { |
|---|
| 97 | | for ( $i = 0; $i < sizeof($delete_files); ++$i ) { |
|---|
| 98 | | @unlink($torrent_dir . '/' . $delete_files[$i]); |
|---|
| 99 | | write_log('docleanup - ' . $delete_files[$i] . ' file deleted - not present in torrents table', LOG_VIEW_SYSOP); |
|---|
| 100 | | } |
|---|
| 101 | | } |
|---|
| 102 | | //end delete some old torrent-files and not torrent files from torrents dir |
|---|
| | 102 | if ( sizeof($delete_files) ) { |
|---|
| | 103 | for ( $i = 0; $i < sizeof($delete_files); ++$i ) { |
|---|
| | 104 | @unlink($torrent_dir . '/' . $delete_files[$i]); |
|---|
| | 105 | write_log('docleanup - ' . $delete_files[$i] . ' file deleted - not present in torrents table', LOG_VIEW_SYSOP); |
|---|
| | 106 | } |
|---|
| | 107 | } |
|---|
| | 108 | //end delete some old torrent-files and not torrent files from torrents dir |
|---|
| | 109 | break; |
|---|
| 117 | | foreach ( $user_uid AS $pms_count => $ary ) { |
|---|
| 118 | | $sql = 'UPDATE ' . USERS_TABLE . ' SET user_unread_pms = ' . $pms_count . ' WHERE ' . $db->sql_in_set('uid', $ary); |
|---|
| | 125 | foreach ( $user_uid AS $pms_count => $ary ) { |
|---|
| | 126 | $sql = 'UPDATE ' . USERS_TABLE . ' SET user_unread_pms = ' . $pms_count . ' WHERE ' . $db->sql_in_set('uid', $ary); |
|---|
| | 127 | $db->sql_query($sql); |
|---|
| | 128 | } |
|---|
| | 129 | |
|---|
| | 130 | write_log('docleanup - ' . sizeof($user_uid) . ' user PMs count updated', LOG_VIEW_SYSOP); |
|---|
| | 131 | } |
|---|
| | 132 | break; |
|---|
| | 133 | |
|---|
| | 134 | case 5: |
|---|
| | 135 | $user_limit_ary_torrents = unserialize($config['user_limit_ary_torrents']); |
|---|
| | 136 | $user_limit_ary_allow_download = unserialize($config['user_limit_ary_allow_download']); |
|---|
| | 137 | $users_class_arr = array(); |
|---|
| | 138 | $i = 0; |
|---|
| | 139 | while ( get_user_class_name($i) !== '' ) { |
|---|
| | 140 | $can_leech = ( isset($user_limit_ary_allow_download[$i]) ? 1 : 0 ); |
|---|
| | 141 | $sql = 'UPDATE ' . USERS_TABLE . ' SET torrents_limit = ' . $user_limit_ary_torrents[$i] . ', can_leech = ' . $can_leech . ' WHERE class = ' . $i; |
|---|
| | 142 | $db->sql_query($sql); |
|---|
| | 143 | ++$i; |
|---|
| | 144 | write_log('docleanup - ' . $db->sql_affectedrows() . ' users torrent limits updated', LOG_VIEW_SYSOP); |
|---|
| | 145 | } |
|---|
| | 146 | |
|---|
| | 147 | $sql = 'UPDATE ' . USERS_TABLE . ' SET torrents_limit = ' . $user_limit_ary_torrents['D'] . ' WHERE donor = 1'; |
|---|
| 122 | | write_log('docleanup - ' . sizeof($user_uid) . ' user PMs count updated', LOG_VIEW_SYSOP); |
|---|
| | 151 | $sql = 'UPDATE ' . USERS_TABLE . ' SET torrents_limit = ' . $user_limit_ary_torrents['W'] . ' WHERE warneduntil > 0'; |
|---|
| | 152 | $db->sql_query($sql); |
|---|
| | 153 | write_log('docleanup - ' . $db->sql_affectedrows() . ' users torrent limits updated', LOG_VIEW_SYSOP); |
|---|
| | 154 | break; |
|---|
| | 155 | |
|---|
| | 156 | case 6: |
|---|
| | 157 | $sql = 'SELECT t.fid, u.uid FROM ' . TORRENTS_TABLE . ' t LEFT JOIN ' . USERS_TABLE . ' u ON ( t.owner = u.uid ) WHERE u.uid IS NULL'; |
|---|
| | 158 | $result = $db->sql_query($sql); |
|---|
| | 159 | if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| | 160 | $i = 0; |
|---|
| | 161 | do { |
|---|
| | 162 | $sql = 'UPDATE ' . TORRENTS_TABLE . ' SET owner = ' . ANONYMOUS . ' WHERE fid = ' . $row['fid']; |
|---|
| | 163 | $db->sql_query($sql); |
|---|
| | 164 | |
|---|
| | 165 | ++$i; |
|---|
| | 166 | } |
|---|
| | 167 | while ( $row = $db->sql_fetchrow($result) ); |
|---|
| | 168 | |
|---|
| | 169 | write_log('docleanup - ' . $i . ' torrent owner fixed', LOG_VIEW_SYSOP); |
|---|
| | 170 | } |
|---|
| | 171 | break; |
|---|
| | 172 | |
|---|
| | 173 | default: |
|---|
| | 174 | trigger_error('all is ok'); |
|---|
| | 175 | break; |
|---|
| | 176 | |
|---|
| 125 | | $user_limit_ary_torrents = unserialize($config['user_limit_ary_torrents']); |
|---|
| 126 | | $user_limit_ary_allow_download = unserialize($config['user_limit_ary_allow_download']); |
|---|
| 127 | | $users_class_arr = array(); |
|---|
| 128 | | $i = 0; |
|---|
| 129 | | while ( get_user_class_name($i) !== '' ) { |
|---|
| 130 | | $can_leech = ( isset($user_limit_ary_allow_download[$i]) ? 1 : 0 ); |
|---|
| 131 | | $sql = 'UPDATE ' . USERS_TABLE . ' SET torrents_limit = ' . $user_limit_ary_torrents[$i] . ', can_leech = ' . $can_leech . ' WHERE class = ' . $i; |
|---|
| 132 | | $db->sql_query($sql); |
|---|
| 133 | | ++$i; |
|---|
| 134 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' users torrent limits updated', LOG_VIEW_SYSOP); |
|---|
| 135 | | } |
|---|
| 136 | | |
|---|
| 137 | | $sql = 'UPDATE ' . USERS_TABLE . ' SET torrents_limit = ' . $user_limit_ary_torrents['D'] . ' WHERE donor = 1'; |
|---|
| 138 | | $db->sql_query($sql); |
|---|
| 139 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' users torrent limits updated', LOG_VIEW_SYSOP); |
|---|
| 140 | | |
|---|
| 141 | | $sql = 'UPDATE ' . USERS_TABLE . ' SET torrents_limit = ' . $user_limit_ary_torrents['W'] . ' WHERE warneduntil > 0'; |
|---|
| 142 | | $db->sql_query($sql); |
|---|
| 143 | | write_log('docleanup - ' . $db->sql_affectedrows() . ' users torrent limits updated', LOG_VIEW_SYSOP); |
|---|
| 144 | | |
|---|
| 145 | | $sql = 'SELECT t.fid, u.uid FROM ' . TORRENTS_TABLE . ' t LEFT JOIN ' . USERS_TABLE . ' u ON ( t.owner = u.uid ) WHERE u.uid IS NULL'; |
|---|
| 146 | | $result = $db->sql_query($sql); |
|---|
| 147 | | if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 148 | | $i = 0; |
|---|
| 149 | | do { |
|---|
| 150 | | $sql = 'UPDATE ' . TORRENTS_TABLE . ' SET owner = ' . ANONYMOUS . ' WHERE fid = ' . $row['fid']; |
|---|
| 151 | | $db->sql_query($sql); |
|---|
| 152 | | |
|---|
| 153 | | ++$i; |
|---|
| 154 | | } |
|---|
| 155 | | while ( $row = $db->sql_fetchrow($result) ); |
|---|
| 156 | | |
|---|
| 157 | | write_log('docleanup - ' . $i . ' torrent owner fixed', LOG_VIEW_SYSOP); |
|---|
| 158 | | } |
|---|
| 159 | | |
|---|
| 160 | | trigger_error('all is ok'); |
|---|
| | 179 | meta_refresh(10, append_sid($root_path . 'docleanup.php?step=' . ($step + 1) )); |
|---|
| | 180 | trigger_error('Wait 10 seconds'); |
|---|