Exemple #1
0
 /**
  * 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'])]);
         }
     }
 }
Exemple #2
0
 /**
  * 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];
 }
Exemple #3
0
function populate_rt($table, $max)
{
    $pdo = new DB();
    switch ($table) {
        case 'releases_rt':
            $pdo->queryDirect('SET SESSION group_concat_max_len=8192');
            $query = 'SELECT r.id, r.name, r.searchname, r.fromname, IFNULL(GROUP_CONCAT(rf.name SEPARATOR " "),"") filename
				FROM releases r
				LEFT JOIN release_files rf ON(r.id=rf.releaseid)
				WHERE r.id > %d
				GROUP BY r.id
				ORDER BY r.id ASC
				LIMIT %d';
            $rtvalues = '(id, name, searchname, fromname, filename)';
            $totals = $pdo->queryOneRow("SELECT COUNT(id) AS c, MIN(id) AS min FROM releases");
            if (!$totals) {
                exit("Could not get database information for releases table.\n");
            }
            $total = $totals["c"];
            $minId = $totals["min"];
            break;
        default:
            exit;
    }
    $sphinx = new SphinxSearch();
    $string = sprintf('REPLACE INTO %s %s VALUES ', $table, $rtvalues);
    $lastId = $minId - 1;
    echo "[Starting to populate sphinx RT index {$table} with {$total} releases.]\n";
    for ($i = $minId; $i <= $total + $max; $i += $max) {
        $rows = $pdo->queryDirect(sprintf($query, $lastId, $max));
        if (!$rows) {
            continue;
        }
        $tempString = '';
        foreach ($rows as $row) {
            if ($row["id"] > $lastId) {
                $lastId = $row["id"];
            }
            switch ($table) {
                case 'releases_rt':
                    $tempString .= sprintf('(%d,%s,%s,%s,%s),', $row['id'], $sphinx->sphinxQL->escapeString($row['name']), $sphinx->sphinxQL->escapeString($row['searchname']), $sphinx->sphinxQL->escapeString($row['fromname']), $sphinx->sphinxQL->escapeString($row['filename']));
                    break;
            }
        }
        if (!$tempString) {
            continue;
        }
        $sphinx->sphinxQL->queryExec($string . rtrim($tempString, ','));
        echo ".";
    }
    echo "\n[Done]\n";
}
Exemple #4
0
    /**
     * 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);
        }
    }
Exemple #5
0
 /**
  * Return a single PRE for a release.
  *
  * @param int $preID
  *
  * @return array
  */
 public function getOne($preID)
 {
     return $this->pdo->queryOneRow(sprintf('SELECT * FROM predb WHERE id = %d', $preID));
 }
Exemple #6
0
        case 'all':
            $pdo = new DB();
            $preData = $pdo->query(sprintf('SELECT * FROM predb p WHERE 1=1 %s %s %s ORDER BY p.predate DESC LIMIT %d OFFSET %d', $newer, $older, $nuked, $limit, $offset));
            break;
    }
} 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) {
Exemple #7
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;
    }
    $postDate = $pdo->queryOneRow(sprintf('SELECT UNIX_TIMESTAMP(postdate) AS postdate FROM releases WHERE group_id = %d ORDER BY postdate ASC LIMIT 1', $group['id']));
    if ($postDate === false) {
        echo 'ERROR! Could not find any existing releases for group (' . $group['name'] . ')' . PHP_EOL;
        continue;
    }
    $articleNumber = (int) $binaries->daytopost(round((time() - $postDate['postdate']) / 86400), $groupNNTP);
    if ($group['last_record'] != 0 && $articleNumber >= $group['last_record']) {
        echo 'ERROR! Could not determine the article number for this date: (' . $postDate['postdate'] . ') on group (' . $group['name'] . ')' . PHP_EOL;
        continue;
    }
    $articleDate = $binaries->postdate($articleNumber, $groupNNTP);
    $pdo->queryExec(sprintf('
			UPDATE groups
			SET first_record = %d, first_record_postdate = %s
			WHERE id = %d', $articleNumber, $pdo->from_unixtime($articleDate), $group['id']));
    echo 'SUCCESS! Updated group (' . $group['name'] . ')\'s first article number to (' . $articleNumber . ') dated (' . date('r', $articleDate) . ').' . PHP_EOL . 'The previous first article number was: (' . $group['first_record'] . ')' . (empty($group['first_record_postdate']) ? '.' : ' dated (' . date('r', strtotime($group['first_record_postdate'])) . ').') . PHP_EOL;