Ejemplo n.º 1
0
    /**
     * Add new files for a release ID.
     *
     * @param int    $id          The ID of the release.
     * @param string $name        Name of the file.
     * @param int    $size        Size of the file.
     * @param int    $createdTime Unix time the file was created.
     * @param int    $hasPassword Does it have a password (see Releases class constants)?
     *
     * @return mixed
     */
    public function add($id, $name, $size, $createdTime, $hasPassword)
    {
        $insert = 0;
        $duplicateCheck = $this->pdo->queryOneRow(sprintf('
				SELECT id
				FROM releasefiles
				WHERE releaseid = %d AND name = %s', $id, $this->pdo->escapeString(utf8_encode($name))));
        if ($duplicateCheck === false) {
            $insert = $this->pdo->queryInsert(sprintf("\n\t\t\t\t\t\tINSERT INTO releasefiles\n\t\t\t\t\t\t(releaseid, name, size, createddate, passworded)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t(%d, %s, %s, %s, %d)", $id, $this->pdo->escapeString(utf8_encode($name)), $this->pdo->escapeString($size), $this->pdo->from_unixtime($createdTime), $hasPassword));
        }
        return $insert;
    }
Ejemplo n.º 2
0
    /**
     * Fetch a comment and insert it.
     *
     * @param string $messageID Message-ID for the article.
     * @param string $siteID    id of the site.
     *
     * @return bool
     */
    protected function insertNewComment(&$messageID, &$siteID)
    {
        // Get the article body.
        $body = $this->nntp->getMessages(self::group, $messageID);
        // Check if there's an error.
        if ($this->nntp->isError($body)) {
            return false;
        }
        // Decompress the body.
        $body = @gzinflate($body);
        if ($body === false) {
            return false;
        }
        // JSON Decode the body.
        $body = json_decode($body, true);
        if ($body === false) {
            return false;
        }
        // Just in case.
        if (!isset($body['USER']) || !isset($body['SID']) || !isset($body['RID']) || !isset($body['TIME']) | !isset($body['BODY'])) {
            return false;
        }
        $cid = md5($body['SID'] . $body['USER'] . $body['TIME'] . $siteID);
        // Insert the comment.
        if ($this->pdo->queryExec(sprintf('
				INSERT IGNORE INTO releasecomment
				(text, createddate, issynced, shareid, cid, gid, nzb_guid, siteid, username, userid, releaseid, shared, host, sourceID)
				VALUES (%s, %s, 1, %s, %s, %s, %s, %s, %s, 0, 0, 2, "", 999)', $this->pdo->escapeString($body['BODY']), $this->pdo->from_unixtime($body['TIME'] > time() ? time() : $body['TIME']), $this->pdo->escapeString($body['SID']), $this->pdo->escapeString($cid), $this->pdo->escapeString($body['RID']), $this->pdo->escapeString($body['RID']), $this->pdo->escapeString($siteID), $this->pdo->escapeString(substr($body['USER'], 0, 3) === 'sn-' ? 'SH_ANON' : 'SH_' . $body['USER'])))) {
            return true;
        }
        return false;
    }
Ejemplo n.º 3
0
 /**
  * Process bot messages, insert/update PREs.
  *
  * @access protected
  */
 protected function processChannelMessages()
 {
     if (preg_match('/^(NEW|UPD|NUK): \\[DT: (?P<time>.+?)\\]\\s?\\[TT: (?P<title>.+?)\\]\\s?\\[SC: (?P<source>.+?)\\]\\s?\\[CT: (?P<category>.+?)\\]\\s?\\[RQ: (?P<req>.+?)\\]' . '\\s?\\[SZ: (?P<size>.+?)\\]\\s?\\[FL: (?P<files>.+?)\\]\\s?(\\[FN: (?P<filename>.+?)\\]\\s?)?(\\[(?P<nuked>(UN|MOD|RE|OLD)?NUKED?): (?P<reason>.+?)\\])?$/i', $this->_channelData['message'], $matches)) {
         if (isset($this->_ignoredChannels[$matches['source']]) && $this->_ignoredChannels[$matches['source']] === true) {
             return;
         }
         if ($this->_categoryIgnoreRegex !== false && preg_match((string) $this->_categoryIgnoreRegex, $matches['category'])) {
             return;
         }
         if ($this->_titleIgnoreRegex !== false && preg_match((string) $this->_titleIgnoreRegex, $matches['title'])) {
             return;
         }
         $this->_curPre['predate'] = $this->_pdo->from_unixtime(strtotime($matches['time'] . ' UTC'));
         $this->_curPre['title'] = $matches['title'];
         $this->_curPre['source'] = $matches['source'];
         if ($matches['category'] !== 'N/A') {
             $this->_curPre['category'] = $matches['category'];
         }
         if ($matches['req'] !== 'N/A' && preg_match('/^(?P<req>\\d+):(?P<group>.+)$/i', $matches['req'], $matches2)) {
             $this->_curPre['reqid'] = $matches2['req'];
             $this->_curPre['group_id'] = $this->_getGroupID($matches2['group']);
         }
         if ($matches['size'] !== 'N/A') {
             $this->_curPre['size'] = $matches['size'];
         }
         if ($matches['files'] !== 'N/A') {
             $this->_curPre['files'] = substr($matches['files'], 0, 50);
         }
         if (isset($matches['filename']) && $matches['filename'] !== 'N/A') {
             $this->_curPre['filename'] = $matches['filename'];
         }
         if (isset($matches['nuked'])) {
             switch ($matches['nuked']) {
                 case 'NUKED':
                     $this->_curPre['nuked'] = PreHash::PRE_NUKED;
                     break;
                 case 'UNNUKED':
                     $this->_curPre['nuked'] = PreHash::PRE_UNNUKED;
                     break;
                 case 'MODNUKED':
                     $this->_curPre['nuked'] = PreHash::PRE_MODNUKE;
                     break;
                 case 'RENUKED':
                     $this->_curPre['nuked'] = PreHash::PRE_RENUKED;
                     break;
                 case 'OLDNUKE':
                     $this->_curPre['nuked'] = PreHash::PRE_OLDNUKE;
                     break;
             }
             $this->_curPre['reason'] = isset($matches['reason']) ? substr($matches['reason'], 0, 255) : '';
         }
         $this->_checkForDupe();
     }
 }
Ejemplo n.º 4
0
    /**
     * Download new headers for a single group.
     *
     * @param array $groupMySQL Array of MySQL results for a single group.
     * @param int   $maxHeaders (Optional) How many headers to download max.
     *
     * @return void
     */
    public function updateGroup($groupMySQL, $maxHeaders = 0)
    {
        $startGroup = microtime(true);
        // Select the group on the NNTP server, gets the latest info on it.
        $groupNNTP = $this->_nntp->selectGroup($groupMySQL['name']);
        if ($this->_nntp->isError($groupNNTP)) {
            $groupNNTP = $this->_nntp->dataError($this->_nntp, $groupMySQL['name']);
            if ($groupNNTP->code == 411) {
                $this->_groups->disableIfNotExist($groupMySQL['id']);
            }
            if ($this->_nntp->isError($groupNNTP)) {
                return;
            }
        }
        if ($this->_echoCLI) {
            $this->_colorCLI->doEcho($this->_colorCLI->primary('Processing ' . $groupMySQL['name']), true);
        }
        if ($groupMySQL['regexmatchonly'] == 1) {
            $this->onlyProcessRegexBinaries = true;
            if ($this->_echoCLI) {
                $this->_colorCLI->doEcho($this->_colorCLI->primary('Note: Discarding parts that do not match a regex', true));
            }
        } else {
            $this->onlyProcessRegexBinaries = false;
        }
        // Attempt to repair any missing parts before grabbing new ones.
        if ($groupMySQL['last_record'] != 0) {
            if ($this->_partRepair) {
                if ($this->_echoCLI) {
                    $this->_colorCLI->doEcho($this->_colorCLI->primary('Part repair enabled. Checking for missing parts.'), true);
                }
                $this->partRepair($groupMySQL);
            } else {
                if ($this->_echoCLI) {
                    $this->_colorCLI->doEcho($this->_colorCLI->primary('Part repair disabled by user.'), true);
                }
            }
        }
        // Generate postdate for first record, for those that upgraded.
        if (is_null($groupMySQL['first_record_postdate']) && $groupMySQL['first_record'] != 0) {
            $groupMySQL['first_record_postdate'] = $this->postdate($groupMySQL['first_record'], $groupNNTP);
            $this->_pdo->queryExec(sprintf('
					UPDATE groups
					SET first_record_postdate = %s
					WHERE id = %d', $this->_pdo->from_unixtime($groupMySQL['first_record_postdate']), $groupMySQL['id']));
        }
        // Get first article we want aka the oldest.
        if ($groupMySQL['last_record'] == 0) {
            if ($this->_newGroupScanByDays) {
                // For new newsgroups - determine here how far we want to go back using date.
                $first = $this->daytopost($this->_newGroupDaysToScan, $groupNNTP);
            } else {
                if ($groupNNTP['first'] >= $groupNNTP['last'] - ($this->_newGroupMessagesToScan + $this->messageBuffer)) {
                    // If what we want is lower than the groups first article, set the wanted first to the first.
                    $first = $groupNNTP['first'];
                } else {
                    // Or else, use the newest article minus how much we should get for new groups.
                    $first = (string) ($groupNNTP['last'] - ($this->_newGroupMessagesToScan + $this->messageBuffer));
                }
            }
            // We will use this to subtract so we leave articles for the next time (in case the server doesn't have them yet)
            $leaveOver = $this->messageBuffer;
            // If this is not a new group, go from our newest to the servers newest.
        } else {
            // Set our oldest wanted to our newest local article.
            $first = $groupMySQL['last_record'];
            // This is how many articles we will grab. (the servers newest minus our newest).
            $totalCount = (string) ($groupNNTP['last'] - $first);
            // Check if the server has more articles than our loop limit x 2.
            if ($totalCount > $this->messageBuffer * 2) {
                // Get the remainder of $totalCount / $this->message buffer
                $leaveOver = round($totalCount % $this->messageBuffer, 0, PHP_ROUND_HALF_DOWN) + $this->messageBuffer;
            } else {
                // Else get half of the available.
                $leaveOver = round($totalCount / 2, 0, PHP_ROUND_HALF_DOWN);
            }
        }
        // The last article we want, aka the newest.
        $last = $groupLast = (string) ($groupNNTP['last'] - $leaveOver);
        // If the newest we want is older than the oldest we want somehow.. set them equal.
        if ($last < $first) {
            $last = $groupLast = $first;
        }
        // This is how many articles we are going to get.
        $total = (string) ($groupLast - $first);
        // This is how many articles are available (without $leaveOver).
        $realTotal = (string) ($groupNNTP['last'] - $first);
        // Check if we should limit the amount of fetched new headers.
        if ($maxHeaders > 0) {
            if ($maxHeaders < $groupLast - $first) {
                $groupLast = $last = (string) ($maxHeaders + $first);
            }
            $total = (string) ($groupLast - $first);
        }
        // If total is bigger than 0 it means we have new parts in the newsgroup.
        if ($total > 0) {
            if ($this->_echoCLI) {
                $this->_colorCLI->doEcho($this->_colorCLI->primary(($groupMySQL['last_record'] == 0 ? 'New group ' . $groupNNTP['group'] . ' starting with ' . ($this->_newGroupScanByDays ? $this->_newGroupDaysToScan . ' days' : number_format($this->_newGroupMessagesToScan) . ' messages') . ' worth.' : 'Group ' . $groupNNTP['group'] . ' has ' . number_format($realTotal) . ' new articles.') . ' Leaving ' . number_format($leaveOver) . " for next pass.\nServer oldest: " . number_format($groupNNTP['first']) . ' Server newest: ' . number_format($groupNNTP['last']) . ' Local newest: ' . number_format($groupMySQL['last_record'])), true);
            }
            $done = false;
            // Get all the parts (in portions of $this->messageBuffer to not use too much memory).
            while ($done === false) {
                // Increment last until we reach $groupLast (group newest article).
                if ($total > $this->messageBuffer) {
                    $last = (string) ($first + $this->messageBuffer) > $groupLast ? $groupLast : (string) ($first + $this->messageBuffer);
                }
                // Increment first so we don't get an article we already had.
                $first++;
                if ($this->_echoCLI) {
                    $this->_colorCLI->doEcho($this->_colorCLI->header("\nGetting " . number_format($last - $first + 1) . ' articles (' . number_format($first) . ' to ' . number_format($last) . ') from ' . $groupMySQL['name'] . " - (" . number_format($groupLast - $last) . " articles in queue)."));
                }
                // Get article headers from newsgroup.
                $scanSummary = $this->scan($groupMySQL, $first, $last);
                // Check if we fetched headers.
                if (!empty($scanSummary)) {
                    // If new group, update first record & postdate
                    if (is_null($groupMySQL['first_record_postdate']) && $groupMySQL['first_record'] == 0) {
                        $groupMySQL['first_record'] = $scanSummary['firstArticleNumber'];
                        if (isset($scanSummary['firstArticleDate'])) {
                            $groupMySQL['first_record_postdate'] = strtotime($scanSummary['firstArticleDate']);
                        } else {
                            $groupMySQL['first_record_postdate'] = $this->postdate($groupMySQL['first_record'], $groupNNTP);
                        }
                        $this->_pdo->queryExec(sprintf('
								UPDATE groups
								SET first_record = %s, first_record_postdate = %s
								WHERE id = %d', $scanSummary['firstArticleNumber'], $this->_pdo->from_unixtime($this->_pdo->escapeString($groupMySQL['first_record_postdate'])), $groupMySQL['id']));
                    }
                    if (isset($scanSummary['lastArticleDate'])) {
                        $scanSummary['lastArticleDate'] = strtotime($scanSummary['lastArticleDate']);
                    } else {
                        $scanSummary['lastArticleDate'] = $this->postdate($scanSummary['lastArticleNumber'], $groupNNTP);
                    }
                    $this->_pdo->queryExec(sprintf('
							UPDATE groups
							SET last_record = %s, last_record_postdate = %s, last_updated = NOW()
							WHERE id = %d', $this->_pdo->escapeString($scanSummary['lastArticleNumber']), $this->_pdo->from_unixtime($scanSummary['lastArticleDate']), $groupMySQL['id']));
                } else {
                    // If we didn't fetch headers, update the record still.
                    $this->_pdo->queryExec(sprintf('
							UPDATE groups
							SET last_record = %s, last_updated = NOW()
							WHERE id = %d', $this->_pdo->escapeString($last), $groupMySQL['id']));
                }
                if ($last == $groupLast) {
                    $done = true;
                } else {
                    $first = $last;
                }
            }
            if ($this->_echoCLI) {
                $this->_colorCLI->doEcho($this->_colorCLI->primary(PHP_EOL . 'Group ' . $groupMySQL['name'] . ' processed in ' . number_format(microtime(true) - $startGroup, 2) . ' seconds.'), true);
            }
        } else {
            if ($this->_echoCLI) {
                $this->_colorCLI->doEcho($this->_colorCLI->primary('No new articles for ' . $groupMySQL['name'] . ' (first ' . number_format($first) . ', last ' . number_format($last) . ', grouplast ' . number_format($groupMySQL['last_record']) . ', total ' . number_format($total) . ")\n" . 'Server oldest: ' . number_format($groupNNTP['first']) . ' Server newest: ' . number_format($groupNNTP['last']) . ' Local newest: ' . number_format($groupMySQL['last_record'])), true);
            }
        }
    }
Ejemplo n.º 5
0
 public function updateSchedule()
 {
     $countries = $this->pdo->query("\n\t\t\t\t\t\tSELECT DISTINCT(country) AS country\n\t\t\t\t\t\tFROM tvrage\n\t\t\t\t\t\tWHERE country != ''");
     $showsindb = $this->pdo->query("\n\t\t\t\t\t\tSELECT DISTINCT(rageid) AS rageid\n\t\t\t\t\t\tFROM tvrage");
     $showarray = [];
     foreach ($showsindb as $show) {
         $showarray[] = $show['rageid'];
     }
     foreach ($countries as $country) {
         if ($this->echooutput) {
             echo $this->pdo->log->headerOver('Updating schedule for: ') . $this->pdo->log->primary($country['country']);
         }
         $sched = Utility::getURL(['url' => $this->xmlFullScheduleUrl . $country['country']]);
         if ($sched !== false && ($xml = @simplexml_load_string($sched))) {
             $tzOffset = 60 * 60 * 6;
             $yesterday = strtotime("-1 day") - $tzOffset;
             $xmlSchedule = [];
             foreach ($xml->DAY as $sDay) {
                 $currDay = strtotime($sDay['attr']);
                 foreach ($sDay as $sTime) {
                     $currTime = (string) $sTime['attr'];
                     foreach ($sTime as $sShow) {
                         $currShowName = (string) $sShow['name'];
                         $currShowId = (string) $sShow->sid;
                         $day_time = strtotime($sDay['attr'] . ' ' . $currTime);
                         $tag = $currDay < $yesterday ? 'prev' : 'next';
                         if ($tag == 'prev' || $tag == 'next' && !isset($xmlSchedule[$currShowId]['next'])) {
                             $xmlSchedule[$currShowId][$tag] = ['name' => $currShowName, 'day' => $currDay, 'time' => $currTime, 'day_time' => $day_time, 'day_date' => date("Y-m-d H:i:s", $day_time), 'title' => html_entity_decode((string) $sShow->title, ENT_QUOTES, 'UTF-8'), 'episode' => html_entity_decode((string) $sShow->ep, ENT_QUOTES, 'UTF-8')];
                             $xmlSchedule[$currShowId]['showname'] = $currShowName;
                         }
                         // Only add it here, no point adding it to tvrage aswell that will automatically happen when an ep gets posted.
                         if ($sShow->ep == "01x01") {
                             $showarray[] = $sShow->sid;
                         }
                         // Only stick current shows and new shows in there.
                         if (in_array($currShowId, $showarray)) {
                             $this->pdo->queryExec(sprintf("\n\t\t\t\t\t\t\t\t\t\t\tINSERT INTO episodeinfo (rageid, showtitle, fullep, airdate, link, eptitle)\n\t\t\t\t\t\t\t\t\t\t\tVALUES (%d, %s, %s, %s, %s, %s)\n\t\t\t\t\t\t\t\t\t\t\tON DUPLICATE KEY UPDATE\n\t\t\t\t\t\t\t\t\t\t\t\tshowtitle = %2\$s, airdate = %4\$s, link = %5\$s ,eptitle = %6\$s", $sShow->sid, $this->pdo->escapeString($currShowName), $this->pdo->escapeString($sShow->ep), $this->pdo->escapeString(date("Y-m-d H:i:s", $day_time)), $this->pdo->escapeString($sShow->link), $this->pdo->escapeString($sShow->title), $this->pdo->escapeString(date("Y-m-d H:i:s", $day_time))));
                         }
                     }
                 }
             }
             // Update series info.
             foreach ($xmlSchedule as $showId => $epInfo) {
                 $res = $this->pdo->query(sprintf("SELECT * FROM tvrage WHERE rageid = %d", $showId));
                 if (sizeof($res) > 0) {
                     foreach ($res as $arr) {
                         $prev_ep = $next_ep = "";
                         $query = [];
                         // Previous episode.
                         if (isset($epInfo['prev']) && $epInfo['prev']['episode'] != '') {
                             $prev_ep = $epInfo['prev']['episode'] . ', "' . $epInfo['prev']['title'] . '"';
                             $query[] = sprintf("prevdate = %s, previnfo = %s", $this->pdo->from_unixtime($epInfo['prev']['day_time']), $this->pdo->escapeString($prev_ep));
                         }
                         // Next episode.
                         if (isset($epInfo['next']) && $epInfo['next']['episode'] != '') {
                             if ($prev_ep == "" && $arr['nextinfo'] != '' && $epInfo['next']['day_time'] > strtotime($arr["nextdate"]) && strtotime(date('Y-m-d', strtotime($arr["nextdate"]))) < $yesterday) {
                                 $this->pdo->queryExec(sprintf("\n\t\t\t\t\t\t\t\t\t\t\t\tUPDATE tvrage\n\t\t\t\t\t\t\t\t\t\t\t\tSET prevdate = nextdate, previnfo = nextinfo\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE id = %d", $arr['id']));
                                 $prev_ep = "SWAPPED with: " . $arr['nextinfo'] . " - " . date("r", strtotime($arr["nextdate"]));
                             }
                             $next_ep = $epInfo['next']['episode'] . ', "' . $epInfo['next']['title'] . '"';
                             $query[] = sprintf("nextdate = %s, nextinfo = %s", $this->pdo->from_unixtime($epInfo['next']['day_time']), $this->pdo->escapeString($next_ep));
                         } else {
                             $query[] = "nextdate = NULL, nextinfo = NULL";
                         }
                         // Output.
                         if ($this->echooutput) {
                             echo $this->pdo->log->primary($epInfo['showname'] . " (" . $showId . "):");
                             if (isset($epInfo['prev']['day_time'])) {
                                 echo $this->pdo->log->headerOver("Prev EP: ") . $this->pdo->log->primary("{$prev_ep} - " . date("m/d/Y H:i T", $epInfo['prev']['day_time']));
                             }
                             if (isset($epInfo['next']['day_time'])) {
                                 echo $this->pdo->log->headerOver("Next EP: ") . $this->pdo->log->primary("{$next_ep} - " . date("m/d/Y H:i T", $epInfo['next']['day_time']));
                             }
                             echo "\n";
                         }
                         // Update info.
                         if (count($query) > 0) {
                             $sqlQry = join(", ", $query);
                             $this->pdo->queryExec(sprintf("\n\t\t\t\t\t\t\t\t\t\t\tUPDATE tvrage\n\t\t\t\t\t\t\t\t\t\t\tSET %s\n\t\t\t\t\t\t\t\t\t\t\tWHERE id = %d", $sqlQry, $arr['id']));
                         }
                     }
                 }
             }
         } else {
             // No response from tvrage.
             if ($this->echooutput) {
                 echo $this->pdo->log->info("Schedule not found.");
             }
         }
     }
     if ($this->echooutput) {
         echo $this->pdo->log->primary("Updated the TVRage schedule succesfully.");
     }
 }
Ejemplo n.º 6
0
    /**
     * Backfill single group.
     *
     * @param array $groupArr
     * @param int $left
     * @param int|string $articles
     *
     * @return void
     */
    public function backfillGroup($groupArr, $left, $articles = '')
    {
        // Start time for this group.
        $startGroup = microtime(true);
        $groupName = str_replace('alt.binaries', 'a.b', $groupArr['name']);
        // If our local oldest article 0, it means we never ran update_binaries on the group.
        if ($groupArr['first_record'] <= 0) {
            $dMessage = "You need to run update_binaries on " . $groupName . ". Otherwise the group is dead, you must disable it.";
            if ($this->_debug) {
                $this->_debugging->log(get_class(), __FUNCTION__, $dMessage, Logger::LOG_ERROR);
            }
            if ($this->_echoCLI) {
                $this->pdo->log->doEcho($this->pdo->log->error($dMessage));
            }
            return;
        }
        // Select group, here, only once
        $data = $this->_nntp->selectGroup($groupArr['name']);
        if ($this->_nntp->isError($data)) {
            $data = $this->_nntp->dataError($this->_nntp, $groupArr['name']);
            if ($this->_nntp->isError($data)) {
                return;
            }
        }
        if ($this->_echoCLI) {
            $this->pdo->log->doEcho($this->pdo->log->primary('Processing ' . $groupName), true);
        }
        // Check if this is days or post backfill.
        $postCheck = $articles === '' ? false : true;
        // Get target post based on date or user specified number.
        $targetpost = (string) ($postCheck ? round($groupArr['first_record'] - $articles) : $this->_binaries->daytopost($groupArr['backfill_target'], $data));
        // Check if target post is smaller than server's oldest, set it to oldest if so.
        if ($targetpost < $data['first']) {
            $targetpost = $data['first'];
        }
        // Check if our target post is newer than our oldest post or if our local oldest article is older than the servers oldest.
        if ($targetpost >= $groupArr['first_record'] || $groupArr['first_record'] <= $data['first']) {
            $dMessage = "We have hit the maximum we can backfill for " . $groupName . ($this->_disableBackfillGroup ? ", disabling backfill on it." : ", skipping it, consider disabling backfill on it.");
            if ($this->_debug) {
                $this->_debugging->log(get_class(), __FUNCTION__, $dMessage, Logger::LOG_NOTICE);
            }
            if ($this->_disableBackfillGroup) {
                $this->pdo->queryExec(sprintf('
					UPDATE groups
					SET backfill = 0
					WHERE id = %d', $groupArr['id']));
            }
            if ($this->_echoCLI) {
                $this->pdo->log->doEcho($this->pdo->log->notice($dMessage), true);
            }
            return;
        }
        if ($this->_echoCLI) {
            $this->pdo->log->doEcho($this->pdo->log->primary('Group ' . $groupName . "'s oldest article is " . number_format($data['first']) . ', newest is ' . number_format($data['last']) . ".\nOur target article is " . number_format($targetpost) . '. Our oldest article is article ' . number_format($groupArr['first_record']) . '.'));
        }
        // Set first and last, moving the window by max messages.
        $last = (string) ($groupArr['first_record'] - 1);
        // Set the initial "chunk".
        $first = (string) ($last - $this->_binaries->messageBuffer + 1);
        // Just in case this is the last chunk we needed.
        if ($targetpost > $first) {
            $first = $targetpost;
        }
        $done = false;
        while ($done === false) {
            if ($this->_echoCLI) {
                $this->pdo->log->doEcho($this->pdo->log->set256('Yellow') . "\nGetting " . number_format($last - $first + 1) . " articles from " . $groupName . ", " . $left . " group(s) left. (" . number_format($first - $targetpost) . " articles in queue)." . $this->pdo->log->rsetColor(), true);
            }
            flush();
            $lastMsg = $this->_binaries->scan($groupArr, $first, $last, $this->_safePartRepair);
            // Get the oldest date.
            if (isset($lastMsg['firstArticleDate'])) {
                // Try to get it from the oldest pulled article.
                $newdate = strtotime($lastMsg['firstArticleDate']);
            } else {
                // If above failed, try to get it with postdate method.
                $newdate = $this->_binaries->postdate($first, $data);
            }
            $this->pdo->queryExec(sprintf('
					UPDATE groups
					SET first_record_postdate = %s, first_record = %s, last_updated = NOW()
					WHERE id = %d', $this->pdo->from_unixtime($newdate), $this->pdo->escapeString($first), $groupArr['id']));
            if ($first == $targetpost) {
                $done = true;
            } else {
                // Keep going: set new last, new first, check for last chunk.
                $last = (string) ($first - 1);
                $first = (string) ($last - $this->_binaries->messageBuffer + 1);
                if ($targetpost > $first) {
                    $first = $targetpost;
                }
            }
        }
        if ($this->_echoCLI) {
            $this->pdo->log->doEcho($this->pdo->log->primary(PHP_EOL . 'Group ' . $groupName . ' processed in ' . number_format(microtime(true) - $startGroup, 2) . " seconds."), true);
        }
    }