From c20b7856abc9c3eec7db31e3e66f565a72aa0a20 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Sat, 16 May 2015 03:25:53 +0200 Subject: [PATCH] Move CBP deletion. --- lib/copy_this/newznab/controllers/NZB.php | 62 +++++++++++-------- .../newznab/controllers/TmuxOutput.php | 2 +- .../newznab/processing/ProcessReleases.php | 42 +++---------- 3 files changed, 43 insertions(+), 63 deletions(-) diff --git a/lib/copy_this/newznab/controllers/NZB.php b/lib/copy_this/newznab/controllers/NZB.php index da6c7d8c0..a3c0b403d 100644 --- a/lib/copy_this/newznab/controllers/NZB.php +++ b/lib/copy_this/newznab/controllers/NZB.php @@ -8,6 +8,9 @@ use newznab\db\DB; */ class NZB { + const NZB_NONE = 0; // Release has no NZB file yet. + const NZB_ADDED = 1; // Release had an NZB file created. + /** * Determines if the site setting table per group is enabled. * @var bool @@ -76,8 +79,12 @@ class NZB */ protected $_nzbHeadString; - const NZB_NONE = 0; // Release has no NZB file yet. - const NZB_ADDED = 1; // Release had an NZB file created. + /** + * Names of CBP tables. + * @var array [string => string] + * @access protected + */ + protected $_tableNames; /** * Default constructor. @@ -111,19 +118,22 @@ class NZB public function initiateForWrite($groupID) { $this->groupID = $groupID; - $site = new Sites(); // Set table names if ($this->tablePerGroup === true) { if ($this->groupID == '') { exit("$this->groupID is missing\n"); } - $cName = 'collections_' .$this->groupID; - $bName = 'binaries_' . $this->groupID; - $pName = 'parts_' . $this->groupID; + $this->_tableNames = [ + 'cName' => 'collections_' . $this->groupID, + 'bName' => 'binaries_' . $this->groupID, + 'pName' => 'parts_' . $this->groupID + ]; } else { - $cName = 'collections'; - $bName = 'binaries'; - $pName = 'parts'; + $this->_tableNames = [ + 'cName' => 'collections', + 'bName' => 'binaries', + 'pName' => 'parts' + ]; } $this->_collectionsQuery = sprintf( @@ -131,22 +141,23 @@ class NZB FROM %s INNER JOIN groups ON %s.group_id = groups.id WHERE %s.releaseid = ', - $cName, - $cName, - $cName, - $cName, - $cName + $this->_tableNames['cName'], + $this->_tableNames['cName'], + $this->_tableNames['cName'], + $this->_tableNames['cName'], + $this->_tableNames['cName'] ); $this->_binariesQuery = ( - 'SELECT id, name, totalparts FROM '. $bName .' WHERE collection_id = %d ORDER BY name' + 'SELECT id, name, totalparts FROM ' . $this->_tableNames['bName'] . ' WHERE collection_id = %d ORDER BY name' ); $this->_partsQuery = ( - 'SELECT DISTINCT(messageid), size, partnumber FROM ' . $pName . ' WHERE binaryid = %d ORDER BY partnumber' + 'SELECT DISTINCT(messageid), size, partnumber FROM ' . $this->_tableNames['pName'] . + ' WHERE binaryid = %d ORDER BY partnumber' ); $this->_nzbHeadString = ( - "\n\n\n\n\n %s\n %s\n\n\n" ); } @@ -154,7 +165,7 @@ class NZB /** * Write an NZB to the hard drive for a single release. * - * @param int $relID The id of the release in the DB. + * @param int $relID The ID of the release in the DB. * @param string $relGuid The guid of the release. * @param string $name The name of the release. * @param string $cTitle The name of the category this release is in. @@ -169,7 +180,6 @@ class NZB $fp = gzopen($path, 'wb7'); if ($fp) { $nzb_guid = ''; - $gid = ''; gzwrite( $fp, sprintf( @@ -202,9 +212,6 @@ class NZB if ($nzb_guid === '') { $nzb_guid = $part['messageid']; } - if ($gid === '') { - $gid = $part['messageid']; - } $string .= ( ' ' @@ -230,13 +237,14 @@ class NZB gzclose($fp); if (is_file($path)) { + // Mark release as having NZB and delete CBP. $this->pdo->queryExec( sprintf(' - UPDATE releases SET nzbstatus = %d %s %s WHERE id = %d', - \NZB::NZB_ADDED, + UPDATE releases SET nzbstatus = %d %s WHERE id = %d; + DELETE FROM %s WHERE releaseid = %d', + NZB::NZB_ADDED, ($nzb_guid === '' ? '' : ', nzb_guid = ' . $this->pdo->escapestring(md5($nzb_guid))), - ($gid === '' ? '' : ', gid = ' . $this->pdo->escapestring(md5($gid))), - $relID + $relID, $this->_tableNames['cName'], $relID ) ); diff --git a/lib/copy_this/newznab/controllers/TmuxOutput.php b/lib/copy_this/newznab/controllers/TmuxOutput.php index d84d920d7..5ef6dff85 100644 --- a/lib/copy_this/newznab/controllers/TmuxOutput.php +++ b/lib/copy_this/newznab/controllers/TmuxOutput.php @@ -112,7 +112,7 @@ class TmuxOutput extends Tmux $buffer = ''; $state = ($this->runVar['settings']['is_running'] == 1) ? 'Running' : 'Disabled'; //$version = $this->_tvers . 'r' . $this->_vers; - $tversion = '0.6r0218'; + $tversion = '0.6r0221'; $buffer .= sprintf($this->tmpMasks[2], "Monitor $state v$tversion @ $this->_tvers [" . $this->_vers ."]: ", diff --git a/lib/copy_this/newznab/processing/ProcessReleases.php b/lib/copy_this/newznab/processing/ProcessReleases.php index 2f1f8e6a6..bc38e357f 100644 --- a/lib/copy_this/newznab/processing/ProcessReleases.php +++ b/lib/copy_this/newznab/processing/ProcessReleases.php @@ -660,7 +660,6 @@ class ProcessReleases public function createNZBs($groupID) { $startTime = time(); - $group = $this->groups->getCBPTableNames($this->tablePerGroup, $groupID); if ($this->echoCLI) { $this->pdo->log->doEcho($this->pdo->log->header("Process Releases -> Create the NZB, delete collections/binaries/parts.")); @@ -674,11 +673,11 @@ class ProcessReleases INNER JOIN category c ON r.categoryid = c.id INNER JOIN category cp ON cp.id = c.parentid WHERE %s nzbstatus = 0", - (!empty($groupID) ? ' r.groupid = ' . $groupID . ' AND ' : ' ') + (!empty($groupID) ? ' r.group_id = ' . $groupID . ' AND ' : ' ') ) ); - $deleted = $nzbCount = 0; + $nzbCount = 0; if ($releases && $releases->rowCount()) { $total = $releases->rowCount(); @@ -689,47 +688,20 @@ class ProcessReleases if ($this->nzb->writeNZBforReleaseId($release['id'], $release['guid'], $release['name'], $release['title']) === true) { $nzbCount++; if ($this->echoCLI) { - echo $this->pdo->log->primaryOver("Creating NZBs:\t" . $nzbCount . '/' . $total . "\r"); + echo $this->pdo->log->primaryOver("Creating NZBs and deleting Collections:\t" . $nzbCount . '/' . $total . "\r"); } } } } - $nzbEnd = time(); - - if ($nzbCount > 0) { - if ($this->echoCLI) { - $this->pdo->log->doEcho( - $this->pdo->log->primary( - PHP_EOL . 'Deleting collections/binaries/parts, be patient.' - ) - ); - } - - $deleteQuery = $this->pdo->queryExec( - sprintf(' - DELETE c FROM %s c - INNER JOIN releases r ON r.id = c.releaseid - WHERE r.nzbstatus = %d - AND c.filecheck = %d', - $group['cname'], - \NZB::NZB_ADDED, - self::COLLFC_INSERTED - ) - ); - if ($deleteQuery !== false) { - $deleted = $deleteQuery->rowCount(); - } - } - - $deleteEnd = time(); + $totalTime = (time() - $startTime); if ($this->echoCLI) { $this->pdo->log->doEcho( $this->pdo->log->primary( - number_format($nzbCount) . ' NZBs created in ' . ($nzbEnd - $startTime) . ' seconds.' . PHP_EOL . - 'Deleted ' . number_format($deleted) . ' collections in ' . ($deleteEnd - $nzbEnd) . ' seconds.' . PHP_EOL . - 'Total time: ' . $this->pdo->log->primary($this->consoleTools->convertTime(time() - $startTime)) + number_format($nzbCount) . ' NZBs created/Collections deleted in ' . + $totalTime . ' seconds.' . PHP_EOL . + 'Total time: ' . $this->pdo->log->primary($this->consoleTools->convertTime($totalTime)) ) ); }