Beispiel #1
0
 /**
  * Update the list of newsgroups and return an array of messages.
  *
  * @param string $groupList
  * @param int    $active
  * @param int    $backfill
  *
  * @return array
  */
 public function addBulk($groupList, $active = 1, $backfill = 1)
 {
     if (preg_match('/^\\s*$/m', $groupList)) {
         $ret = "No group list provided.";
     } else {
         $nntp = new NNTP(['Echo' => false]);
         if ($nntp->doConnect() !== true) {
             return 'Problem connecting to usenet.';
         }
         $groups = $nntp->getGroups();
         $nntp->doQuit();
         if ($nntp->isError($groups)) {
             return 'Problem fetching groups from usenet.';
         }
         $regFilter = '/' . $groupList . '/i';
         $ret = [];
         foreach ($groups as $group) {
             if (preg_match($regFilter, $group['group']) > 0) {
                 $res = $this->pdo->queryOneRow(sprintf('SELECT id FROM groups WHERE name = %s', $this->pdo->escapeString($group['group'])));
                 if ($res === false) {
                     $this->pdo->queryInsert(sprintf('INSERT INTO groups (name, active, backfill) VALUES (%s, %d, %d)', $this->pdo->escapeString($group['group']), $active, $backfill));
                     $ret[] = ['group' => $group['group'], 'msg' => 'Created'];
                 }
             }
         }
         if (count($ret) === 0) {
             $ret = 'No groups found with your regex, try again!';
         }
     }
     return $ret;
 }
Beispiel #2
0
<?php

require_once realpath(dirname(dirname(dirname(dirname(dirname(__DIR__))))) . DIRECTORY_SEPARATOR . 'indexer.php');
use nzedb\ConsoleTools;
use nzedb\NNTP;
use nzedb\db\Settings;
$start = TIME();
$pdo = new Settings();
$consoleTools = new ConsoleTools(['ColorCLI' => $pdo->log]);
// Create the connection here and pass
$nntp = new NNTP(['Settings' => $pdo]);
if ($nntp->doConnect() !== true) {
    exit($pdo->log->error("Unable to connect to usenet."));
}
echo $pdo->log->header("Getting first/last for all your active groups.");
$data = $nntp->getGroups();
if ($nntp->isError($data)) {
    exit($pdo->log->error("Failed to getGroups() from nntp server."));
}
echo $pdo->log->header("Inserting new values into short_groups table.");
$pdo->queryExec('TRUNCATE TABLE short_groups');
// Put into an array all active groups
$res = $pdo->query('SELECT name FROM groups WHERE active = 1 OR backfill = 1');
foreach ($data as $newgroup) {
    if (myInArray($res, $newgroup['group'], 'name')) {
        $pdo->queryInsert(sprintf('INSERT INTO short_groups (name, first_record, last_record, updated) VALUES (%s, %s, %s, NOW())', $pdo->escapeString($newgroup['group']), $pdo->escapeString($newgroup['first']), $pdo->escapeString($newgroup['last'])));
        echo $pdo->log->primary('Updated ' . $newgroup['group']);
    }
}
echo $pdo->log->header('Running time: ' . $consoleTools->convertTimer(TIME() - $start));
function myInArray($array, $value, $key)