|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Blacklight\Backfill; |
|
6
|
|
|
use Blacklight\NNTP; |
|
7
|
|
|
use Illuminate\Console\Command; |
|
8
|
|
|
|
|
9
|
|
|
class UpdateBackfill extends Command |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* The name and signature of the console command. |
|
13
|
|
|
* |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $signature = 'update:backfill |
|
17
|
|
|
{mode=all : Mode: all, alph, date, safe, or group name} |
|
18
|
|
|
{quantity? : Number of articles to backfill}'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The console command description. |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $description = 'Backfill groups by various methods'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Execute the console command. |
|
29
|
|
|
*/ |
|
30
|
|
|
public function handle(): int |
|
31
|
|
|
{ |
|
32
|
|
|
$mode = $this->argument('mode'); |
|
33
|
|
|
$quantity = $this->argument('quantity'); |
|
34
|
|
|
|
|
35
|
|
|
try { |
|
36
|
|
|
$nntp = $this->getNntp(); |
|
37
|
|
|
$backfill = new Backfill(['NNTP' => $nntp]); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
match (true) { |
|
40
|
|
|
$mode === 'all' && ! isset($quantity) => $backfill->backfillAllGroups(), |
|
|
|
|
|
|
41
|
|
|
$mode === 'alph' && is_numeric($quantity) => $backfill->backfillAllGroups('', (int) $quantity, 'normal'), |
|
|
|
|
|
|
42
|
|
|
$mode === 'date' && is_numeric($quantity) => $backfill->backfillAllGroups('', (int) $quantity, 'date'), |
|
|
|
|
|
|
43
|
|
|
$mode === 'safe' && is_numeric($quantity) => $backfill->safeBackfill((int) $quantity), |
|
|
|
|
|
|
44
|
|
|
preg_match('/^alt\.binaries\..+$/i', $mode) && ! isset($quantity) => $backfill->backfillAllGroups($mode), |
|
|
|
|
|
|
45
|
|
|
preg_match('/^alt\.binaries\..+$/i', $mode) && is_numeric($quantity) => $backfill->backfillAllGroups($mode, (int) $quantity), |
|
|
|
|
|
|
46
|
|
|
default => throw new \Exception($this->getHelpText()), |
|
47
|
|
|
}; |
|
48
|
|
|
|
|
49
|
|
|
return self::SUCCESS; |
|
50
|
|
|
} catch (\Throwable $e) { |
|
51
|
|
|
$this->error($e->getMessage()); |
|
52
|
|
|
|
|
53
|
|
|
return self::FAILURE; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Get help text. |
|
59
|
|
|
*/ |
|
60
|
|
|
private function getHelpText(): string |
|
61
|
|
|
{ |
|
62
|
|
|
return "Wrong set of arguments.\n\n" |
|
63
|
|
|
."Examples:\n" |
|
64
|
|
|
." php artisan update:backfill all - Backfills all groups 1 at a time, by date\n" |
|
65
|
|
|
." php artisan update:backfill alt.binaries.ath - Backfills a group by name, by date\n" |
|
66
|
|
|
." php artisan update:backfill alt.binaries.ath 200000 - Backfills a group by name by number of articles\n" |
|
67
|
|
|
." php artisan update:backfill alph 200000 - Backfills all groups (alphabetically) by number of articles\n" |
|
68
|
|
|
." php artisan update:backfill date 200000 - Backfills all groups (by least backfilled) by number of articles\n" |
|
69
|
|
|
." php artisan update:backfill safe 200000 - Safe backfill, stops at 2012-06-24\n"; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Get NNTP connection. |
|
74
|
|
|
*/ |
|
75
|
|
|
private function getNntp(): NNTP |
|
76
|
|
|
{ |
|
77
|
|
|
$nntp = new NNTP; |
|
78
|
|
|
|
|
79
|
|
|
if ($nntp->doConnect() !== true) { |
|
80
|
|
|
throw new \Exception('Unable to connect to usenet.'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return $nntp; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.