73 lines
1.5 KiB
PHP
73 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
|
|
|
use App\Jobs\{PhotoDelete,VideoDelete};
|
|
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()->get() 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));
|
|
|
|
// 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'));
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
} |