|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\Settings; |
|
6
|
|
|
use App\Models\UsenetGroup; |
|
7
|
|
|
use Blacklight\Backfill; |
|
8
|
|
|
use Blacklight\Binaries; |
|
9
|
|
|
use Blacklight\Nfo; |
|
10
|
|
|
use Blacklight\NNTP; |
|
11
|
|
|
use Blacklight\processing\post\ProcessAdditional; |
|
12
|
|
|
use Blacklight\processing\ProcessReleases; |
|
13
|
|
|
use Illuminate\Console\Command; |
|
14
|
|
|
use Illuminate\Support\Facades\Log; |
|
15
|
|
|
|
|
16
|
|
|
class UpdatePerGroup extends Command |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* The name and signature of the console command. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $signature = 'group:update-all {groupId : Group ID to process}'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The console command description. |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $description = 'Do a single group (update_binaries/backFill/update_releases/postprocess)'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Execute the console command. |
|
34
|
|
|
*/ |
|
35
|
|
|
public function handle(): int |
|
36
|
|
|
{ |
|
37
|
|
|
$groupId = $this->argument('groupId'); |
|
38
|
|
|
|
|
39
|
|
|
if (! is_numeric($groupId)) { |
|
40
|
|
|
$this->error('Group ID must be numeric.'); |
|
41
|
|
|
|
|
42
|
|
|
return self::FAILURE; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
try { |
|
46
|
|
|
$groupMySQL = UsenetGroup::find($groupId)->toArray(); |
|
47
|
|
|
|
|
48
|
|
|
if ($groupMySQL === null) { |
|
49
|
|
|
$this->error("Group not found with id {$groupId}"); |
|
50
|
|
|
|
|
51
|
|
|
return self::FAILURE; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$nntp = $this->getNntp(); |
|
55
|
|
|
$backFill = new Backfill; |
|
56
|
|
|
|
|
57
|
|
|
// Update the group for new binaries |
|
58
|
|
|
$this->info("Updating binaries for group: {$groupMySQL['name']}"); |
|
59
|
|
|
(new Binaries)->updateGroup($groupMySQL); |
|
60
|
|
|
|
|
61
|
|
|
// BackFill the group with 20k articles |
|
62
|
|
|
$this->info("Backfilling group: {$groupMySQL['name']}"); |
|
63
|
|
|
$backFill->backfillAllGroups($groupMySQL['name'], 20000, 'normal'); |
|
64
|
|
|
|
|
65
|
|
|
// Create releases |
|
66
|
|
|
$this->info("Processing releases for group: {$groupMySQL['name']}"); |
|
67
|
|
|
$this->processReleases(new ProcessReleases, $groupId); |
|
68
|
|
|
|
|
69
|
|
|
// Post process the releases |
|
70
|
|
|
$this->info("Post-processing additional for group: {$groupMySQL['name']}"); |
|
71
|
|
|
(new ProcessAdditional(['Echo' => true, 'NNTP' => $nntp]))->start($groupId); |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
$this->info("Processing NFO files for group: {$groupMySQL['name']}"); |
|
74
|
|
|
(new Nfo)->processNfoFiles( |
|
75
|
|
|
$nntp, |
|
76
|
|
|
$groupId, |
|
77
|
|
|
'', |
|
78
|
|
|
(int) Settings::settingValue('lookupimdb'), |
|
|
|
|
|
|
79
|
|
|
(int) Settings::settingValue('lookuptv') |
|
|
|
|
|
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
$this->info("Completed all processing for group: {$groupMySQL['name']}"); |
|
83
|
|
|
|
|
84
|
|
|
return self::SUCCESS; |
|
85
|
|
|
} catch (\Throwable $e) { |
|
86
|
|
|
Log::error($e->getTraceAsString()); |
|
87
|
|
|
$this->error($e->getMessage()); |
|
88
|
|
|
|
|
89
|
|
|
return self::FAILURE; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Create / process releases for a groupID. |
|
95
|
|
|
*/ |
|
96
|
|
|
private function processReleases(ProcessReleases $releases, string $groupID): void |
|
97
|
|
|
{ |
|
98
|
|
|
$releaseCreationLimit = Settings::settingValue('maxnzbsprocessed') !== '' |
|
99
|
|
|
? (int) Settings::settingValue('maxnzbsprocessed') |
|
100
|
|
|
: 1000; |
|
101
|
|
|
|
|
102
|
|
|
$releases->processIncompleteCollections($groupID); |
|
103
|
|
|
$releases->processCollectionSizes($groupID); |
|
104
|
|
|
$releases->deleteUnwantedCollections($groupID); |
|
105
|
|
|
|
|
106
|
|
|
do { |
|
107
|
|
|
$releasesCount = $releases->createReleases($groupID); |
|
108
|
|
|
$nzbFilesAdded = $releases->createNZBs($groupID); |
|
109
|
|
|
} while ($releaseCreationLimit <= $releasesCount['added'] + $releasesCount['dupes'] |
|
110
|
|
|
|| $nzbFilesAdded >= $releaseCreationLimit); |
|
111
|
|
|
|
|
112
|
|
|
$releases->deleteCollections($groupID); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Get NNTP connection. |
|
117
|
|
|
*/ |
|
118
|
|
|
private function getNntp(): NNTP |
|
119
|
|
|
{ |
|
120
|
|
|
$nntp = new NNTP; |
|
121
|
|
|
|
|
122
|
|
|
if ((config('nntmux_nntp.use_alternate_nntp_server') === true |
|
123
|
|
|
? $nntp->doConnect(false, true) |
|
124
|
|
|
: $nntp->doConnect()) !== true) { |
|
125
|
|
|
throw new \Exception('Unable to connect to usenet.'); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return $nntp; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
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.