From bd5fb5d46fd7e0661a6f43d275ef78f49c83c619 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 9 Nov 2019 14:58:15 +1100 Subject: [PATCH] Updated ScanAll to enable scanning all photos --- app/Console/Commands/CatalogScan.php | 2 +- app/Console/Commands/PhotoScanAll.php | 86 ++++++++++++++------------- app/Models/Photo.php | 1 + 3 files changed, 47 insertions(+), 42 deletions(-) diff --git a/app/Console/Commands/CatalogScan.php b/app/Console/Commands/CatalogScan.php index a4f8a20..072a4a8 100644 --- a/app/Console/Commands/CatalogScan.php +++ b/app/Console/Commands/CatalogScan.php @@ -39,7 +39,7 @@ class CatalogScan extends Command if (! is_readable($o->file_path())) { $this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path())); - exit; + return; } $o->setDateCreated(); diff --git a/app/Console/Commands/PhotoScanAll.php b/app/Console/Commands/PhotoScanAll.php index 12d911d..eb3ce23 100644 --- a/app/Console/Commands/PhotoScanAll.php +++ b/app/Console/Commands/PhotoScanAll.php @@ -4,55 +4,59 @@ namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Foundation\Bus\DispatchesJobs; -use Log; -use App\Model\Photo; +use Illuminate\Support\Facades\Log; + +use App\Models\Photo; use App\Jobs\CatalogScan; class PhotoScanAll extends Command { use DispatchesJobs; - /** - * The name and signature of the console command. - * - * @var string - */ - protected $signature = 'photo:scanall'; + /** + * The name and signature of the console command. + * + * @var string + */ + protected $signature = 'photo:scanall '. + '{--scanned : Rescan Scanned Photos}'; - /** - * The console command description. - * - * @var string - */ - protected $description = 'Command description'; + /** + * The console command description. + * + * @var string + */ + protected $description = 'Rescan Photos'; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } + /** + * Create a new command instance. + * + * @return void + */ + public function __construct() + { + parent::__construct(); + } - /** - * Execute the console command. - * - * @return mixed - */ - public function handle() - { - Photo::NotScanned()->chunk(200,function ($data) { - foreach ($data as $o) - { - if ($o->remove) { - Log::warning(sprintf('Not scanning [%s], marked for removal',$o->id)); - continue; + /** + * Execute the console command. + * + * @return mixed + */ + public function handle() + { + $o = ($this->option('scanned') ? Photo::NotRemove() : Photo::NotScanned()); + + $o->each(function ($item) { + if ($item->remove) { + Log::warning(sprintf('Not scanning [%s], marked for removal',$item->id)); + return; } - $this->dispatch((new CatalogScan($o))->onQueue('scan')); - } - }); - } -} + Log::info(sprintf('%s: Rescanning [%s]',__METHOD__,$item->id)); + $this->dispatch((new CatalogScan($item))->onQueue('scan')); + }); + + Log::info(sprintf('Processed [%s]',$o->count())); + } +} \ No newline at end of file diff --git a/app/Models/Photo.php b/app/Models/Photo.php index 2aecf30..5c9453a 100644 --- a/app/Models/Photo.php +++ b/app/Models/Photo.php @@ -192,6 +192,7 @@ class Photo extends Abstracted\Catalog $this->thumbnail = exif_thumbnail($this->file_path()); } catch (\Exception $e) { // @todo Couldnt get the thumbnail, so we should create one. + Log::info(sprintf('Unable to create thumbnail for %s (%s)',$this->id,$e->getMessage())); } }