/** * Update the search name of a release. * * @param int $releaseID * @param string $searchName */ public function updateReleaseSearchName($releaseID, $searchName) { if (!is_null($this->sphinxQL)) { $old = $this->sphinxQL->queryOneRow(sprintf('SELECT * FROM releases_rt WHERE id = %s', $releaseID)); if ($old !== false) { $this->insertRelease(['id' => $releaseID, 'guid' => $this->sphinxQL->escapeString($old['guid']), 'name' => $this->sphinxQL->escapeString($old['name']), 'searchname' => $searchName, 'fromname' => $this->sphinxQL->escapeString($old['fromname'])]); } } }
/** * Get a group ID for a group name. * * @param string $groupName * * @return mixed * * @access protected */ protected function _getGroupID($groupName) { if (!isset($this->_groupList[$groupName])) { $group = $this->_pdo->queryOneRow(sprintf('SELECT id FROM groups WHERE name = %s', $this->_pdo->escapeString($groupName))); $this->_groupList[$groupName] = $group['id']; } return $this->_groupList[$groupName]; }
/** * Try to match a single release to a PreDB title when the release is created. * * @param string $cleanerName * * @return array|bool Array with title/ID from PreDB if found, bool False if not found. */ public function matchPre($cleanerName) { if ($cleanerName == '') { return false; } $titleCheck = $this->pdo->queryOneRow(sprintf('SELECT id FROM predb WHERE title = %s LIMIT 1', $this->pdo->escapeString($cleanerName))); if ($titleCheck !== false) { return ['title' => $cleanerName, 'preid' => $titleCheck['id']]; } // Check if clean name matches a PreDB filename. $fileCheck = $this->pdo->queryOneRow(sprintf('SELECT id, title FROM predb WHERE filename = %s LIMIT 1', $this->pdo->escapeString($cleanerName))); if ($fileCheck !== false) { return ['title' => $fileCheck['title'], 'preid' => $fileCheck['id']]; } return false; }
/** * Safe backfill using posts. Going back to a date specified by the user on the site settings. * This does 1 group for x amount of parts until it reaches the date. * * @param string $articles * * @return void */ public function safeBackfill($articles = '') { $groupname = $this->pdo->queryOneRow(sprintf(' SELECT name FROM groups WHERE first_record_postdate BETWEEN %s AND NOW() AND backfill = 1 ORDER BY name ASC', $this->pdo->escapeString($this->_safeBackFillDate))); if (!$groupname) { $dMessage = 'No groups to backfill, they are all at the target date ' . $this->_safeBackFillDate . ", or you have not enabled them to be backfilled in the groups page.\n"; if ($this->_debug) { $this->_debugging->log(get_class(), __FUNCTION__, $dMessage, Logger::LOG_FATAL); } exit($dMessage); } else { $this->backfillAllGroups($groupname['name'], $articles); } }
} } else { if (isset($_POST['data'])) { $reqData = @unserialize($_POST['data']); if ($reqData !== false && is_array($reqData) && isset($reqData[0]['ident'])) { $pdo = new DB(); $preData = []; foreach ($reqData as $request) { $result = $pdo->queryOneRow(sprintf(' SELECT p.*, g.name AS groupname FROM predb p INNER JOIN groups g ON g.id = p.group_id WHERE requestid = %d AND g.name = %s LIMIT 1', $request['reqid'], $pdo->escapeString($request['group']))); if ($result !== false) { $result['ident'] = $request['ident']; $preData[] = $result; } } } } } if ($json === false) { header('Content-type: text/xml'); echo '<?xml version="1.0" encoding="UTF-8"?>', PHP_EOL, '<requests>', PHP_EOL; if (count($preData) > 0) { foreach ($preData as $data) { echo '<request', ' reqid="' . (!empty($data['requestid']) ? $data['requestid'] : '') . '"', ' md5="' . (!empty($data['md5']) ? $data['md5'] : '') . '"', ' sha1="' . (!empty($data['sha1']) ? $data['sha1'] : '') . '"', ' nuked="' . (!empty($data['nuked']) ? $data['nuked'] : '') . '"', ' category="' . (!empty($data['category']) ? $data['category'] : '') . '"', ' source="' . (!empty($data['source']) ? $data['source'] : '') . '"', ' nukereason="' . (!empty($data['nukereason']) ? $data['nukereason'] : '') . '"', ' files="' . (!empty($data['files']) ? $data['files'] : '') . '"', ' name="' . (!empty($data['title']) ? sanitize($data['title']) : '') . '"', ' date="' . (!empty($data['predate']) ? strtotime($data['predate']) : '') . '"', ' size="' . (!empty($data['size']) && $data['size'] != 'NULL' ? $data['size'] : '') . '"', ' group="' . (isset($data['groupname']) && !empty($data['groupname']) ? $data['groupname'] : '') . '"', ' ident="' . (isset($data['ident']) && !empty($data['ident']) ? $data['ident'] : '') . '"', '/>'; }
<?php if (!isset($argv[1])) { exit('This script will set where backfill starts based on your oldest release in a group or groups,' . ' so you do not have to re-download and process all the headers you already downloaded.' . PHP_EOL . 'This is good if you imported NZBs or reset a group for example.' . PHP_EOL . 'To start the script, type in a group name or all for all the backfill enabled groups.' . PHP_EOL); } require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'indexer.php'); use nzedb\Binaries; use nzedb\NNTP; use nzedb\db\DB; $pdo = new DB(); if ($argv[1] === 'all') { $groups = $pdo->query('SELECT * FROM groups WHERE backfill = 1'); } else { $groups = $pdo->query(sprintf('SELECT * FROM groups WHERE name = %s', $pdo->escapeString($argv[1]))); } if (count($groups) === 0) { if ($argv[1] === 'all') { exit('ERROR! No groups were found with backfill enabled!' . PHP_EOL); } else { exit('ERROR! Group (' . $argv[1] . ') not found!' . PHP_EOL); } } $nntp = new NNTP(['Settings' => $pdo]); $nntp->doConnect() or exit('Could not connect to Usenet!' . PHP_EOL); $binaries = new Binaries(['NNTP' => $nntp, 'Settings' => $pdo]); foreach ($groups as $group) { $groupNNTP = $nntp->selectGroup($group['name']); if ($nntp->isError($groupNNTP)) { echo 'ERROR! Could not fetch information from NNTP for group (' . $group['name'] . ')' . PHP_EOL; continue; }
/** * Insert release into Sphinx RT table. * @param $parameters */ public function insertRelease($parameters) { if (!is_null($this->sphinxQL) && $parameters['id']) { $this->sphinxQL->queryExec(sprintf('REPLACE INTO releases_rt (id, name, searchname, fromname, filename) VALUES (%d, %s, %s, %s, %s)', $parameters['id'], $this->sphinxQL->escapeString($parameters['name']), $this->sphinxQL->escapeString($parameters['searchname']), $this->sphinxQL->escapeString($parameters['fromname']), empty($parameters['filename']) ? "''" : $this->sphinxQL->escapeString($parameters['filename']))); } }