NNTmux /
newznab-tmux
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Console\Commands; |
||
| 4 | |||
| 5 | use App\Models\Release; |
||
| 6 | use App\Models\ReleaseFile; |
||
| 7 | use Blacklight\ManticoreSearch; |
||
| 8 | use Blacklight\NZB; |
||
| 9 | use Blacklight\ReleaseImage; |
||
| 10 | use Elasticsearch; |
||
| 11 | use Elasticsearch\Common\Exceptions\Missing404Exception; |
||
| 12 | use Illuminate\Console\Command; |
||
| 13 | use Illuminate\Support\Facades\File; |
||
| 14 | |||
| 15 | class NntmuxRemoveBadReleases extends Command |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * The name and signature of the console command. |
||
| 19 | * |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $signature = 'nntmux:remove-bad'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * The console command description. |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $description = 'Update releases that have passworded files inside archives and remove releases that cannot be PPA\'d properly'; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Create a new command instance. |
||
| 33 | * |
||
| 34 | * @return void |
||
| 35 | */ |
||
| 36 | public function __construct() |
||
| 37 | { |
||
| 38 | parent::__construct(); |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Execute the console command. |
||
| 43 | * |
||
| 44 | * |
||
| 45 | * @throws \Exception |
||
| 46 | */ |
||
| 47 | public function handle(): void |
||
| 48 | { |
||
| 49 | // Select releases with password status -2 and smaller and delete them. Also delete the files from the filesystem. |
||
| 50 | $badReleases = Release::query()->where('passwordstatus', '<=', -2)->get(); |
||
| 51 | foreach ($badReleases as $badRelease) { |
||
| 52 | $nzbPath = (new NZB)->getNZBPath($badRelease->guid); |
||
|
0 ignored issues
–
show
|
|||
| 53 | File::delete($nzbPath); |
||
| 54 | (new ReleaseImage)->delete($badRelease->guid); |
||
| 55 | if (config('nntmux.elasticsearch_enabled') === true) { |
||
| 56 | $params = [ |
||
| 57 | 'index' => 'releases', |
||
| 58 | 'id' => $badRelease->id, |
||
| 59 | ]; |
||
| 60 | |||
| 61 | try { |
||
| 62 | Elasticsearch::delete($params); |
||
| 63 | } catch (Missing404Exception $e) { |
||
| 64 | // we do nothing here just catch the error, we don't care if release is missing from ES, we are deleting it anyway |
||
| 65 | } |
||
| 66 | } else { |
||
| 67 | $identifiers = [ |
||
| 68 | 'i' => $badRelease->id, |
||
| 69 | 'g' => $badRelease->guid, |
||
| 70 | ]; |
||
| 71 | // Delete from sphinx. |
||
| 72 | (new ManticoreSearch)->deleteRelease($identifiers); |
||
| 73 | } |
||
| 74 | $badRelease->delete(); |
||
| 75 | } |
||
| 76 | Release::query()->where('passwordstatus', '=', -2)->delete(); |
||
| 77 | |||
| 78 | $passReleases = ReleaseFile::query()->where('passworded', '=', 1)->groupBy('releases_id')->get(); |
||
| 79 | |||
| 80 | $count = 0; |
||
| 81 | foreach ($passReleases as $passRelease) { |
||
| 82 | Release::whereId($passRelease->releases_id)->update(['passwordstatus' => 1]); |
||
| 83 | $count++; |
||
| 84 | } |
||
| 85 | |||
| 86 | $this->info('Updated '.$count.' bad releases'); |
||
| 87 | } |
||
| 88 | } |
||
| 89 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.