2018-01-11 12:59:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
|
|
|
|
|
|
class CatalogScan extends Command
|
|
|
|
{
|
|
|
|
// Our photo object
|
|
|
|
private $o = NULL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'catalog:scan {type : Photo | Video } {id : Photo ID}';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Scan Photo for metadata';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$class = 'App\Model\\'.$this->argument('type');
|
|
|
|
|
|
|
|
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()))
|
|
|
|
{
|
|
|
|
$this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path()));
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$o->setDateCreated();
|
|
|
|
$o->setSubSecTime();
|
|
|
|
$o->setSignature();
|
|
|
|
$o->setMakeModel();
|
|
|
|
$o->setLocation();
|
|
|
|
$o->setHeightWidth();
|
|
|
|
$o->setThumbnail();
|
|
|
|
|
|
|
|
// If this is a duplicate
|
|
|
|
$x = $class::whereIN('id',$o->list_duplicate())->get();
|
|
|
|
if (count($x)) {
|
|
|
|
$break = FALSE;
|
|
|
|
|
|
|
|
foreach ($x as $oo) {
|
2019-11-08 10:43:36 +00:00
|
|
|
// And that photo is not marked as a duplicate
|
|
|
|
if (! $oo->duplicate)
|
2018-01-11 12:59:53 +00:00
|
|
|
{
|
2019-11-08 10:43:36 +00:00
|
|
|
$o->duplicate = '1';
|
|
|
|
$this->warn(sprintf('Image [%s] marked as a duplicate',$o->file_path()));
|
2018-01-11 12:59:53 +00:00
|
|
|
|
2019-11-08 10:43:36 +00:00
|
|
|
// 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()));
|
|
|
|
$o->remove = '1';
|
2018-01-11 12:59:53 +00:00
|
|
|
}
|
2019-11-08 10:43:36 +00:00
|
|
|
|
|
|
|
break;
|
2018-01-11 12:59:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$o->scanned = '1';
|
|
|
|
|
|
|
|
if ($o->getDirty())
|
|
|
|
$this->warn(sprintf('Image [%s] metadata changed',$o->file_path()));
|
|
|
|
|
|
|
|
$o->save();
|
|
|
|
}
|
|
|
|
}
|