/** * Formulate part of a query to prevent deletion of currently inserting parts / binaries / collections. * * @param string $groupName * @param int $difference * * @return string * @access private */ private function minMaxQueryFormulator($groupName, $difference) { $minMaxId = $this->pdo->queryOneRow(sprintf('SELECT MIN(id) AS min, MAX(id) AS max FROM %s', $groupName)); if ($minMaxId === false) { $minMaxId = ''; } else { $minMaxId = ' AND id < ' . ($minMaxId['max'] - $minMaxId['min'] >= $difference ? $minMaxId['max'] - $difference : 1); } return $minMaxId; }
/** * Delete release from Sphinx RT table. * @param array $identifiers ['g' => Release GUID(mandatory), 'id => ReleaseID(optional, pass false)] * @param nzedb\db\Settings $pdo */ public function deleteRelease($identifiers, nzedb\db\Settings $pdo) { if (!is_null($this->sphinxQL)) { if ($identifiers['i'] === false) { $identifiers['i'] = $pdo->queryOneRow(sprintf('SELECT id FROM releases WHERE guid = %s', $pdo->escapeString($identifiers['g']))); if ($identifiers['i'] !== false) { $identifiers['i'] = $identifiers['i']['id']; } } if ($identifiers['i'] !== false) { $this->sphinxQL->queryExec(sprintf('DELETE FROM releases_rt WHERE id = %s', $identifiers['i'])); } } }
/** * Attempt to get a better name from a par2 file and categorize the release. * * @note Called from NZBContents.php * * @param string $messageID MessageID from NZB file. * @param int $relID ID of the release. * @param int $groupID Group ID of the release. * @param NNTP $nntp Class NNTP * @param int $show Only show result or apply iy. * * @return bool */ public function parsePAR2($messageID, $relID, $groupID, &$nntp, $show) { if ($messageID === '') { return false; } $query = $this->pdo->queryOneRow(sprintf(' SELECT id, group_id, categoryid, name, searchname, UNIX_TIMESTAMP(postdate) AS post_date, id AS releaseid FROM releases WHERE isrenamed = 0 AND id = %d', $relID)); if ($query === false) { return false; } // Only get a new name if the category is OTHER. $foundName = true; if (!in_array((int) $query['categoryid'], array(\Category::CAT_BOOKS_OTHER, \Category::CAT_GAME_OTHER, \Category::CAT_MOVIE_OTHER, \Category::CAT_MUSIC_OTHER, \Category::CAT_PC_PHONE_OTHER, \Category::CAT_TV_OTHER, \Category::CAT_OTHER_HASHED, \Category::CAT_XXX_OTHER, \Category::CAT_MISC))) { $foundName = false; } // Get the PAR2 file. $par2 = $nntp->getMessages($this->groups->getByNameByID($groupID), $messageID, $this->alternateNNTP); if ($nntp->isError($par2)) { return false; } // Put the PAR2 into Par2Info, check if there's an error. $this->_par2Info->setData($par2); if ($this->_par2Info->error) { return false; } // Get the file list from Par2Info. $files = $this->_par2Info->getFileList(); if ($files !== false && count($files) > 0) { $filesAdded = 0; // Loop through the files. foreach ($files as $file) { if (!isset($file['name'])) { continue; } // If we found a name and added 10 files, stop. if ($foundName === true && $filesAdded > 10) { break; } if ($this->addpar2) { // Add to release files. if ($filesAdded < 11 && $this->pdo->queryOneRow(sprintf(' SELECT id FROM releasefiles WHERE releaseid = %d AND name = %s', $relID, $this->pdo->escapeString($file['name']))) === false) { // Try to add the files to the DB. if ($this->releaseFiles->add($relID, $file['name'], $file['size'], $query['post_date'], 0)) { $filesAdded++; } } } else { $filesAdded++; } // Try to get a new name. if ($foundName === false) { $query['textstring'] = $file['name']; if ($this->nameFixer->checkName($query, 1, 'PAR2, ', 1, $show) === true) { $foundName = true; } } } // If we found some files. if ($filesAdded > 0) { $this->debugging->log('PostProcess', 'parsePAR2', 'Added ' . $filesAdded . ' releasefiles from PAR2 for ' . $query['searchname'], \Logger::LOG_INFO); // Update the file count with the new file count + old file count. $this->pdo->queryExec(sprintf(' UPDATE releases SET rarinnerfilecount = rarinnerfilecount + %d WHERE id = %d', $filesAdded, $relID)); } if ($foundName === true) { return true; } } return false; }
} else { $sort = ""; } } if (isset($argv[3]) && is_numeric($argv[3])) { $limit = "LIMIT " . $argv[3]; } else { if (isset($argv[2]) && is_numeric($argv[2])) { $limit = "LIMIT " . $argv[2]; } else { $limit = ""; } } $mask = $pdo->log->primary("%-50.50s %22.22s %22.22s %22.22s %22.22s %22.22s %22.22s %22.22s"); $releases = $pdo->queryDirect("SELECT name, backfill_target, first_record_postdate, last_updated, last_updated, CAST(last_record AS SIGNED)-CAST(first_record AS SIGNED) AS 'headers downloaded', TIMESTAMPDIFF(DAY,first_record_postdate,NOW()) AS days FROM groups"); if ($releases instanceof Traversable) { foreach ($releases as $release) { $count += $release['headers downloaded']; $groups++; } } $active = $pdo->queryOneRow("SELECT COUNT(*) AS count FROM groups WHERE ACTIVE = 1"); printf($mask, "\nGroup Name => " . $active['count'] . "[" . $groups . "] (" . number_format($count) . " downloaded)", "Backfilled Days", "Oldest Post", "Last Updated", "Headers Downloaded", "Releases", "Renamed", "PreDB Matches"); printf($mask, "==================================================", "======================", "======================", "======================", "======================", "======================", "======================", "======================"); $releases = $pdo->queryDirect(sprintf("\n\t\tSELECT name, backfill_target, first_record_postdate, last_updated,\n\t\tCAST(last_record as SIGNED)-CAST(first_record as SIGNED) AS 'headers downloaded', TIMESTAMPDIFF(DAY,first_record_postdate,NOW()) AS days,\n\t\tCOALESCE(rel.num, 0) AS num_releases,\n\t\tCOALESCE(pre.num, 0) AS pre_matches,\n\t\tCOALESCE(ren.num, 0) AS renamed FROM groups\n\t\tLEFT OUTER JOIN ( SELECT group_id, COUNT(id) AS num FROM releases GROUP BY group_id ) rel ON rel.group_id = groups.id\n\t\tLEFT OUTER JOIN ( SELECT group_id, COUNT(id) AS num FROM releases WHERE preid > 0 GROUP BY group_id ) pre ON pre.group_id = groups.id\n\t\tLEFT OUTER JOIN ( SELECT group_id, COUNT(id) AS num FROM releases WHERE iscategorized = 1 GROUP BY group_id ) ren ON ren.group_id = groups.id\n\t\tWHERE active = 1 AND first_record_postdate %s %s %s", $order, $sort, $limit)); if ($releases instanceof Traversable) { foreach ($releases as $release) { $headers = number_format($release['headers downloaded']); printf($mask, $release['name'], $release['backfill_target'] . "(" . $release['days'] . ")", $release['first_record_postdate'], $release['last_updated'], $headers, number_format($release['num_releases']), $release['num_releases'] == 0 ? number_format($release['num_releases']) : number_format($release['renamed']) . "(" . floor($release['renamed'] / $release['num_releases'] * 100) . "%)", $release['num_releases'] == 0 ? number_format($release['num_releases']) : number_format($release['pre_matches']) . "(" . floor($release['pre_matches'] / $release['num_releases'] * 100) . "%)"); } }
case 'update_group_headers': $pdo = new \nzedb\db\Settings(); $nntp = nntp($pdo); $groups = new \Groups(['Settings' => $pdo]); $groupMySQL = $groups->getByName($options[2]); (new \Binaries(['NNTP' => $nntp, 'Groups' => $groups, 'Settings' => $pdo]))->updateGroup($groupMySQL); break; // Do a single group (update_binaries/backFill/update_releases/postprocess). // $options[2] => (int)groupID, group to work on // Do a single group (update_binaries/backFill/update_releases/postprocess). // $options[2] => (int)groupID, group to work on case 'update_per_group': if (is_numeric($options[2])) { $pdo = new \nzedb\db\Settings(); // Get the group info from MySQL. $groupMySQL = $pdo->queryOneRow(sprintf('SELECT * FROM groups WHERE id = %d', $options[2])); if ($groupMySQL === false) { exit('ERROR: Group not found with ID ' . $options[2] . PHP_EOL); } // Connect to NNTP. $nntp = nntp($pdo); $backFill = new \Backfill(['NNTP' => $nntp, 'Settings' => $pdo], true); // Update the group for new binaries. (new \Binaries(['NNTP' => $nntp, 'Settings' => $pdo]))->updateGroup($groupMySQL); // BackFill the group with 20k articles. $backFill->backfillAllGroups($groupMySQL['name'], 20000, 'normal'); // Check if we got anything from binaries/backFill, exit if not. collectionCheck($pdo, $options[2]); // Create releases. processReleases(new \ProcessReleases(['Settings' => $pdo]), $options[2]); // Post process the releases.
/** * Return the specified blacklist. * * @param int $id The blacklist ID. * * @return array|bool */ public function getBlacklistByID($id) { return $this->_pdo->queryOneRow(sprintf('SELECT * FROM binaryblacklist WHERE id = %d', $id)); }