Start of console commands enhancements

This commit is contained in:
Deon George
2020-01-03 08:04:15 +11:00
parent c5fcfdc1d7
commit cf7c9317eb
6 changed files with 131 additions and 127 deletions

View File

@@ -4,42 +4,42 @@ namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Traits\Type;
class CatalogDump extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'catalog:dump {type : Photo | Video } {id : Photo ID}';
use Type;
/**
* The console command description.
*
* @var string
*/
protected $description = 'Scan Photo for metadata';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'catalog:dump {type : Photo | Video } {id : Photo ID}';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$class = 'App\Model\\'.$this->argument('type');
/**
* The console command description.
*
* @var string
*/
protected $description = 'Scan Photo for metadata';
if (! class_exists($class))
abort(500,sprintf('No class [%s]',$this->argument('type')));
$o = $class::findOrFail($this->argument('id'));
if (! is_readable($o->file_path()))
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path()));
exit;
}
$class = $this->getModelType($this->argument('type'));
print_r($o->properties());
}
}
$o = $class::findOrFail($this->argument('id'));
if (! $o->isReadable()) {
$this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path()));
exit;
}
dump($o->properties());
}
}

View File

@@ -4,37 +4,38 @@ namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Traits\Type;
class CatalogScan extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'catalog:scan {type : Photo | Video } {id : Photo ID}';
use Type;
/**
* The console command description.
*
* @var string
*/
protected $description = 'Scan Photo for metadata';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'catalog:scan {type : Photo | Video } {id : Photo ID}';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$class = 'App\Models\\'.$this->argument('type');
/**
* The console command description.
*
* @var string
*/
protected $description = 'Scan Photo for metadata';
if (! class_exists($class))
abort(500,sprintf('No class [%s]',$this->argument('type')));
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$class = $this->getModelType($this->argument('type'));
$o = $class::findOrFail($this->argument('id'));
if (! is_readable($o->file_path())) {
if (! $o->isReadable()) {
$this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path()));
return;
}
@@ -70,10 +71,10 @@ class CatalogScan extends Command
$o->scanned = '1';
if ($o->getDirty()) {
$this->warn(sprintf('Image [%s] metadata changed',$o->file_path()));
$this->warn(sprintf('Image [%s] metadata changed',$o->filename));
dump(['id'=>$o->id,'data'=>$o->getDirty()]);
}
$o->save();
}
}
}
}

View File

@@ -9,7 +9,7 @@ use Illuminate\Support\Facades\Log;
use App\Models\Photo;
use App\Jobs\CatalogScan;
class PhotoScanAll extends Command
class CatalogScanAll extends Command
{
use DispatchesJobs;
@@ -18,15 +18,16 @@ class PhotoScanAll extends Command
*
* @var string
*/
protected $signature = 'photo:scanall '.
'{--scanned : Rescan Scanned Photos}';
protected $signature = 'catalog:scanall'.
' {type : Photo | Video }'.
' {--scanned : Rescan Scanned Photos}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Scan Photos';
protected $description = '(re)Scan Media';
/**
* Create a new command instance.
@@ -45,15 +46,19 @@ class PhotoScanAll extends Command
*/
public function handle()
{
$o = ($this->option('scanned') ? Photo::NotRemove() : Photo::NotScanned());
$class = $this->getModelType($this->argument('type'));
$o->each(function ($item) {
if ($this->option('scanned')) {
$class::update(['scanned'=>NULL]);
}
$class::NotScanned()->each(function ($item) {
if ($item->remove) {
Log::warning(sprintf('Not scanning [%s], marked for removal',$item->id));
return;
}
Log::info(sprintf('%s: Rescanning [%s]',__METHOD__,$item->id));
Log::info(sprintf('%s: Rescanning [%s]',$item->type,$item->id));
$this->dispatch((new CatalogScan($item))->onQueue('scan'));
});

View File

@@ -1,62 +0,0 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Support\Facades\Log;
use App\Models\Video;
use App\Jobs\CatalogScan;
class VideoScanAll extends Command
{
use DispatchesJobs;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'video:scanall'.
' {--scanned : Rescan Scanned Videos}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Scan Videos';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$o = ($this->option('scanned') ? Video::NotRemove() : Video::NotScanned());
$o->each(function ($item) {
if ($item->remove) {
Log::warning(sprintf('Not scanning [%s], marked for removal',$item->id));
return;
}
Log::info(sprintf('%s: Rescanning [%s]',__METHOD__,$item->id));
$this->dispatch((new CatalogScan($item))->onQueue('scan'));
});
Log::info(sprintf('Processed [%s]',$o->count()));
}
}