|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\Release; |
|
6
|
|
|
use Blacklight\processing\post\ProcessAdditional; |
|
7
|
|
|
use Illuminate\Console\Command; |
|
8
|
|
|
|
|
9
|
|
|
class ProcessAdditionalGuid extends Command |
|
10
|
|
|
{ |
|
11
|
|
|
protected $signature = 'releases:additional |
|
12
|
|
|
{guid? : Release GUID (optional if using --id)} |
|
13
|
|
|
{--id= : Numeric release ID to run additional postprocessing on (alternative to GUID)} |
|
14
|
|
|
{--reset : Reset key additional postprocessing flags before running} |
|
15
|
|
|
{--no-progress : Suppress progress / status output (forces quiet mode)}'; |
|
16
|
|
|
|
|
17
|
|
|
protected $description = 'Run additional postprocessing for a specific release by GUID or ID regardless of prior postprocessing status'; |
|
18
|
|
|
|
|
19
|
|
|
public function handle(): int |
|
20
|
|
|
{ |
|
21
|
|
|
$guidArg = trim((string) $this->argument('guid')); |
|
22
|
|
|
$idOpt = $this->option('id'); |
|
23
|
|
|
|
|
24
|
|
|
if ($guidArg === '' && ($idOpt === null || $idOpt === '')) { |
|
25
|
|
|
$this->error('You must supply either a GUID argument or --id=<release id>.'); |
|
26
|
|
|
|
|
27
|
|
|
return 1; // missing identifier |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
if ($guidArg !== '' && $idOpt !== null && $idOpt !== '') { |
|
31
|
|
|
$this->error('Provide only one identifier: GUID or --id, not both.'); |
|
32
|
|
|
|
|
33
|
|
|
return 4; // conflicting identifiers |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$release = null; |
|
37
|
|
|
$guid = ''; |
|
38
|
|
|
|
|
39
|
|
|
if ($idOpt !== null && $idOpt !== '') { |
|
40
|
|
|
if (! ctype_digit((string) $idOpt)) { |
|
41
|
|
|
$this->error('Release ID must be numeric.'); |
|
42
|
|
|
|
|
43
|
|
|
return 5; // invalid id format |
|
44
|
|
|
} |
|
45
|
|
|
$release = Release::find((int) $idOpt); |
|
46
|
|
|
if ($release === null) { |
|
47
|
|
|
$this->error('Release not found for ID: '.$idOpt); |
|
48
|
|
|
|
|
49
|
|
|
return 2; // not found |
|
50
|
|
|
} |
|
51
|
|
|
$guid = $release->guid; |
|
|
|
|
|
|
52
|
|
|
} else { |
|
53
|
|
|
$guid = $guidArg; |
|
54
|
|
|
if ($guid === '') { // should not happen but guard |
|
55
|
|
|
$this->error('GUID is required if --id not supplied.'); |
|
56
|
|
|
|
|
57
|
|
|
return 1; |
|
58
|
|
|
} |
|
59
|
|
|
$release = Release::where('guid', $guid)->first(); |
|
60
|
|
|
if ($release === null) { |
|
61
|
|
|
$this->error('Release not found for GUID: '.$guid); |
|
62
|
|
|
|
|
63
|
|
|
return 2; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if ($this->option('reset')) { |
|
68
|
|
|
Release::where('id', $release->id)->update([ |
|
69
|
|
|
'passwordstatus' => -1, |
|
70
|
|
|
'haspreview' => -1, |
|
71
|
|
|
'jpgstatus' => 0, |
|
72
|
|
|
'videostatus' => 0, |
|
73
|
|
|
'audiostatus' => 0, |
|
74
|
|
|
'nfostatus' => -1, |
|
75
|
|
|
]); |
|
76
|
|
|
$this->info('Reset postprocessing flags for release ID '.$release->id.' (GUID '.$guid.')'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
if ($this->option('no-progress')) { |
|
80
|
|
|
config(['nntmux.echocli' => false]); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$processor = new ProcessAdditional; |
|
84
|
|
|
$ok = $processor->processSingleGuid($guid); |
|
85
|
|
|
|
|
86
|
|
|
if (! $ok) { |
|
87
|
|
|
$this->error('Processing failed or nothing processed for '.($idOpt ? 'ID '.$idOpt : 'GUID '.$guid).'.'); |
|
88
|
|
|
|
|
89
|
|
|
return 3; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$this->info('Additional postprocessing completed for '.($idOpt ? 'ID '.$idOpt : 'GUID '.$guid).'.'); |
|
93
|
|
|
|
|
94
|
|
|
return 0; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|