Start of console commands enhancements
This commit is contained in:
parent
c5fcfdc1d7
commit
cf7c9317eb
@ -4,8 +4,12 @@ namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
use App\Traits\Type;
|
||||
|
||||
class CatalogDump extends Command
|
||||
{
|
||||
use Type;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
@ -27,19 +31,15 @@ class CatalogDump extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$class = 'App\Model\\'.$this->argument('type');
|
||||
|
||||
if (! class_exists($class))
|
||||
abort(500,sprintf('No class [%s]',$this->argument('type')));
|
||||
$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()));
|
||||
exit;
|
||||
}
|
||||
|
||||
print_r($o->properties());
|
||||
dump($o->properties());
|
||||
}
|
||||
}
|
@ -4,8 +4,12 @@ namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
use App\Traits\Type;
|
||||
|
||||
class CatalogScan extends Command
|
||||
{
|
||||
use Type;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
@ -27,14 +31,11 @@ class CatalogScan extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$class = 'App\Models\\'.$this->argument('type');
|
||||
|
||||
if (! class_exists($class))
|
||||
abort(500,sprintf('No class [%s]',$this->argument('type')));
|
||||
$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,7 +71,7 @@ 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()]);
|
||||
}
|
||||
|
||||
|
@ -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'));
|
||||
});
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
@ -180,8 +180,25 @@ abstract class Catalog extends Model
|
||||
return $format ? date('d-m-Y H:i:s',$t) : $t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return what the filename should be.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function file_name(bool $short=TRUE): string
|
||||
{
|
||||
// If the date created is not set, the file name will be based on the ID of the file.
|
||||
$file = sprintf('%s.%s',((is_null($this->date_created) OR ! $this->date_created)
|
||||
? sprintf('UNKNOWN/%07s',$this->file_path_id())
|
||||
: sprintf('%s_%03s',$this->date_created->format('Y/m/d-His'),$this->subsectime).
|
||||
((! static::$includeSubSecTime OR $this->subsectime) ? '' : sprintf('-%05s',$this->id))),$this->type());
|
||||
|
||||
return (($short OR preg_match('/^\//',$file)) ? '' : config('photo.dir').DIRECTORY_SEPARATOR).$file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the new name for the image
|
||||
* @deprecated
|
||||
*/
|
||||
public function file_path($short=FALSE,$new=FALSE)
|
||||
{
|
||||
@ -304,6 +321,16 @@ abstract class Catalog extends Model
|
||||
return ($this->gps_lat AND $this->gps_lon) ? sprintf('%s/%s',$this->gps_lat,$this->gps_lon) : 'UNKNOWN';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if this source file is readable.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isReadable(): bool
|
||||
{
|
||||
return is_readable($this->file_path());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an HTML checkbox
|
||||
*/
|
||||
@ -371,6 +398,17 @@ abstract class Catalog extends Model
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag to indicate if a file should be moved.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function mustMove(): bool
|
||||
{
|
||||
dump(['f'=>$this->filename,'fn'=>$this->file_name(),'test'=>($this->filename == $this->file_name())]);
|
||||
return $this->filename !== $this->file_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of the previous record
|
||||
*/
|
||||
|
22
app/Traits/Type.php
Normal file
22
app/Traits/Type.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
/**
|
||||
* Trait Files
|
||||
* This will return a valid Model Object.
|
||||
*
|
||||
* @package App\Traits
|
||||
*/
|
||||
trait Type
|
||||
{
|
||||
private function getModelType(string $type): string
|
||||
{
|
||||
$class = 'App\Models\\'.$type;
|
||||
|
||||
if (! class_exists($class))
|
||||
abort(500,sprintf('No class [%s]',$type));
|
||||
|
||||
return $class;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user