function reCategorize($argv) { global $pdo; $where = ''; $othercats = Category::getCategoryOthersGroup(); $update = true; if (isset($argv[1]) && is_numeric($argv[1])) { $where = ' AND group_id = ' . $argv[1]; } else { if (isset($argv[1]) && preg_match('/\\([\\d, ]+\\)/', $argv[1])) { $where = ' AND group_id IN ' . $argv[1]; } else { if (isset($argv[1]) && $argv[1] === 'misc') { $where = sprintf(' AND categoryid IN (%s)', $othercats); } } } if (isset($argv[2]) && $argv[2] === 'test') { $update = false; } if (isset($argv[1]) && (is_numeric($argv[1]) || preg_match('/\\([\\d, ]+\\)/', $argv[1]))) { echo $pdo->log->header("Categorizing all releases in {$argv[1]} using searchname. This can take a while, be patient."); } else { if (isset($argv[1]) && $argv[1] == "misc") { echo $pdo->log->header("Categorizing all releases in misc categories using searchname. This can take a while, be patient."); } else { echo $pdo->log->header("Categorizing all releases using searchname. This can take a while, be patient."); } } $timestart = TIME(); if (isset($argv[1]) && (is_numeric($argv[1]) || preg_match('/\\([\\d, ]+\\)/', $argv[1])) || $argv[1] === 'misc') { $chgcount = categorizeRelease(str_replace(" AND", "WHERE", $where), $update, true); } else { $chgcount = categorizeRelease('', $update, true); } $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]); $time = $consoletools->convertTime(TIME() - $timestart); if ($update === true) { echo $pdo->log->header("Finished re-categorizing " . number_format($chgcount) . " releases in " . $time . " , using the searchname.\n"); } else { echo $pdo->log->header("Finished re-categorizing in " . $time . " , using the searchname.\n" . "This would have changed " . number_format($chgcount) . " releases but no updates were done.\n"); } }
/** * @param array $options Class instances / Echo to cli. */ public function __construct(array $options = []) { $defaults = ['Echo' => true, 'Categorize' => null, 'ConsoleTools' => null, 'Groups' => null, 'Misc' => null, 'Settings' => null, 'SphinxSearch' => null]; $options += $defaults; $this->echooutput = $options['Echo'] && nZEDb_ECHOCLI; $this->relid = $this->fixed = $this->checked = 0; $this->pdo = $options['Settings'] instanceof Settings ? $options['Settings'] : new Settings(); $this->othercats = Category::getCategoryOthersGroup(); $this->timeother = sprintf(' AND rel.adddate > (NOW() - INTERVAL 6 HOUR) AND rel.categoryid IN (%s) GROUP BY rel.id ORDER BY postdate DESC', $this->othercats); $this->timeall = ' AND rel.adddate > (NOW() - INTERVAL 6 HOUR) GROUP BY rel.id ORDER BY postdate DESC'; $this->fullother = sprintf(' AND rel.categoryid IN (%s) GROUP BY rel.id', $this->othercats); $this->fullall = ''; $this->_fileName = ''; $this->done = $this->matched = false; $this->consoletools = $options['ConsoleTools'] instanceof ConsoleTools ? $options['ConsoleTools'] : new ConsoleTools(['ColorCLI' => $this->pdo->log]); $this->category = $options['Categorize'] instanceof Categorize ? $options['Categorize'] : new Categorize(['Settings' => $this->pdo]); $this->text = $options['Misc'] instanceof Text ? $options['Misc'] : new Text(); $this->_groups = $options['Groups'] instanceof Groups ? $options['Groups'] : new Groups(['Settings' => $this->pdo]); $this->sphinx = $options['SphinxSearch'] instanceof SphinxSearch ? $options['SphinxSearch'] : new SphinxSearch(); }
/** * Matches the hashes within the predb table to release files and subjects (names) which are hashed. * * @param $time * @param $echo * @param $cats * @param $namestatus * @param $show * * @return int */ public function parseTitles($time, $echo, $cats, $namestatus, $show) { $namefixer = new NameFixer(['Echo' => $this->echooutput, 'ConsoleTools' => $this->pdo->log, 'Settings' => $this->pdo]); $consoletools = new ConsoleTools(['ColorCLI' => $this->pdo->log]); $othercats = Category::getCategoryOthersGroup(); $updated = $checked = 0; $tq = ''; if ($time == 1) { $tq = 'AND r.adddate > (NOW() - INTERVAL 3 HOUR) ORDER BY rf.releaseid, rf.size DESC'; } $ct = ''; if ($cats == 1) { $ct = sprintf('AND r.categoryid IN (%s)', $othercats); } if ($this->echooutput) { $te = ''; if ($time == 1) { $te = ' in the past 3 hours'; } echo $this->pdo->log->header('Fixing search names' . $te . " using the predb hash."); } $regex = "AND (r.ishashed = 1 OR rf.ishashed = 1)"; if ($cats === 3) { $query = sprintf('SELECT r.id AS releaseid, r.name, r.searchname, r.categoryid, r.group_id, ' . 'dehashstatus, rf.name AS filename FROM releases r ' . 'LEFT OUTER JOIN release_files rf ON r.id = rf.releaseid ' . 'WHERE nzbstatus = 1 AND dehashstatus BETWEEN -6 AND 0 AND preid = 0 %s', $regex); } else { $query = sprintf('SELECT r.id AS releaseid, r.name, r.searchname, r.categoryid, r.group_id, ' . 'dehashstatus, rf.name AS filename FROM releases r ' . 'LEFT OUTER JOIN release_files rf ON r.id = rf.releaseid ' . 'WHERE nzbstatus = 1 AND isrenamed = 0 AND dehashstatus BETWEEN -6 AND 0 %s %s %s', $regex, $ct, $tq); } $res = $this->pdo->queryDirect($query); $total = $res->rowCount(); echo $this->pdo->log->primary(number_format($total) . " releases to process."); if ($res instanceof \Traversable) { foreach ($res as $row) { if (preg_match('/[a-fA-F0-9]{32,40}/i', $row['name'], $matches)) { $updated = $updated + $namefixer->matchPredbHash($matches[0], $row, $echo, $namestatus, $this->echooutput, $show); } else { if (preg_match('/[a-fA-F0-9]{32,40}/i', $row['filename'], $matches)) { $updated = $updated + $namefixer->matchPredbHash($matches[0], $row, $echo, $namestatus, $this->echooutput, $show); } } if ($show === 2) { $consoletools->overWritePrimary("Renamed Releases: [" . number_format($updated) . "] " . $consoletools->percentString(++$checked, $total)); } } } if ($echo == 1) { echo $this->pdo->log->header("\n" . $updated . " releases have had their names changed out of: " . number_format($checked) . " files."); } else { echo $this->pdo->log->header("\n" . $updated . " releases could have their names changed. " . number_format($checked) . " files were checked."); } return $updated; }