Issues (955)

app/Console/Commands/FixReleaseNames.php (9 issues)

Labels
Severity
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Services\NameFixing\NameFixingService;
6
use App\Services\NNTP\NNTPService;
7
use Illuminate\Console\Command;
8
9
class FixReleaseNames extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'releases:fix-names
17
                                 {method : The method number (3-20) to use for fixing names}
18
                                 {--update : Actually update the names, otherwise just display results}
19
                                 {--category=other : Category to process: "other", "all", or "predb_id"}
20
                                 {--set-status : Set releases as checked after processing}
21
                                 {--show : Display detailed release changes rather than just counters}';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Fix release names using various methods (NFO, file name, Par2, etc.)';
29
30
    /**
31
     * Execute the console command.
32
     */
33
    public function handle(NameFixingService $nameFixingService, NNTPService $nntp): int
34
    {
35
        $method = $this->argument('method');
36
        $update = (bool) $this->option('update');
37
        $setStatus = (bool) $this->option('set-status');
38
        $show = $this->option('show');
39
40
        // Set category option
41
        $categoryOption = $this->option('category');
42
        $other = 1;
43
        if ($categoryOption === 'all') {
44
            $other = 2;
45
        } elseif ($categoryOption === 'predb_id') {
46
            $other = 3;
47
        }
48
49
        // Connect to NNTP if method requires it
50
        if ($method === '7' || $method === '8') {
51
            $compressedHeaders = config('nntmux_nntp.compressed_headers');
52
            $connectResult = config('nntmux_nntp.use_alternate_nntp_server') === true
53
                ? $nntp->doConnect($compressedHeaders, true)
54
                : $nntp->doConnect();
55
56
            if ($connectResult !== true) {
57
                $errorMessage = 'Unable to connect to usenet.';
58
                if (NNTPService::isError($connectResult)) {
59
                    $errorMessage .= ' Error: '.$connectResult->getMessage();
60
                }
61
                $this->error($errorMessage);
62
63
                return 1;
64
            }
65
        }
66
67
        switch ($method) {
68
            case '3':
69
                $nameFixingService->fixNamesWithNfo(1, $update, $other, $setStatus, $show);
0 ignored issues
show
$show of type string is incompatible with the type boolean expected by parameter $show of App\Services\NameFixing\...vice::fixNamesWithNfo(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

69
                $nameFixingService->fixNamesWithNfo(1, $update, $other, $setStatus, /** @scrutinizer ignore-type */ $show);
Loading history...
70
                break;
71
            case '4':
72
                $nameFixingService->fixNamesWithNfo(2, $update, $other, $setStatus, $show);
73
                break;
74
            case '5':
75
                $nameFixingService->fixNamesWithFiles(1, $update, $other, $setStatus, $show);
0 ignored issues
show
$show of type string is incompatible with the type boolean expected by parameter $show of App\Services\NameFixing\...ce::fixNamesWithFiles(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

75
                $nameFixingService->fixNamesWithFiles(1, $update, $other, $setStatus, /** @scrutinizer ignore-type */ $show);
Loading history...
76
                break;
77
            case '6':
78
                $nameFixingService->fixNamesWithFiles(2, $update, $other, $setStatus, $show);
79
                break;
80
            case '7':
81
                $nameFixingService->fixNamesWithPar2(1, $update, $other, $setStatus, $show, $nntp);
0 ignored issues
show
$show of type string is incompatible with the type boolean expected by parameter $show of App\Services\NameFixing\...ice::fixNamesWithPar2(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

81
                $nameFixingService->fixNamesWithPar2(1, $update, $other, $setStatus, /** @scrutinizer ignore-type */ $show, $nntp);
Loading history...
82
                break;
83
            case '8':
84
                $nameFixingService->fixNamesWithPar2(2, $update, $other, $setStatus, $show, $nntp);
85
                break;
86
            case '9':
87
                $nameFixingService->fixNamesWithMedia(1, $update, $other, $setStatus, $show);
0 ignored issues
show
$show of type string is incompatible with the type boolean expected by parameter $show of App\Services\NameFixing\...ce::fixNamesWithMedia(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
                $nameFixingService->fixNamesWithMedia(1, $update, $other, $setStatus, /** @scrutinizer ignore-type */ $show);
Loading history...
88
                break;
89
            case '10':
90
                $nameFixingService->fixNamesWithMedia(2, $update, $other, $setStatus, $show);
91
                break;
92
            case '11':
93
                $nameFixingService->fixXXXNamesWithFiles(1, $update, $other, $setStatus, $show);
0 ignored issues
show
$show of type string is incompatible with the type boolean expected by parameter $show of App\Services\NameFixing\...:fixXXXNamesWithFiles(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

93
                $nameFixingService->fixXXXNamesWithFiles(1, $update, $other, $setStatus, /** @scrutinizer ignore-type */ $show);
Loading history...
94
                break;
95
            case '12':
96
                $nameFixingService->fixXXXNamesWithFiles(2, $update, $other, $setStatus, $show);
97
                break;
98
            case '13':
99
                $nameFixingService->fixNamesWithSrr(1, $update, $other, $setStatus, $show);
0 ignored issues
show
$show of type string is incompatible with the type boolean expected by parameter $show of App\Services\NameFixing\...vice::fixNamesWithSrr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

99
                $nameFixingService->fixNamesWithSrr(1, $update, $other, $setStatus, /** @scrutinizer ignore-type */ $show);
Loading history...
100
                break;
101
            case '14':
102
                $nameFixingService->fixNamesWithSrr(2, $update, $other, $setStatus, $show);
103
                break;
104
            case '15':
105
                $nameFixingService->fixNamesWithParHash(1, $update, $other, $setStatus, $show);
0 ignored issues
show
$show of type string is incompatible with the type boolean expected by parameter $show of App\Services\NameFixing\...::fixNamesWithParHash(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

105
                $nameFixingService->fixNamesWithParHash(1, $update, $other, $setStatus, /** @scrutinizer ignore-type */ $show);
Loading history...
106
                break;
107
            case '16':
108
                $nameFixingService->fixNamesWithParHash(2, $update, $other, $setStatus, $show);
109
                break;
110
            case '17':
111
                $nameFixingService->fixNamesWithMediaMovieName(1, $update, $other, $setStatus, $show);
0 ignored issues
show
$show of type string is incompatible with the type boolean expected by parameter $show of App\Services\NameFixing\...mesWithMediaMovieName(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

111
                $nameFixingService->fixNamesWithMediaMovieName(1, $update, $other, $setStatus, /** @scrutinizer ignore-type */ $show);
Loading history...
112
                break;
113
            case '18':
114
                $nameFixingService->fixNamesWithMediaMovieName(2, $update, $other, $setStatus, $show);
115
                break;
116
            case '19':
117
                $nameFixingService->fixNamesWithCrc(1, $update, $other, $setStatus, $show);
0 ignored issues
show
$show of type string is incompatible with the type boolean expected by parameter $show of App\Services\NameFixing\...vice::fixNamesWithCrc(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

117
                $nameFixingService->fixNamesWithCrc(1, $update, $other, $setStatus, /** @scrutinizer ignore-type */ $show);
Loading history...
118
                break;
119
            case '20':
120
                $nameFixingService->fixNamesWithCrc(2, $update, $other, $setStatus, $show);
121
                break;
122
            default:
123
                $this->showHelp();
124
125
                return 1;
126
        }
127
128
        return 0;
129
    }
130
131
    /**
132
     * Display detailed help information.
133
     */
134
    protected function showHelp(): void
135
    {
136
        $this->info('');
137
        $this->info('Usage Examples:');
138
        $this->info('');
139
        $this->info('php artisan releases:fix-names 3 : Fix release names using NFO in the past 6 hours.');
140
        $this->info('php artisan releases:fix-names 4 : Fix release names using NFO.');
141
        $this->info('php artisan releases:fix-names 5 : Fix release names in misc categories using File Name in the past 6 hours.');
142
        $this->info('php artisan releases:fix-names 6 : Fix release names in misc categories using File Name.');
143
        $this->info('php artisan releases:fix-names 7 : Fix release names in misc categories using Par2 Files in the past 6 hours.');
144
        $this->info('php artisan releases:fix-names 8 : Fix release names in misc categories using Par2 Files.');
145
        $this->info('php artisan releases:fix-names 9 : Fix release names in misc categories using UID in the past 6 hours.');
146
        $this->info('php artisan releases:fix-names 10 : Fix release names in misc categories using UID.');
147
        $this->info('php artisan releases:fix-names 11 : Fix SDPORN XXX release names using specific File Name in the past 6 hours.');
148
        $this->info('php artisan releases:fix-names 12 : Fix SDPORN XXX release names using specific File Name.');
149
        $this->info('php artisan releases:fix-names 13 : Fix release names using SRR files in the past 6 hours.');
150
        $this->info('php artisan releases:fix-names 14 : Fix release names using SRR files.');
151
        $this->info('php artisan releases:fix-names 15 : Fix release names using PAR2 hash_16K block in the past 6 hours.');
152
        $this->info('php artisan releases:fix-names 16 : Fix release names using PAR2 hash_16K block.');
153
        $this->info('php artisan releases:fix-names 17 : Fix release names using Mediainfo in the past 6 hours.');
154
        $this->info('php artisan releases:fix-names 18 : Fix release names using Mediainfo.');
155
        $this->info('php artisan releases:fix-names 19 : Fix release names using CRC32 in the past 6 hours.');
156
        $this->info('php artisan releases:fix-names 20 : Fix release names using CRC32.');
157
        $this->info('');
158
        $this->info('Options:');
159
        $this->info('  --update           Actually update the names (default: only display potential changes)');
160
        $this->info('  --category=VALUE   Process "other" categories (default), "all" categories, or "predb_id" for unmatched');
161
        $this->info('  --set-status       Mark releases as checked so they won\'t be processed again');
162
        $this->info('  --show             Display detailed release changes (default: only show counters)');
163
        $this->info('');
164
    }
165
}
166