composer require ldc/web-status-checker-laravel remove Old static status checker Fix ImportMedia WIP commands OK many fixes Fix and try to optimize folder component Fix front icons + actions based on icons Favico front fix alert Fix Media upload on depot fix folder component buttons Full front fix with perf due tu vuejs Download medias Navigate within medias superfix Move media + loader isLocked boolean and remove media fix Folder scroll fix arcadia link color red Fix panier show external Tons of fixes back as front REwrited all
91 lines
2.7 KiB
PHP
91 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Media;
|
|
use App\Models\Sujet;
|
|
use Illuminate\Console\Command;
|
|
|
|
class DeleteMediaArchive extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'media:deletearchive';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
* @phpcs:disable Generic.Files.LineLength.TooLong
|
|
*/
|
|
protected $description = 'Suppression définitive de tous les médias (et leurs fichiers) qui ont été supprimés (en soft delete)';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
//phpcs:ignore Generic.Files.LineLength.TooLong
|
|
$this->info('Vous allez supprimer définitivement tous les médias (et leurs fichiers) qui ont été supprimés (en soft delete).');
|
|
|
|
if (!$this->confirm('Etes-vous sûr de vouloir lancer ce traitement ?')) {
|
|
return 0;
|
|
}
|
|
|
|
/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Sujet> */
|
|
$subjects = Sujet::where('sujet_dam', true)->get();
|
|
|
|
$this->newLine();
|
|
$this->line('Liste des sujets disponibles');
|
|
$this->line('----------------------------');
|
|
$this->line('[0] Tous les sujets');
|
|
foreach ($subjects as $subject) {
|
|
$this->line("[{$subject->codeSujet}] {$subject->libelle}");
|
|
}
|
|
|
|
$sujetId = $this->askWithCompletion(
|
|
'Pour quel sujet de média souhaitez vous executer le traitement ?',
|
|
$subjects->pluck('codeSujet')->toArray(),
|
|
0
|
|
);
|
|
|
|
$this->newLine();
|
|
|
|
if ($sujetId != 0 and !$subjects->pluck('codeSujet')->contains(\intval($sujetId))) {
|
|
$this->error('Id de sujet incorrect');
|
|
return -1;
|
|
}
|
|
|
|
$sujetId = intval($sujetId);
|
|
|
|
$mediaCollection = Media::onlyTrashed()->with('sujet.formats');
|
|
if ($sujetId !== 0) {
|
|
$mediaCollection->where('sujet_id', $sujetId);
|
|
}
|
|
/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Media> */
|
|
$mediaCollection = $mediaCollection->get();
|
|
|
|
if (!$mediaCollection->count()) {
|
|
$this->error('Aucun média a supprimer');
|
|
return -1;
|
|
}
|
|
|
|
$this->info($mediaCollection->count() . ' média(s) trouvé(s) - Début du traitement');
|
|
$bar = $this->output->createProgressBar($mediaCollection->count());
|
|
$bar->start();
|
|
|
|
foreach ($mediaCollection as $media) {
|
|
$media->prune();
|
|
$bar->advance();
|
|
}
|
|
|
|
$bar->finish();
|
|
$this->newLine();
|
|
$this->info('Fin du traitement');
|
|
}
|
|
}
|