/** * Delete releases using admin settings. * This deletes releases, regardless of group. * * @void * @access public */ public function deleteReleases() { $startTime = time(); $category = new Category(['Settings' => $this->pdo]); $genres = new Genres(['Settings' => $this->pdo]); $passwordDeleted = $duplicateDeleted = $retentionDeleted = $completionDeleted = $disabledCategoryDeleted = 0; $disabledGenreDeleted = $miscRetentionDeleted = $miscHashedDeleted = $categoryMinSizeDeleted = 0; // Delete old releases and finished collections. if ($this->echoCLI) { $this->pdo->log->doEcho($this->pdo->log->header("Process Releases -> Delete old releases and passworded releases.")); } // Releases past retention. if ($this->pdo->getSetting('releaseretentiondays') != 0) { $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE postdate < (NOW() - INTERVAL %d DAY)', $this->pdo->getSetting('releaseretentiondays'))); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $retentionDeleted++; } } } // Passworded releases. if ($this->pdo->getSetting('deletepasswordedrelease') == 1) { $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE passwordstatus = %d', Releases::PASSWD_RAR)); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $passwordDeleted++; } } } // Possibly passworded releases. if ($this->pdo->getSetting('deletepossiblerelease') == 1) { $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE passwordstatus = %d', Releases::PASSWD_POTENTIAL)); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $passwordDeleted++; } } } if ($this->crossPostTime != 0) { // Crossposted releases. do { $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE adddate > (NOW() - INTERVAL %d HOUR) GROUP BY name HAVING COUNT(name) > 1', $this->crossPostTime)); $total = 0; if ($releases && $releases->rowCount()) { $total = $releases->rowCount(); foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $duplicateDeleted++; } } } while ($total > 0); } if ($this->completion > 0) { $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE completion < %d AND completion > 0', $this->completion)); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $completionDeleted++; } } } // Disabled categories. $disabledCategories = $category->getDisabledIDs(); if (count($disabledCategories) > 0) { foreach ($disabledCategories as $disabledCategory) { $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE categoryid = %d', $disabledCategory['id'])); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $disabledCategoryDeleted++; $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); } } } } // Delete smaller than category minimum sizes. $categories = $this->pdo->queryDirect(' SELECT SQL_NO_CACHE c.id AS id, CASE WHEN c.minsize = 0 THEN cp.minsize ELSE c.minsize END AS minsize FROM category c INNER JOIN category cp ON cp.id = c.parentid WHERE c.parentid IS NOT NULL'); if ($categories instanceof \Traversable) { foreach ($categories as $category) { if ($category['minsize'] > 0) { $releases = $this->pdo->queryDirect(sprintf(' SELECT SQL_NO_CACHE r.id, r.guid FROM releases r WHERE r.categoryid = %d AND r.size < %d LIMIT 1000', $category['id'], $category['minsize'])); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $categoryMinSizeDeleted++; } } } } } // Disabled music genres. $genrelist = $genres->getDisabledIDs(); if (count($genrelist) > 0) { foreach ($genrelist as $genre) { $releases = $this->pdo->queryDirect(sprintf(' SELECT SQL_NO_CACHE id, guid FROM releases INNER JOIN (SELECT id AS mid FROM musicinfo WHERE musicinfo.genre_id = %d) mi ON musicinfoid = mid', $genre['id'])); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $disabledGenreDeleted++; $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); } } } } // Misc other. if ($this->pdo->getSetting('miscotherretentionhours') > 0) { $releases = $this->pdo->queryDirect(sprintf(' SELECT SQL_NO_CACHE id, guid FROM releases WHERE categoryid = %d AND adddate <= NOW() - INTERVAL %d HOUR', Category::CAT_OTHER_MISC, $this->pdo->getSetting('miscotherretentionhours'))); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $miscRetentionDeleted++; } } } // Misc hashed. if ($this->pdo->getSetting('mischashedretentionhours') > 0) { $releases = $this->pdo->queryDirect(sprintf(' SELECT SQL_NO_CACHE id, guid FROM releases WHERE categoryid = %d AND adddate <= NOW() - INTERVAL %d HOUR', Category::CAT_OTHER_HASHED, $this->pdo->getSetting('mischashedretentionhours'))); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $miscHashedDeleted++; } } } if ($this->echoCLI) { $this->pdo->log->doEcho($this->pdo->log->primary('Removed releases: ' . number_format($retentionDeleted) . ' past retention, ' . number_format($passwordDeleted) . ' passworded, ' . number_format($duplicateDeleted) . ' crossposted, ' . number_format($disabledCategoryDeleted) . ' from disabled categories, ' . number_format($categoryMinSizeDeleted) . ' smaller than category settings, ' . number_format($disabledGenreDeleted) . ' from disabled music genres, ' . number_format($miscRetentionDeleted) . ' from misc->other' . number_format($miscHashedDeleted) . ' from misc->hashed' . ($this->completion > 0 ? ', ' . number_format($completionDeleted) . ' under ' . $this->completion . '% completion.' : '.'))); $totalDeleted = $retentionDeleted + $passwordDeleted + $duplicateDeleted + $disabledCategoryDeleted + $disabledGenreDeleted + $miscRetentionDeleted + $miscHashedDeleted + $completionDeleted + $categoryMinSizeDeleted; if ($totalDeleted > 0) { $this->pdo->log->doEcho($this->pdo->log->primary("Removed " . number_format($totalDeleted) . ' releases in ' . $this->consoleTools->convertTime(time() - $startTime))); } } }
/* Deletes releases in categories you have disabled here : http://localhost/admin/category-list.php */ require dirname(__FILE__) . '/../../../www/config.php'; use nzedb\Category; use nzedb\NZB; use nzedb\ReleaseImage; use nzedb\Releases; use nzedb\db\Settings; $pdo = new Settings(); if (isset($argv[1]) && $argv[1] == "true") { $timestart = TIME(); $releases = new Releases(['Settings' => $pdo]); $category = new Category(['Settings' => $pdo]); $nzb = new NZB($pdo); $releaseImage = new ReleaseImage($pdo); $catlist = $category->getDisabledIDs(); $relsdeleted = 0; if (count($catlist > 0)) { foreach ($catlist as $cat) { $rels = $pdo->query(sprintf("SELECT id, guid FROM releases WHERE categoryid = %d", $cat['id'])); if (count($rels)) { foreach ($rels as $rel) { $relsdeleted++; $releases->deleteSingle(['g' => $rel['guid'], 'i' => $rel['id']], $nzb, $releaseImage); } } } } $time = TIME() - $timestart; if ($relsdeleted > 0) { echo $pdo->log->header($relsdeleted . " releases deleted in " . $time . " seconds.");