Internal optimisations and additional flags for Photo/Video

This commit is contained in:
Deon George
2020-01-05 00:28:00 +11:00
parent 93364ab53a
commit 1ffc2d994e
19 changed files with 402 additions and 279 deletions

View File

@@ -0,0 +1,77 @@
<?php
namespace App\Console\Commands;
use App\Jobs\PhotoMove;
use App\Jobs\VideoMove;
use Illuminate\Console\Command;
use Illuminate\Foundation\Bus\DispatchesJobs;
use App\Jobs\PhotoDelete;
use App\Models\Photo;
use App\Traits\Type;
class CatalogAutoDelete extends Command
{
use DispatchesJobs,Type;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'catalog:autodelete {type : Photo | Video }';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Auto Delete Catalog Items';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$class = $this->getModelType($this->argument('type'));
$class::where('remove',1)->each(function($o) {
foreach ($o->myduplicates() as $oo) {
if (! $oo->signature OR ! $oo->file_signature)
continue;
if ($oo->signature == $o->signature AND $oo->file_signature == $o->file_signature) {
$this->info(sprintf('Removing: %s (%s)',$o->id,$o->filename));
continue;
// Dispatch Job to move file.
switch (strtolower($this->argument('type'))) {
case 'photo':
$this->dispatch((new PhotoDelete($o))->onQueue('delete'));
break;
case 'video':
$this->dispatch((new VideoDelete($o))->onQueue('delete'));
break;
default:
$this->error('Dont know how to handle: ',$this->argument('type'));
}
}
}
});
}
}

View File

@@ -15,7 +15,10 @@ class CatalogScan extends Command
*
* @var string
*/
protected $signature = 'catalog:scan {type : Photo | Video } {id : Photo ID}';
protected $signature = 'catalog:scan'.
' {type : Photo | Video }'.
' {id : Photo ID}'.
' {--dirty : Show Dirty}';
/**
* The console command description.
@@ -49,17 +52,17 @@ class CatalogScan extends Command
$o->setThumbnail();
// If this is a duplicate
$x = $o->duplicates()->get();
$x = $o->myduplicates()->get();
if (count($x)) {
foreach ($x as $oo) {
// And that photo is not marked as a duplicate
if (! $oo->duplicate) {
$o->duplicate = '1';
$this->warn(sprintf('Image [%s] marked as a duplicate',$o->file_path()));
$this->warn(sprintf('Image [%s] marked as a duplicate',$o->filename));
// If the file signature also matches, we'll mark it for deletion
if ($oo->file_signature AND $o->file_signature == $oo->file_signature) {
$this->warn(sprintf('Image [%s] marked for deletion',$o->file_path()));
$this->warn(sprintf('Image [%s] marked for deletion',$o->filename));
$o->remove = '1';
}
@@ -72,9 +75,15 @@ class CatalogScan extends Command
if ($o->getDirty()) {
$this->warn(sprintf('Image [%s] metadata changed',$o->filename));
dump(['id'=>$o->id,'data'=>$o->getDirty()]);
if ($this->option('dirty'))
dump(['id'=>$o->id,'data'=>$o->getDirty()]);
}
// If the file signature changed, abort the update.
if ($o->getOriginal('file_signature') AND $o->getDirty('file_signature'))
abort(500,'File Signature Changed?');
$o->save();
}
}

View File

@@ -61,6 +61,7 @@ class CatalogScanAll extends Command
}
$this->dispatch((new CatalogScan($item))->onQueue('scan'));
$c++;
});
Log::info(sprintf('Processed [%s]',$c));

View File

@@ -1,63 +0,0 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Foundation\Bus\DispatchesJobs;
use App\Jobs\PhotoDelete;
use App\Models\Photo;
class PhotoAutoDelete extends Command
{
use DispatchesJobs;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'photo:autodelete';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Auto Delete Photos';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
Photo::where('remove',1)->chunk(10,function($chunk) {
foreach ($chunk as $o) {
foreach ($o->list_duplicates(TRUE) as $oo) {
if (! $oo->signature OR ! $oo->file_signature)
continue;
if ($oo->signature == $o->signature AND $oo->file_signature == $o->file_signature) {
if ($oo->remove) {
$this->info(sprintf('Removing: %s (%s)',$oo->id,$oo->filename));
$this->dispatch((new PhotoDelete($o))->onQueue('delete'));
}
}
}
}
});
}
}