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 RegenerateThumbnails extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'media:regenerate';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Regénération de toutes les vignettes des médias';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$this->info('Vous allez regénérer toutes les miniatures des médias.');
|
|
|
|
/** @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
|
|
);
|
|
|
|
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 n\'a été trouvé');
|
|
return -1;
|
|
}
|
|
|
|
$this->info($mediaCollection->count() . ' média(s) trouvé(s) - Début du traitement');
|
|
$bar = $this->output->createProgressBar($mediaCollection->count());
|
|
$bar->start();
|
|
|
|
/** @var \App\Models\Media $media */
|
|
foreach ($mediaCollection as $media) {
|
|
try {
|
|
// ---- Creation des vignettes de base
|
|
$media->createThumbnail();
|
|
// ---- Creation des vignettes en lien avec le sujet du média
|
|
$media->createSubjectThumbnails();
|
|
} catch (\ImagickException | \RuntimeException $e) {
|
|
report($e);
|
|
}
|
|
$bar->advance();
|
|
}
|
|
|
|
$bar->finish();
|
|
$this->newLine();
|
|
$this->info('Fin du traitement');
|
|
}
|
|
}
|