//$consoleTools = new \ConsoleTools(); foreach ($objects as $filestoprocess => $nzbFile) { if ($nzbFile->getExtension() != "gz") { continue; } $newFileName = $nzb->getNZBPath(str_replace(".nzb.gz", "", $nzbFile->getBasename()), $newLevel, true); if ($newFileName != $nzbFile) { rename($nzbFile, $newFileName); chmod($newFileName, 0777); } $iFilesProcessed++; if ($iFilesProcessed % 100 == 0) { $consoleTools->overWrite("Reorganized {$iFilesProcessed}"); } } $pdo->ping(true); $pdo->queryExec(sprintf("UPDATE settings SET value = %s WHERE setting = 'nzbsplitlevel'", $argv[1])); $consoleTools->overWrite("Processed {$iFilesProcessed} nzbs in " . relativeTime($time) . "\n"); function relativeTime($_time) { $d = array(); $d[0] = array(1, "sec"); $d[1] = array(60, "min"); $d[2] = array(3600, "hr"); $d[3] = array(86400, "day"); $d[4] = array(31104000, "yr"); $w = array(); $return = ""; $now = TIME(); $diff = $now - $_time; $secondsLeft = $diff;
//create timers and set to now $runVar['timers']['timer1'] = $runVar['timers']['timer2'] = $runVar['timers']['timer3'] = $runVar['timers']['timer4'] = $runVar['timers']['timer5'] = time(); $runVar['timers']['query']['tmux_time'] = $runVar['timers']['query']['split_time'] = $runVar['timers']['query']['init_time'] = $runVar['timers']['query']['proc1_time'] = $runVar['timers']['query']['proc2_time'] = $runVar['timers']['query']['proc3_time'] = $runVar['timers']['query']['split1_time'] = $runVar['timers']['query']['init1_time'] = $runVar['timers']['query']['proc11_time'] = $runVar['timers']['query']['proc21_time'] = $runVar['timers']['query']['proc31_time'] = $runVar['timers']['query']['tpg_time'] = $runVar['timers']['query']['tpg1_time'] = 0; // Analyze tables printf($pdo->log->info("\nAnalyzing your tables to refresh your indexes.")); $pdo->optimise(false, 'analyze', false, ['releases']); Misc::clearScreen(); $runVar['settings']['monitor'] = 0; $runVar['counts']['iterations'] = 1; $runVar['modsettings']['fc']['firstrun'] = true; $runVar['modsettings']['fc']['num'] = 0; $tblCount = "SELECT TABLE_ROWS AS count FROM information_schema.TABLES WHERE TABLE_NAME = :table AND TABLE_SCHEMA = " . $pdo->escapeString($db_name); $psTableRowCount = $pdo->Prepare($tblCount); while ($runVar['counts']['iterations'] > 0) { //check the db connection if ($pdo->ping(true) == false) { unset($pdo); $pdo = new Settings(); } $timer01 = time(); // These queries are very fast, run every loop -- tmux and site settings $runVar['settings'] = $pdo->queryOneRow($tRun->getMonitorSettings(), false); $runVar['timers']['query']['tmux_time'] = time() - $timer01; $runVar['settings']['book_reqids'] = !empty($runVar['settings']['book_reqids']) ? $runVar['settings']['book_reqids'] : Category::CAT_PARENT_BOOKS; //get usenet connection info $runVar['connections'] = $tOut->getConnectionsInfo($runVar['constants']); $runVar['modsettings']['clean'] = $runVar['settings']['post_non'] == 2 ? ' clean ' : ' '; $runVar['constants']['pre_lim'] = $runVar['counts']['iterations'] > 1 ? '7' : ''; //assign scripts $runVar['scripts']['releases'] = $runVar['constants']['tablepergroup'] == 0 ? "{$runVar['commands']['_php']} {$runVar['paths']['misc']}update/update_releases.php 1 false" : "{$runVar['commands']['_php']} {$runVar['paths']['misc']}update/nix/multiprocessing/releases.php"; switch ((int) $runVar['settings']['binaries_run']) {
/** * Create releases from complete collections. * * @param int|string $groupID (optional) * * @return int * @access public */ public function createReleases($groupID) { $startTime = time(); $group = $this->groups->getCBPTableNames($this->tablePerGroup, $groupID); $categorize = new Categorize(['Settings' => $this->pdo]); $returnCount = $duplicate = 0; if ($this->echoCLI) { $this->pdo->log->doEcho($this->pdo->log->header("Process Releases -> Create releases from complete collections.")); } $this->pdo->ping(true); $collections = $this->pdo->queryDirect(sprintf(' SELECT SQL_NO_CACHE %s.*, groups.name AS gname FROM %s INNER JOIN groups ON %s.group_id = groups.id WHERE %s %s.filecheck = %d AND filesize > 0 LIMIT %d', $group['cname'], $group['cname'], $group['cname'], !empty($groupID) ? ' group_id = ' . $groupID . ' AND ' : ' ', $group['cname'], self::COLLFC_SIZED, $this->releaseCreationLimit)); if ($this->echoCLI && $collections !== false) { echo $this->pdo->log->primary($collections->rowCount() . " Collections ready to be converted to releases."); } if ($collections instanceof \Traversable) { $preDB = new PreDb(['Echo' => $this->echoCLI, 'Settings' => $this->pdo]); foreach ($collections as $collection) { $cleanRelName = $this->pdo->escapeString(utf8_encode(str_replace(['#', '@', '$', '%', '^', '§', '¨', '©', 'Ö'], '', $collection['subject']))); $fromName = $this->pdo->escapeString(utf8_encode(trim($collection['fromname'], "'"))); // Look for duplicates, duplicates match on releases.name, releases.fromname and releases.size // A 1% variance in size is considered the same size when the subject and poster are the same $dupeCheck = $this->pdo->queryOneRow(sprintf("\n\t\t\t\t\t\tSELECT SQL_NO_CACHE id\n\t\t\t\t\t\tFROM releases\n\t\t\t\t\t\tWHERE name = %s\n\t\t\t\t\t\tAND fromname = %s\n\t\t\t\t\t\tAND size BETWEEN '%s'\n\t\t\t\t\t\tAND '%s'", $cleanRelName, $fromName, $collection['filesize'] * 0.99, $collection['filesize'] * 1.01)); if ($dupeCheck === false) { $cleanedName = $this->releaseCleaning->releaseCleaner($collection['subject'], $collection['fromname'], $collection['filesize'], $collection['gname']); if (is_array($cleanedName)) { $properName = $cleanedName['properlynamed']; $preID = isset($cleanerName['predb']) ? $cleanerName['predb'] : false; $isReqID = isset($cleanerName['requestid']) ? $cleanerName['requestid'] : false; $cleanedName = $cleanedName['cleansubject']; } else { $properName = true; $isReqID = $preID = false; } if ($preID === false && $cleanedName !== '') { // try to match the cleaned searchname to predb title or filename here $preMatch = $preDB->matchPre($cleanedName); if ($preMatch !== false) { $cleanedName = $preMatch['title']; $preID = $preMatch['preid']; $properName = true; } } $releaseID = $this->releases->insertRelease(['name' => $cleanRelName, 'searchname' => $this->pdo->escapeString(utf8_encode($cleanedName)), 'totalpart' => $collection['totalfiles'], 'group_id' => $collection['group_id'], 'guid' => $this->pdo->escapeString($this->releases->createGUID($cleanRelName)), 'postdate' => $this->pdo->escapeString($collection['date']), 'fromname' => $fromName, 'size' => $collection['filesize'], 'categoryid' => $categorize->determineCategory($collection['group_id'], $cleanedName), 'isrenamed' => $properName === true ? 1 : 0, 'reqidstatus' => $isReqID === true ? 1 : 0, 'preid' => $preID === false ? 0 : $preID, 'nzbstatus' => NZB::NZB_NONE]); if ($releaseID !== false) { // Update collections table to say we inserted the release. $this->pdo->queryExec(sprintf(' UPDATE %s SET filecheck = %d, releaseid = %d WHERE id = %d', $group['cname'], self::COLLFC_INSERTED, $releaseID, $collection['id'])); $returnCount++; if ($this->echoCLI) { echo "Added {$returnCount} releases.\r"; } } } else { // The release was already in the DB, so delete the collection. $this->pdo->queryExec(sprintf(' DELETE c, b, p FROM %s c INNER JOIN %s b ON(c.id=b.collection_id) STRAIGHT_JOIN %s p ON(b.id=p.binaryid) WHERE c.collectionhash = %s', $group['cname'], $group['bname'], $group['pname'], $this->pdo->escapeString($collection['collectionhash']))); $duplicate++; } } } if ($this->echoCLI) { $this->pdo->log->doEcho($this->pdo->log->primary(PHP_EOL . number_format($returnCount) . ' Releases added and ' . number_format($duplicate) . ' duplicate collections deleted in ' . $this->consoleTools->convertTime(time() - $startTime)), true); } return ['added' => $returnCount, 'dupes' => $duplicate]; }