argument('group'); $max = $this->argument('max'); $maxHeaders = is_numeric($max) && $max > 0 ? (int) $max : ((int) Settings::settingValue('max_headers_iteration') ?: 1000000); try { $nntp = $this->getNntp(); $binaries = new Binaries(['NNTP' => $nntp]); if ($groupName && ! is_numeric($groupName)) { $this->info("Updating group: {$groupName}"); $this->updateSingleGroup($binaries, $groupName, $maxHeaders); } else { $this->info('Updating all groups...'); $binaries->updateAllGroups($maxHeaders); } return self::SUCCESS; } catch (\Throwable $e) { Log::error($e->getMessage()); $this->error($e->getMessage()); return self::FAILURE; } } /** * Update a single group. */ private function updateSingleGroup(Binaries $binaries, string $groupName, int $maxHeaders): void { $group = UsenetGroup::getByName($groupName)->toArray(); if (! is_array($group)) { throw new \Exception("Group not found: {$groupName}"); } $binaries->updateGroup($group, $maxHeaders); } /** * Get NNTP connection. */ private function getNntp(): NNTP { $nntp = new NNTP; if ($nntp->doConnect() !== true) { throw new \Exception('Unable to connect to usenet.'); } return $nntp; } }