|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\Category; |
|
6
|
|
|
use App\Models\Release; |
|
7
|
|
|
use App\Models\Video; |
|
8
|
|
|
use Illuminate\Console\Command; |
|
9
|
|
|
|
|
10
|
|
|
class NntmuxResetTvShowPostProcessing extends Command |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* The name and signature of the console command. |
|
14
|
|
|
* |
|
15
|
|
|
* videos_id: ID from videos table (type = 0 TV) whose releases should be reset. |
|
16
|
|
|
* --dry-run: Show how many releases would be reset without making changes. |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $signature = 'nntmux:reset-tv-show {videos_id : ID of the TV show (videos.id)} {--dry-run : Show counts only, do not modify releases}'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The console command description. |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $description = 'Reset postprocessing for all TV releases belonging to a specific videos_id so they can be reprocessed again.'; |
|
24
|
|
|
|
|
25
|
|
|
public function handle(): int |
|
26
|
|
|
{ |
|
27
|
|
|
$videosId = (int) $this->argument('videos_id'); |
|
28
|
|
|
$dryRun = (bool) $this->option('dry-run'); |
|
29
|
|
|
|
|
30
|
|
|
// Validate target show exists and is TV type (0) |
|
31
|
|
|
$video = Video::query()->where('id', $videosId)->where('type', 0)->first(['id', 'title']); |
|
32
|
|
|
if ($video === null) { |
|
33
|
|
|
$this->error("videos_id {$videosId} not found or is not a TV show (type=0)"); |
|
34
|
|
|
|
|
35
|
|
|
return self::FAILURE; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
// Gather releases to reset |
|
39
|
|
|
$baseQuery = Release::query() |
|
40
|
|
|
->select(['id']) |
|
41
|
|
|
->where('videos_id', $videosId) |
|
42
|
|
|
->whereBetween('categories_id', [Category::TV_ROOT, Category::TV_OTHER]); |
|
43
|
|
|
|
|
44
|
|
|
$total = (clone $baseQuery)->count(); |
|
45
|
|
|
if ($total === 0) { |
|
46
|
|
|
$this->info('No releases found for this videos_id in TV categories'); |
|
47
|
|
|
|
|
48
|
|
|
return self::SUCCESS; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if ($dryRun) { |
|
52
|
|
|
$this->line("[Dry Run] Would reset {$total} release(s) for TV show: {$video->title} (videos_id={$videosId})"); |
|
53
|
|
|
|
|
54
|
|
|
return self::SUCCESS; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$this->info("Resetting postprocessing for TV show: {$video->title} (videos_id={$videosId})"); |
|
58
|
|
|
|
|
59
|
|
|
// Progress bar |
|
60
|
|
|
$bar = $this->output->createProgressBar($total); |
|
|
|
|
|
|
61
|
|
|
$bar->setOverwrite(true); |
|
62
|
|
|
$bar->start(); |
|
63
|
|
|
|
|
64
|
|
|
// Chunk through releases to avoid loading all models simultaneously |
|
65
|
|
|
$baseQuery->chunkById(1000, function ($chunk) use ($bar) { |
|
66
|
|
|
foreach ($chunk as $release) { |
|
67
|
|
|
Release::query()->where('id', $release->id)->update([ |
|
68
|
|
|
// Reset association so TV pipeline picks them up again |
|
69
|
|
|
'videos_id' => 0, |
|
70
|
|
|
'tv_episodes_id' => 0, |
|
71
|
|
|
]); |
|
72
|
|
|
$bar->advance(); |
|
73
|
|
|
} |
|
74
|
|
|
}); |
|
75
|
|
|
|
|
76
|
|
|
$bar->finish(); |
|
77
|
|
|
$this->newLine(); |
|
78
|
|
|
$this->info(number_format($total).' release(s) reset. They will be considered for TV postprocessing again.'); |
|
|
|
|
|
|
79
|
|
|
$this->line('You can now run: php artisan postprocess:tv-pipeline <guid-bucket> (or your existing TV processing routines)'); |
|
80
|
|
|
|
|
81
|
|
|
return self::SUCCESS; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|