コード例 #1
0
ファイル: populate_rt_indexes.php プロジェクト: sebst3r/nZEDb
function releases_rt()
{
    $pdo = new DB();
    $rows = $pdo->queryExec('SELECT id, guid, name, searchname, fromname FROM releases');
    if ($rows !== false && $rows->rowCount()) {
        $sphinx = new SphinxSearch();
        $total = $rows->rowCount();
        $string = 'REPLACE INTO releases_rt (id, guid, name, searchname, fromname) VALUES ';
        $tempString = '';
        $i = 0;
        echo '[Starting to populate sphinx RT indexes with ' . $total . ' releases.] ';
        foreach ($rows as $row) {
            $i++;
            $tempString .= sprintf('(%d, %s, %s, %s, %s),', $row['id'], $sphinx->sphinxQL->escapeString($row['guid']), $sphinx->sphinxQL->escapeString($row['name']), $sphinx->sphinxQL->escapeString($row['searchname']), $sphinx->sphinxQL->escapeString($row['fromname']));
            if ($i === 1000 || $i >= $total) {
                $sphinx->sphinxQL->queryExec($string . rtrim($tempString, ','));
                $tempString = '';
                $total -= $i;
                $i = 0;
                echo '.';
            }
        }
        echo ' [Done.]' . PHP_EOL;
    } else {
        echo 'No releases in your DB or an error occurred. This will need to be resolved before you can use the search.' . PHP_EOL;
    }
}
コード例 #2
0
ファイル: populate_rt_indexes.php プロジェクト: zetas/nZEDb
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";
}
コード例 #3
0
ファイル: SphinxSearch.php プロジェクト: zetas/nZEDb
 /**
  * Optimize a RT index.
  * @param string $indexName
  */
 public function optimizeRTIndex($indexName)
 {
     if (!is_null($this->sphinxQL)) {
         $this->sphinxQL->queryExec(sprintf('FLUSH RTINDEX %s', $indexName));
         $this->sphinxQL->queryExec(sprintf('OPTIMIZE INDEX %s', $indexName));
     }
 }
コード例 #4
0
ファイル: Settings.php プロジェクト: kaibosh/nZEDb
 public function __construct(array $options = [])
 {
     parent::__construct($options);
     $result = parent::exec("describe site", true);
     $this->table = $result === false ? 'settings' : 'site';
     $this->setCovers();
     return $this->pdo;
 }
コード例 #5
0
ファイル: IRCScraper.php プロジェクト: kaibosh/nZEDb
 /**
  * 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];
 }
コード例 #6
0
ファイル: populate_rt_indexes.php プロジェクト: kaibosh/nZEDb
function populate_rt($table = '')
{
    $pdo = new DB();
    $rows = false;
    switch ($table) {
        case 'releases_rt':
            $pdo->queryDirect('SET SESSION group_concat_max_len=8192');
            $rows = $pdo->queryExec('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) GROUP BY r.id');
            $rtvalues = '(id, name, searchname, fromname, filename)';
            break;
    }
    if ($rows !== false && ($total = $rows->rowCount())) {
        $sphinx = new SphinxSearch();
        $string = sprintf('REPLACE INTO %s %s VALUES ', $table, $rtvalues);
        $tempString = '';
        $i = 0;
        echo '[Starting to populate sphinx RT index ' . $table . ' with ' . $total . ' releases.] ';
        foreach ($rows as $row) {
            $i++;
            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 ($i === 1000 || $i >= $total) {
                $sphinx->sphinxQL->queryExec($string . rtrim($tempString, ','));
                $tempString = '';
                $total -= $i;
                $i = 0;
                echo '.';
            }
        }
        echo ' [Done.]' . PHP_EOL;
    } else {
        echo 'No releases in your DB or an error occurred. This will need to be resolved before you can use the search.' . PHP_EOL;
    }
}
コード例 #7
0
ファイル: Backfill.php プロジェクト: EeGgSs/nZEDb
    /**
     * 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);
        }
    }
コード例 #8
0
ファイル: create_se_tables.php プロジェクト: kaibosh/nZEDb
    exit('Error, nZEDb_RELEASE_SEARCH_TYPE in nzedb/config/settings.php must be set to SPHINX!' . PHP_EOL);
}
$sphinxConnection = '';
if ($argc == 3 && is_numeric($argv[2])) {
    $sphinxConnection = sprintf('sphinx://%s:%d/', $argv[1], $argv[2]);
} elseif ($argc == 2) {
    // Checks that argv[1] exists AND that there are no other arguments, which would be an error.
    $socket = preg_replace('#^(?:unix://)?(.*)$#', '$1', $argv[1]);
    if (substr($socket, 0, 1) == '/') {
        // Make sure the socket path is fully qualified (and using correct separator).
        $sphinxConnection = sprintf('unix://%s:', $socket);
    }
} else {
    exit("Argument 1 must the hostname or IP to the Sphinx searchd server, Argument 2 must be the port to the Sphinx searchd server.\nAlternatively, Argument 1 can be a unix domain socket." . PHP_EOL);
}
$pdo = new DB();
$tableSQL_releases = <<<DDLSQL
CREATE TABLE releases_se
(
\tid          BIGINT UNSIGNED NOT NULL,
\tweight      INTEGER NOT NULL,
\tquery       VARCHAR(1024) NOT NULL,
\tname        VARCHAR(255) NOT NULL DEFAULT '',
\tsearchname  VARCHAR(255) NOT NULL DEFAULT '',
\tfromname    VARCHAR(255) NULL,
\tfilename    VARCHAR(1000) NULL,
\tINDEX(query)
) ENGINE=SPHINX CONNECTION="%sreleases_rt"
DDLSQL;
$tables = [];
$tables['releases_se'] = sprintf($tableSQL_releases, $sphinxConnection);
コード例 #9
0
ファイル: PreDb.php プロジェクト: zetas/nZEDb
 /**
  * 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));
 }
コード例 #10
0
ファイル: preinfo.php プロジェクト: kaibosh/nZEDb
            if (isset($_GET['category'])) {
                $pdo = new DB();
                $preData = $pdo->query(sprintf('SELECT * FROM predb p WHERE p.category %s %s %s %s LIMIT %d OFFSET %d', $newer, $older, $nuked, $pdo->likeString($_GET['category']), $limit, $offset));
            }
            break;
        case 'a':
        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;
                }
            }
コード例 #11
0
ファイル: set_backfill_start.php プロジェクト: kaibosh/nZEDb
<?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;
    }
コード例 #12
0
ファイル: test-nntp-debug.php プロジェクト: sebst3r/nZEDb
    public function info($message)
    {
        if (PEAR_LOG_DEBUG) {
            echo $this->color->info($message);
        }
    }
}
$nntp = new NNTPTest(new NNTPDebug(isset($argv[1]) ? true : false));
if ($nntp->doConnect() !== true) {
    exit('Error connecting to usenet!' . PHP_EOL);
}
$n = PHP_EOL;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////// Put your test code under here. ////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$db = new DB();
$groups = $db->query('SELECT name FROM groups WHERE name NOT like \'alt.binaries.%\' AND active = 1');
$groupList = [];
foreach ($groups as $group) {
    $groupList += $nntp->getGroups($group['name']);
}
$groupList += $nntp->getGroups('alt.binaries.*');
$groups = $db->queryDirect('SELECT name FROM groups WHERE active = 1');
$activeGroups = [];
if ($groups instanceof \Traversable) {
    foreach ($groups as $group) {
        if (isset($groupList[$group['name']])) {
            $activeGroups[$group['name']] = $groupList[$group['name']];
        }
    }
}