Internal optimisations and additional flags for Photo/Video
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Models\Abstracted;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
@@ -12,6 +13,7 @@ use App\Models\{Person,Software,Tag};
|
||||
abstract class Catalog extends Model
|
||||
{
|
||||
protected static $includeSubSecTime = FALSE;
|
||||
protected $dates = ['created'];
|
||||
|
||||
/**
|
||||
* People in Multimedia Object
|
||||
@@ -44,18 +46,39 @@ abstract class Catalog extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Search Database for duplicates of this object
|
||||
* Find records marked as duplicate
|
||||
*
|
||||
* @param $query
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopeDuplicates($query) {
|
||||
$query->notRemove()
|
||||
->where('duplicate',TRUE)
|
||||
->where(function($q) {
|
||||
$q->Where('ignore_duplicate','<>',TRUE)
|
||||
->orWhereNull('ignore_duplicate');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Search Database for duplicates of this object
|
||||
*
|
||||
* @param $query
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopeMyDuplicates($query) {
|
||||
if (! $this->exists)
|
||||
return $query;
|
||||
|
||||
// Exclude this record
|
||||
$query->where('id','<>',$this->attributes['id']);
|
||||
|
||||
// Skip ignore dups
|
||||
$query->where(function($q) {
|
||||
$q->whereNull('ignore_duplicate')
|
||||
->orWhere('ignore_duplicate','=',0);
|
||||
});
|
||||
|
||||
// Exclude those marked as remove
|
||||
$query->where(function ($q) {
|
||||
$q->where('remove','<>',TRUE)
|
||||
@@ -69,11 +92,11 @@ abstract class Catalog extends Model
|
||||
// Where the signature is the same
|
||||
->orWhere(function($q) {
|
||||
// Or they have the same time taken with the same camera
|
||||
if ($this->attributes['date_created'] AND $this->software_id) {
|
||||
$q->where('date_created','=',$this->attributes['date_created'] ?: NULL);
|
||||
if ($this->attributes['created'] AND $this->software_id) {
|
||||
$q->where('created','=',$this->attributes['created'] ?: NULL);
|
||||
|
||||
if (static::$includeSubSecTime)
|
||||
$q->where('subsectime','=',$this->attributes['subsectime'] ?: NULL);
|
||||
$q->where('subsectime','=',Arr::get($this->attributes,'subsectime'));
|
||||
|
||||
$q->where('software_id','=',$this->attributes['software_id']);
|
||||
}
|
||||
@@ -124,9 +147,7 @@ abstract class Catalog extends Model
|
||||
}
|
||||
|
||||
// Children objects must inherit this methods
|
||||
abstract public function setDateCreated();
|
||||
abstract public function setLocation();
|
||||
abstract public function setSignature();
|
||||
abstract public function setSubSecTime();
|
||||
abstract public function setThumbnail();
|
||||
abstract public function getHtmlImageURL();
|
||||
@@ -136,9 +157,16 @@ abstract class Catalog extends Model
|
||||
*/
|
||||
public function date_taken(): string
|
||||
{
|
||||
return $this->date_created ? $this->date_created->format('Y-m-d H:i:s') : 'UNKNOWN';
|
||||
return $this->created
|
||||
? $this->created->format('Y-m-d H:i:s').(static::$includeSubSecTime ? sprintf('.%03d',$this->subsectime) : '')
|
||||
: 'UNKNOWN';
|
||||
}
|
||||
|
||||
/**
|
||||
* What device was the multimedia created on
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function device(): string
|
||||
{
|
||||
$result = '';
|
||||
@@ -169,11 +197,13 @@ abstract class Catalog extends Model
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case 'a': $t = fileatime($this->file_path());
|
||||
case 'a': $t = fileatime($this->filename);
|
||||
break;
|
||||
case 'c': $t = filectime($this->file_path());
|
||||
|
||||
case 'c': $t = filectime($this->filename);
|
||||
break;
|
||||
case 'm': $t = filemtime($this->file_path());
|
||||
|
||||
case 'm': $t = filemtime($this->filename);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -188,12 +218,15 @@ abstract class Catalog extends Model
|
||||
public function file_name(bool $short=TRUE): string
|
||||
{
|
||||
// If the date created is not set, the file name will be based on the ID of the file.
|
||||
$file = sprintf('%s.%s',((is_null($this->date_created) OR ! $this->date_created)
|
||||
$file = sprintf('%s.%s',(is_null($this->created)
|
||||
? sprintf('UNKNOWN/%07s',$this->file_path_id())
|
||||
: sprintf('%s_%03s',$this->date_created->format('Y/m/d-His'),$this->subsectime).
|
||||
((! static::$includeSubSecTime OR $this->subsectime) ? '' : sprintf('-%05s',$this->id))),$this->type());
|
||||
: $this->created->format('Y/m/d-His').((! is_null($this->subsectime)) ? sprintf('.%03d',$this->subsectime) : '' ).
|
||||
((! static::$includeSubSecTime OR ! is_null($this->subsectime)) ? '' : sprintf('-%05s',$this->id)).
|
||||
($this->ignore_duplicate ? sprintf('-%06d',$this->id) : '')
|
||||
),$this->type()
|
||||
);
|
||||
|
||||
return (($short OR preg_match('/^\//',$file)) ? '' : config('photo.dir').DIRECTORY_SEPARATOR).$file;
|
||||
return (($short OR preg_match('/^\//',$file)) ? '' : config($this->type.'.dir').DIRECTORY_SEPARATOR).$file;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,11 +238,9 @@ abstract class Catalog extends Model
|
||||
$file = $this->filename;
|
||||
|
||||
if ($new)
|
||||
$file = sprintf('%s.%s',((is_null($this->date_created) OR ! $this->date_created)
|
||||
? sprintf('UNKNOWN/%07s',$this->file_path_id())
|
||||
: $this->date_created->format('Y/m/d-His')),$this->type());
|
||||
$file = $this->file_name(FALSE);
|
||||
|
||||
return (($short OR preg_match('/^\//',$file)) ? '' : config('video.dir').DIRECTORY_SEPARATOR).$file;
|
||||
return (($short OR preg_match('/^\//',$file)) ? '' : config($this->type.'.dir').DIRECTORY_SEPARATOR).$file;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,6 +302,14 @@ abstract class Catalog extends Model
|
||||
return $this->HTMLCheckbox('flag',$this->id,$this->flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return HTML Checkbox for ignore
|
||||
*/
|
||||
public function getIgnoreCheckboxAttribute()
|
||||
{
|
||||
return $this->HTMLCheckbox('ignore_duplicate',$this->id,$this->ignore_duplicate);
|
||||
}
|
||||
|
||||
public function getDateCreatedAttribute() {
|
||||
return $this->attributes['date_created'] ? Carbon::createFromTimestamp($this->attributes['date_created']) : NULL;
|
||||
}
|
||||
@@ -328,7 +367,7 @@ abstract class Catalog extends Model
|
||||
*/
|
||||
public function isReadable(): bool
|
||||
{
|
||||
return is_readable($this->file_path());
|
||||
return is_readable($this->filename);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -344,7 +383,7 @@ abstract class Catalog extends Model
|
||||
*/
|
||||
protected function HTMLLinkAttribute($id,$url)
|
||||
{
|
||||
return sprintf('<a href="%s" target="%s">%s</a>',url($url.$id),$id,$id);
|
||||
return sprintf('<a href="%s" target="%s">%s</a>',url($url,$id),$id,$id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -398,17 +437,6 @@ abstract class Catalog extends Model
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag to indicate if a file should be moved.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function mustMove(): bool
|
||||
{
|
||||
dump(['f'=>$this->filename,'fn'=>$this->file_name(),'test'=>($this->filename == $this->file_name())]);
|
||||
return $this->filename !== $this->file_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of the previous record
|
||||
*/
|
||||
@@ -441,6 +469,11 @@ abstract class Catalog extends Model
|
||||
->first();
|
||||
}
|
||||
|
||||
public function setDateCreated()
|
||||
{
|
||||
$this->created = $this->property('creationdate');
|
||||
}
|
||||
|
||||
public function setHeightWidth()
|
||||
{
|
||||
$this->height = $this->property('height');
|
||||
@@ -448,6 +481,13 @@ abstract class Catalog extends Model
|
||||
$this->orientation = $this->property('orientation');
|
||||
}
|
||||
|
||||
public function setSignature()
|
||||
{
|
||||
$this->signature = $this->property('signature');
|
||||
|
||||
$this->file_signature = md5_file($this->filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the media signature
|
||||
*/
|
||||
@@ -484,7 +524,7 @@ abstract class Catalog extends Model
|
||||
*/
|
||||
public function shouldMove(): bool
|
||||
{
|
||||
return ($this->filename != $this->file_path(TRUE,TRUE));
|
||||
return $this->filename !== $this->file_name();
|
||||
}
|
||||
|
||||
protected function TextTrueFalse($value): string
|
||||
@@ -498,7 +538,7 @@ abstract class Catalog extends Model
|
||||
* @param bool $includeme
|
||||
* @return mixed
|
||||
*/
|
||||
public function list_duplicate($includeme=FALSE)
|
||||
private function list_duplicate($includeme=FALSE)
|
||||
{
|
||||
return $this->list_duplicates($includeme)->pluck('id');
|
||||
}
|
||||
@@ -507,7 +547,7 @@ abstract class Catalog extends Model
|
||||
* Find duplicate images based on some attributes of the current image
|
||||
* @deprecate Use static::duplicates()
|
||||
*/
|
||||
public function list_duplicates($includeme=FALSE)
|
||||
private function list_duplicates($includeme=FALSE)
|
||||
{
|
||||
$o = static::select();
|
||||
|
||||
|
Reference in New Issue
Block a user