<?php require "../../www/config.php"; require_once WWW_DIR . "/lib/backfill.php"; $nntp = new nntp(); $nntp->doConnect(); $backfill = new Backfill(); $data = $nntp->selectGroup("alt.binaries.nintendo.ds"); $output = $backfill->postdate($nntp, "7434768"); echo date('r', $output) . "\n"; print_r($data); $nntp->doQuit();
/** * Process headers and store in database for a group. */ function updateGroup($nntp = null, $groupArr) { $blnDoDisconnect = false; if ($nntp == null) { $nntp = new Nntp(); if (!$nntp->doConnect()) { echo "Failed to get NNTP connection."; return; } $this->message = array(); $blnDoDisconnect = true; } $db = new DB(); $backfill = new Backfill(); $n = $this->n; $this->startGroup = microtime(true); $this->startLoop = microtime(true); echo 'Processing ' . $groupArr['name'] . $n; // Connect to server $data = $nntp->selectGroup($groupArr['name']); if ($nntp->isError($data)) { echo "Could not select group (bad name?): {$groupArr['name']}{$n} {$n}"; return; } if ($groupArr['regexmatchonly'] == 1) { $this->onlyProcessRegexBinaries = true; echo "Note: Discarding parts that do not match a regex" . $n; } else { $this->onlyProcessRegexBinaries = false; } //Attempt to repair any missing parts before grabbing new ones $this->partRepair($nntp, $groupArr); //Get first and last part numbers from newsgroup $last = $grouplast = $data['last']; // For new newsgroups - determine here how far you want to go back. if ($groupArr['last_record'] == 0) { if ($this->NewGroupScanByDays) { $first = $backfill->daytopost($nntp, $groupArr['name'], $this->NewGroupDaysToScan, true); if ($first == '') { echo "Skipping group: {$groupArr['name']}{$n}"; return; } } else { if ($data['first'] > $data['last'] - $this->NewGroupMsgsToScan) { $first = $data['first']; } else { $first = $data['last'] - $this->NewGroupMsgsToScan; } } $first_record_postdate = $backfill->postdate($nntp, $first, false); if ($first_record_postdate != "") { $db->exec(sprintf("update groups SET first_record = %s, first_record_postdate = FROM_UNIXTIME(" . $first_record_postdate . ") WHERE ID = %d", $db->escapeString($first), $groupArr['ID'])); } } else { if ($data['last'] < $groupArr['last_record']) { echo "Warning: Server's last num {$data['last']} is lower than the local last num {$groupArr['last_record']}" . $n; return; } $first = $groupArr['last_record'] + 1; } // Generate postdates for first and last records, for those that upgraded if ((is_null($groupArr['first_record_postdate']) || is_null($groupArr['last_record_postdate'])) && ($groupArr['last_record'] != "0" && $groupArr['first_record'] != "0")) { $db->exec(sprintf("update groups SET first_record_postdate = FROM_UNIXTIME(" . $backfill->postdate($nntp, $groupArr['first_record'], false) . "), last_record_postdate = FROM_UNIXTIME(" . $backfill->postdate($nntp, $groupArr['last_record'], false) . ") WHERE ID = %d", $groupArr['ID'])); } // Deactivate empty groups if ($data['last'] - $data['first'] <= 5) { $db->exec(sprintf("update groups SET active = %s, last_updated = now() WHERE ID = %d", $db->escapeString('0'), $groupArr['ID'])); } // Calculate total number of parts $total = $grouplast - $first + 1; // If total is bigger than 0 it means we have new parts in the newsgroup if ($total > 0) { echo "Group " . $data["group"] . " has " . number_format($total) . " new parts." . $n; if ($total > $this->MaxMsgsPerRun) { $grouplast = $first + $this->MaxMsgsPerRun; echo "NOTICE: Only processing first " . number_format($this->MaxMsgsPerRun) . " parts." . $n; } echo "First: " . $data['first'] . " Last: " . $data['last'] . " Local last: " . $groupArr['last_record'] . $n; if ($groupArr['last_record'] == 0) { echo "New group starting with " . ($this->NewGroupScanByDays ? $this->NewGroupDaysToScan . " days" : $this->NewGroupMsgsToScan . " messages") . " worth." . $n; } $done = false; // Get all the parts (in portions of $this->messagebuffer to not use too much memory) while ($done === false) { $this->startLoop = microtime(true); if ($total > $this->messagebuffer) { if ($first + $this->messagebuffer > $grouplast) { $last = $grouplast; } else { $last = $first + $this->messagebuffer; } } echo "Getting " . number_format($last - $first + 1) . " parts (" . $first . " to " . $last . ") - " . number_format($grouplast - $last) . " in queue" . $n; flush(); //get headers from newsgroup $lastId = $this->scan($nntp, $groupArr, $first, $last); if ($lastId === false) { //scan failed - skip group return; } $db->exec(sprintf("update groups SET last_record = %s, last_updated = now() WHERE ID = %d", $db->escapeString($lastId), $groupArr['ID'])); if ($last == $grouplast) { $done = true; } else { $last = $lastId; $first = $last + 1; } } $last_record_postdate = $backfill->postdate($nntp, $last, false); if ($last_record_postdate != "") { $db->exec(sprintf("update groups SET last_record_postdate = FROM_UNIXTIME(" . $last_record_postdate . "), last_updated = now() WHERE ID = %d", $groupArr['ID'])); //Set group's last postdate } $timeGroup = number_format(microtime(true) - $this->startGroup, 2); echo "Group processed in {$timeGroup} seconds {$n} {$n}"; } else { echo "No new records for " . $data["group"] . " (first {$first} last {$last} total {$total}) grouplast " . $groupArr['last_record'] . $n . $n; } if ($blnDoDisconnect) { $nntp->doQuit(); } }