2018-01-11 12:59:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
2020-01-02 21:04:15 +00:00
|
|
|
use App\Traits\Type;
|
|
|
|
|
2018-01-11 12:59:53 +00:00
|
|
|
class CatalogScan extends Command
|
|
|
|
{
|
2020-01-02 21:04:15 +00:00
|
|
|
use Type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2020-01-04 13:28:00 +00:00
|
|
|
protected $signature = 'catalog:scan'.
|
|
|
|
' {type : Photo | Video }'.
|
|
|
|
' {id : Photo ID}'.
|
|
|
|
' {--dirty : Show Dirty}';
|
2020-01-02 21:04:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Scan Photo for metadata';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$class = $this->getModelType($this->argument('type'));
|
2019-11-09 02:52:04 +00:00
|
|
|
|
|
|
|
$o = $class::findOrFail($this->argument('id'));
|
2019-11-08 10:43:36 +00:00
|
|
|
|
2020-01-02 21:04:15 +00:00
|
|
|
if (! $o->isReadable()) {
|
2019-11-09 02:52:04 +00:00
|
|
|
$this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path()));
|
2019-11-09 03:58:15 +00:00
|
|
|
return;
|
2019-11-09 02:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$o->setDateCreated();
|
|
|
|
$o->setSubSecTime();
|
|
|
|
$o->setSignature();
|
|
|
|
$o->setMakeModel();
|
|
|
|
$o->setLocation();
|
|
|
|
$o->setHeightWidth();
|
|
|
|
$o->setThumbnail();
|
|
|
|
|
|
|
|
// If this is a duplicate
|
2020-01-04 13:28:00 +00:00
|
|
|
$x = $o->myduplicates()->get();
|
2019-11-09 02:52:04 +00:00
|
|
|
if (count($x)) {
|
|
|
|
foreach ($x as $oo) {
|
|
|
|
// And that photo is not marked as a duplicate
|
|
|
|
if (! $oo->duplicate) {
|
|
|
|
$o->duplicate = '1';
|
2020-01-04 13:28:00 +00:00
|
|
|
$this->warn(sprintf('Image [%s] marked as a duplicate',$o->filename));
|
2019-11-09 02:52:04 +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) {
|
2020-01-04 13:28:00 +00:00
|
|
|
$this->warn(sprintf('Image [%s] marked for deletion',$o->filename));
|
2019-11-09 02:52:04 +00:00
|
|
|
$o->remove = '1';
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2018-01-11 12:59:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-09 02:52:04 +00:00
|
|
|
$o->scanned = '1';
|
2018-01-11 12:59:53 +00:00
|
|
|
|
2019-12-15 12:34:42 +00:00
|
|
|
if ($o->getDirty()) {
|
2020-01-02 21:04:15 +00:00
|
|
|
$this->warn(sprintf('Image [%s] metadata changed',$o->filename));
|
2020-01-04 13:28:00 +00:00
|
|
|
|
|
|
|
if ($this->option('dirty'))
|
|
|
|
dump(['id'=>$o->id,'data'=>$o->getDirty()]);
|
2019-12-15 12:34:42 +00:00
|
|
|
}
|
2018-01-11 12:59:53 +00:00
|
|
|
|
2020-01-04 13:28:00 +00:00
|
|
|
// If the file signature changed, abort the update.
|
2020-01-05 07:02:32 +00:00
|
|
|
if ($o->getOriginal('file_signature') AND $o->wasChanged('file_signature')) {
|
|
|
|
dump(['old'=>$o->getOriginal('file_signature'),'new'=>$o->file_signature]);
|
2020-01-04 13:28:00 +00:00
|
|
|
abort(500,'File Signature Changed?');
|
2020-01-05 07:02:32 +00:00
|
|
|
}
|
2020-01-04 13:28:00 +00:00
|
|
|
|
2019-11-09 02:52:04 +00:00
|
|
|
$o->save();
|
2020-01-02 21:04:15 +00:00
|
|
|
}
|
|
|
|
}
|