photo/app/Console/Commands/CatalogScan.php

91 lines
2.0 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Traits\Type;
class CatalogScan extends Command
{
use Type;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'catalog:scan'.
' {type : Photo | Video }'.
' {id : Photo ID}'.
' {--dirty : Show Dirty}';
/**
* 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'));
$o = $class::findOrFail($this->argument('id'));
if (! $o->isReadable()) {
$this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path()));
return;
}
$o->setDateCreated();
$o->setSubSecTime();
$o->setSignature();
$o->setMakeModel();
$o->setLocation();
$o->setHeightWidth();
$o->setThumbnail();
// If this is a duplicate
$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->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->filename));
$o->remove = '1';
}
break;
}
}
}
$o->scanned = '1';
if ($o->getDirty()) {
$this->warn(sprintf('Image [%s] metadata changed',$o->filename));
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->wasChanged('file_signature')) {
dump(['old'=>$o->getOriginal('file_signature'),'new'=>$o->file_signature]);
abort(500,'File Signature Changed?');
}
$o->save();
}
}