From 270f63144b3a716963ca7df3c6fbd3c69aa70166 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 5 Jan 2020 18:02:32 +1100 Subject: [PATCH] Added handling of created_manual, revert some file_path() --- app/Console/Commands/CatalogScan.php | 4 +++- app/Http/Controllers/VideoController.php | 2 +- app/Models/Abstracted/Catalog.php | 25 +++++++++++++++++++----- app/Models/Video.php | 6 ++++++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/Console/Commands/CatalogScan.php b/app/Console/Commands/CatalogScan.php index b88a102..6af91c0 100644 --- a/app/Console/Commands/CatalogScan.php +++ b/app/Console/Commands/CatalogScan.php @@ -81,8 +81,10 @@ class CatalogScan extends Command } // If the file signature changed, abort the update. - if ($o->getOriginal('file_signature') AND $o->getDirty('file_signature')) + 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(); } diff --git a/app/Http/Controllers/VideoController.php b/app/Http/Controllers/VideoController.php index 5a9f386..c56a663 100644 --- a/app/Http/Controllers/VideoController.php +++ b/app/Http/Controllers/VideoController.php @@ -65,6 +65,6 @@ class VideoController extends Controller public function view(Video $o) { if ($o->isReadable()) - (new VideoStream($o->filename))->start(); + (new VideoStream($o->file_path()))->start(); } } \ No newline at end of file diff --git a/app/Models/Abstracted/Catalog.php b/app/Models/Abstracted/Catalog.php index e8040f5..c28b7dc 100644 --- a/app/Models/Abstracted/Catalog.php +++ b/app/Models/Abstracted/Catalog.php @@ -97,7 +97,21 @@ abstract class Catalog extends Model ->orWhere(function($q) { // Or they have the same time taken with the same camera if ($this->attributes['created'] AND $this->software_id) { - $q->where('created','=',$this->attributes['created'] ?: NULL); + $q->where(function ($q) { + $q->where('created','=',$this->attributes['created']) + ->orWhere('created_manual','=',$this->attributes['created']); + }); + + if (static::$includeSubSecTime) + $q->where('subsectime','=',Arr::get($this->attributes,'subsectime')); + + $q->where('software_id','=',$this->attributes['software_id']); + + } elseif ($this->attributes['created_manual'] AND $this->software_id) { + $q->where(function ($q) { + $q->where('created','=',$this->attributes['created_manual']) + ->orWhere('created_manual','=',$this->attributes['created_manual']); + }); if (static::$includeSubSecTime) $q->where('subsectime','=',Arr::get($this->attributes,'subsectime')); @@ -272,6 +286,11 @@ abstract class Catalog extends Model return (! is_readable($this->file_path())) ? NULL : filesize($this->file_path()); } + public function getCreatedAttribute(): Carbon + { + return $this->created_manual ?: $this->asDateTime($this->attributes['created']); + } + /** * Return item dimensions */ @@ -314,10 +333,6 @@ abstract class Catalog extends Model 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; - } - /** * @deprecated */ diff --git a/app/Models/Video.php b/app/Models/Video.php index 3131f85..23a8e36 100644 --- a/app/Models/Video.php +++ b/app/Models/Video.php @@ -8,6 +8,7 @@ class Video extends Abstracted\Catalog { // ID3 Object private $_o = NULL; + protected $dates = ['created','created_manual']; public function getIDLinkAttribute() { @@ -124,6 +125,11 @@ class Video extends Abstracted\Catalog return isset($data[$key]) ? $data[$key] : NULL; } + public function setDateCreated() + { + $this->created = strtotime($this->property('creationdate')); + } + public function setLocation() { $this->gps_lat = $this->property('gps_lat');