1 | <?php |
||
2 | |||
3 | namespace App\Console\Commands; |
||
4 | |||
5 | use App\Models\Category; |
||
6 | use App\Models\Release; |
||
7 | use Illuminate\Console\Command; |
||
8 | |||
9 | class NntmuxResetPostProcessing extends Command |
||
10 | { |
||
11 | /** |
||
12 | * @var array |
||
13 | */ |
||
14 | private static $allowedCategories = [ |
||
15 | 'music', |
||
16 | 'console', |
||
17 | 'movie', |
||
18 | 'game', |
||
19 | 'tv', |
||
20 | 'adult', |
||
21 | 'book', |
||
22 | 'misc', |
||
23 | ]; |
||
24 | |||
25 | /** |
||
26 | * The name and signature of the console command. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $signature = 'nntmux:resetpp {--c|category=* : Reset all, multiple or single category}'; |
||
31 | |||
32 | /** |
||
33 | * The console command description. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $description = 'Reset all, multiple or single release category postprocessing'; |
||
38 | |||
39 | /** |
||
40 | * Create a new command instance. |
||
41 | * |
||
42 | * @return void |
||
43 | */ |
||
44 | public function __construct() |
||
45 | { |
||
46 | parent::__construct(); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Execute the console command. |
||
51 | */ |
||
52 | public function handle(): void |
||
53 | { |
||
54 | if (empty($this->option('category'))) { |
||
55 | $qry = Release::query()->select(['id'])->get(); |
||
56 | $affected = 0; |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
57 | $total = \count($qry); |
||
58 | if ($total > 0) { |
||
59 | $bar = $this->output->createProgressBar($total); |
||
60 | $bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this? |
||
61 | $bar->start(); |
||
62 | $this->info('Resetting all postprocessing'); |
||
63 | foreach ($qry as $releases) { |
||
64 | Release::query()->where('id', $releases->id)->update( |
||
65 | [ |
||
66 | 'consoleinfo_id' => null, |
||
67 | 'gamesinfo_id' => null, |
||
68 | 'imdbid' => null, |
||
69 | 'movieinfo_id' => null, |
||
70 | 'musicinfo_id' => null, |
||
71 | 'bookinfo_id' => null, |
||
72 | 'videos_id' => 0, |
||
73 | 'tv_episodes_id' => 0, |
||
74 | 'xxxinfo_id' => 0, |
||
75 | 'passwordstatus' => -1, |
||
76 | 'haspreview' => -1, |
||
77 | 'jpgstatus' => 0, |
||
78 | 'videostatus' => 0, |
||
79 | 'audiostatus' => 0, |
||
80 | 'nfostatus' => -1, |
||
81 | ] |
||
82 | ); |
||
83 | $bar->advance(); |
||
84 | } |
||
85 | $bar->finish(); |
||
86 | $this->newLine(); |
||
87 | } else { |
||
88 | $this->info('No releases to reset'); |
||
89 | } |
||
90 | } else { |
||
91 | foreach ($this->option('category') as $option) { |
||
92 | $adjusted = str_replace('=', '', $option); |
||
93 | if (\in_array($adjusted, self::$allowedCategories, false)) { |
||
94 | $this->info('Resetting postprocessing for '.$adjusted.' category'); |
||
95 | switch ($adjusted) { |
||
96 | case 'console': |
||
97 | $this->resetConsole(); |
||
98 | break; |
||
99 | case 'movie': |
||
100 | $this->resetMovies(); |
||
101 | break; |
||
102 | case 'game': |
||
103 | $this->resetGames(); |
||
104 | break; |
||
105 | case 'book': |
||
106 | $this->resetBooks(); |
||
107 | break; |
||
108 | case 'music': |
||
109 | $this->resetMusic(); |
||
110 | break; |
||
111 | case 'adult': |
||
112 | $this->resetAdult(); |
||
113 | break; |
||
114 | case 'tv': |
||
115 | $this->resetTv(); |
||
116 | break; |
||
117 | case 'misc': |
||
118 | $this->resetMisc(); |
||
119 | break; |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | } |
||
124 | } |
||
125 | |||
126 | private function resetConsole(): void |
||
127 | { |
||
128 | $qry = Release::query()->whereNotNull('consoleinfo_id')->whereBetween('categories_id', [Category::GAME_ROOT, Category::GAME_OTHER])->get(); |
||
129 | $total = $qry->count(); |
||
130 | $bar = $this->output->createProgressBar($total); |
||
131 | $bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this? |
||
132 | $bar->start(); |
||
133 | if ($total > 0) { |
||
134 | $conCount = 0; |
||
135 | foreach ($qry as $releases) { |
||
136 | Release::query()->where('id', $releases->id)->update( |
||
137 | [ |
||
138 | 'consoleinfo_id' => null, |
||
139 | ]); |
||
140 | $bar->advance(); |
||
141 | } |
||
142 | $bar->finish(); |
||
143 | $this->newLine(); |
||
144 | $this->info(number_format($conCount).' consoleinfo_id\'s reset.'); |
||
145 | } else { |
||
146 | $this->info('No releases to reset'); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | private function resetMovies(): void |
||
151 | { |
||
152 | $qry = Release::query()->whereNotNull('movieinfo_id')->whereBetween('categories_id', [Category::MOVIE_ROOT, Category::MOVIE_OTHER])->get(); |
||
153 | $total = $qry->count(); |
||
154 | if ($total > 0) { |
||
155 | $bar = $this->output->createProgressBar($total); |
||
156 | $bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this? |
||
157 | $bar->start(); |
||
158 | $conCount = 0; |
||
159 | foreach ($qry as $releases) { |
||
160 | Release::query()->where('id', $releases->id)->update( |
||
161 | [ |
||
162 | 'movieinfo_id' => null, |
||
163 | 'imdbid' => null, |
||
164 | ]); |
||
165 | $bar->advance(); |
||
166 | } |
||
167 | $bar->finish(); |
||
168 | $this->newLine(); |
||
169 | $this->info(number_format($conCount).' movieinfo_id\'s reset.'); |
||
170 | } else { |
||
171 | $this->info('No releases to reset'); |
||
172 | } |
||
173 | } |
||
174 | |||
175 | private function resetGames(): void |
||
176 | { |
||
177 | $qry = Release::query()->whereNotNull('gamesinfo_id')->where('categories_id', '=', Category::PC_GAMES)->get(); |
||
178 | $total = $qry->count(); |
||
179 | if ($total > 0) { |
||
180 | $bar = $this->output->createProgressBar($total); |
||
181 | $bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this? |
||
182 | $bar->start(); |
||
183 | $conCount = 0; |
||
184 | foreach ($qry as $releases) { |
||
185 | Release::query()->where('id', $releases->id)->update( |
||
186 | [ |
||
187 | 'gamesinfo_id' => null, |
||
188 | ]); |
||
189 | $bar->advance(); |
||
190 | } |
||
191 | $bar->finish(); |
||
192 | $this->newLine(); |
||
193 | $this->info(number_format($conCount).' gamesinfo_id\'s reset.'); |
||
194 | } else { |
||
195 | $this->info('No releases to reset'); |
||
196 | } |
||
197 | } |
||
198 | |||
199 | private function resetBooks(): void |
||
200 | { |
||
201 | $qry = Release::query()->whereNotNull('bookinfo_id')->whereBetween('categories_id', [Category::BOOKS_ROOT, Category::BOOKS_UNKNOWN])->get(); |
||
202 | $total = $qry->count(); |
||
203 | if ($total > 0) { |
||
204 | $bar = $this->output->createProgressBar($total); |
||
205 | $bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this? |
||
206 | $bar->start(); |
||
207 | $conCount = 0; |
||
208 | foreach ($qry as $releases) { |
||
209 | Release::query()->where('id', $releases->id)->update( |
||
210 | [ |
||
211 | 'bookinfo_id' => null, |
||
212 | ]); |
||
213 | $bar->advance(); |
||
214 | } |
||
215 | $bar->finish(); |
||
216 | $this->newLine(); |
||
217 | $this->info(number_format($conCount).' bookinfo_id\'s reset.'); |
||
218 | } else { |
||
219 | $this->info('No releases to reset'); |
||
220 | } |
||
221 | } |
||
222 | |||
223 | private function resetMusic(): void |
||
224 | { |
||
225 | $qry = Release::query()->whereNotNull('musicinfo_id')->whereBetween('categories_id', [Category::MUSIC_ROOT, Category::MUSIC_OTHER])->get(); |
||
226 | $total = $qry->count(); |
||
227 | if ($total > 0) { |
||
228 | $bar = $this->output->createProgressBar($total); |
||
229 | $bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this? |
||
230 | $bar->start(); |
||
231 | $conCount = 0; |
||
232 | foreach ($qry as $releases) { |
||
233 | Release::query()->where('id', $releases->id)->update( |
||
234 | [ |
||
235 | 'musicinfo_id' => null, |
||
236 | ]); |
||
237 | $bar->advance(); |
||
238 | } |
||
239 | $bar->finish(); |
||
240 | $this->newLine(); |
||
241 | $this->info(number_format($conCount).' musicinfo_id\'s reset.'); |
||
242 | } else { |
||
243 | $this->info('No releases to reset'); |
||
244 | } |
||
245 | } |
||
246 | |||
247 | private function resetAdult(): void |
||
248 | { |
||
249 | $qry = Release::query()->whereNotNull('xxxinfo_id')->whereBetween('categories_id', [Category::XXX_ROOT, Category::XXX_OTHER])->get(); |
||
250 | $total = $qry->count(); |
||
251 | if ($total > 0) { |
||
252 | $bar = $this->output->createProgressBar($total); |
||
253 | $bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this? |
||
254 | $bar->start(); |
||
255 | $conCount = 0; |
||
256 | foreach ($qry as $releases) { |
||
257 | Release::query()->where('id', $releases->id)->update( |
||
258 | [ |
||
259 | 'xxxinfo_id' => null, |
||
260 | ]); |
||
261 | $bar->advance(); |
||
262 | } |
||
263 | $bar->finish(); |
||
264 | $this->newLine(); |
||
265 | $this->info(number_format($conCount).' xxxinfo_id\'s reset.'); |
||
266 | } else { |
||
267 | $this->info('No releases to reset'); |
||
268 | } |
||
269 | } |
||
270 | |||
271 | private function resetTv(): void |
||
272 | { |
||
273 | $qry = Release::query()->where('videos_id', '!=', 0)->where('tv_episodes_id', '!=', 0)->whereBetween('categories_id', [Category::TV_ROOT, Category::TV_OTHER])->get(); |
||
274 | $total = $qry->count(); |
||
275 | if ($total > 0) { |
||
276 | $bar = $this->output->createProgressBar($total); |
||
277 | $bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this? |
||
278 | $bar->start(); |
||
279 | $conCount = 0; |
||
280 | foreach ($qry as $releases) { |
||
281 | Release::query()->where('id', $releases->id)->update( |
||
282 | [ |
||
283 | 'videos_id' => 0, |
||
284 | 'tv_episodes_id' => 0, |
||
285 | ]); |
||
286 | $bar->advance(); |
||
287 | } |
||
288 | $bar->finish(); |
||
289 | $this->newLine(); |
||
290 | $this->info(number_format($conCount).' video_id\'s reset.'); |
||
291 | } else { |
||
292 | $this->info('No releases to reset'); |
||
293 | } |
||
294 | } |
||
295 | |||
296 | private function resetMisc(): void |
||
297 | { |
||
298 | $qry = Release::query()->whereBetween('categories_id', [Category::OTHER_ROOT, Category::OTHER_HASHED])->get(); |
||
299 | $total = $qry->count(); |
||
300 | if ($total > 0) { |
||
301 | $bar = $this->output->createProgressBar($total); |
||
302 | $bar->setOverwrite(true); // Terminal needs to support ANSI Encoding for this? |
||
303 | $bar->start(); |
||
304 | $conCount = 0; |
||
305 | foreach ($qry as $releases) { |
||
306 | Release::query()->where('id', $releases->id)->update( |
||
307 | [ |
||
308 | 'passwordstatus' => -1, |
||
309 | 'haspreview' => -1, |
||
310 | 'jpgstatus' => 0, |
||
311 | 'videostatus' => 0, |
||
312 | 'audiostatus' => 0, |
||
313 | 'nfostatus' => -1, |
||
314 | ]); |
||
315 | $bar->advance(); |
||
316 | } |
||
317 | $bar->finish(); |
||
318 | $this->newLine(); |
||
319 | $this->info(number_format($conCount).' misc releases reset.'); |
||
320 | } else { |
||
321 | $this->info('No releases to reset'); |
||
322 | } |
||
323 | } |
||
324 | } |
||
325 |