2020-01-04 13:28:00 +00:00
|
|
|
<?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) {
|
2020-01-05 10:55:26 +00:00
|
|
|
foreach ($o->myduplicates()->get() as $oo) {
|
2020-01-04 13:28:00 +00:00
|
|
|
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));
|
|
|
|
|
|
|
|
// 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'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|