NNTmux /
newznab-tmux
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Console\Commands; |
||
| 4 | |||
| 5 | use App\Models\Settings; |
||
| 6 | use Blacklight\Backfill; |
||
| 7 | use Illuminate\Console\Command; |
||
| 8 | use Illuminate\Support\Facades\Log; |
||
| 9 | |||
| 10 | class BackfillGroup extends Command |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * The name and signature of the console command. |
||
| 14 | * |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | protected $signature = 'backfill:group |
||
| 18 | {group : The group name to backfill} |
||
| 19 | {type=1 : Backfill type (1=interval, 2=all)} |
||
| 20 | {quantity? : Number of articles to backfill}'; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The console command description. |
||
| 24 | * |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $description = 'Backfill a specific usenet group'; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Execute the console command. |
||
| 31 | */ |
||
| 32 | public function handle(): int |
||
| 33 | { |
||
| 34 | $group = $this->argument('group'); |
||
| 35 | $type = (int) $this->argument('type'); |
||
| 36 | $quantity = $this->argument('quantity'); |
||
| 37 | |||
| 38 | if (! \in_array($type, [1, 2], true)) { |
||
| 39 | $this->error('Invalid backfill type. Must be 1 (interval) or 2 (all).'); |
||
| 40 | |||
| 41 | return self::FAILURE; |
||
| 42 | } |
||
| 43 | |||
| 44 | try { |
||
| 45 | $nntp = $this->getNntp(); |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 46 | |||
| 47 | if ($quantity === null) { |
||
| 48 | $value = Settings::settingValue('backfill_qty'); |
||
| 49 | $quantity = ($type === 1 ? '' : $value); |
||
| 50 | } |
||
| 51 | |||
| 52 | $this->info("Backfilling group: {$group}"); |
||
| 53 | (new Backfill)->backfillAllGroups($group, $quantity); |
||
| 54 | |||
| 55 | return self::SUCCESS; |
||
| 56 | } catch (\Throwable $e) { |
||
| 57 | Log::error($e->getTraceAsString()); |
||
| 58 | $this->error($e->getMessage()); |
||
| 59 | |||
| 60 | return self::FAILURE; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Get NNTP connection. |
||
| 66 | */ |
||
| 67 | private function getNntp(): \Blacklight\NNTP |
||
| 68 | { |
||
| 69 | $nntp = new \Blacklight\NNTP; |
||
| 70 | |||
| 71 | if ((config('nntmux_nntp.use_alternate_nntp_server') === true |
||
| 72 | ? $nntp->doConnect(false, true) |
||
| 73 | : $nntp->doConnect()) !== true) { |
||
| 74 | throw new \Exception('Unable to connect to usenet.'); |
||
| 75 | } |
||
| 76 | |||
| 77 | return $nntp; |
||
| 78 | } |
||
| 79 | } |
||
| 80 |