From b3f381b743a074757367f17bb39658b52e97d6e1 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 5 Oct 2024 21:10:15 +1000 Subject: [PATCH] Be more liberal with finding duplicates --- app/Models/Abstracted/Catalog.php | 48 +++++++++++++++---------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/app/Models/Abstracted/Catalog.php b/app/Models/Abstracted/Catalog.php index a4fc008..86722f4 100644 --- a/app/Models/Abstracted/Catalog.php +++ b/app/Models/Abstracted/Catalog.php @@ -120,36 +120,34 @@ abstract class Catalog extends Model $query->where(fn($q)=>$q->whereNull('ignore_duplicate') ->orWhere('ignore_duplicate',FALSE)); - // Exclude those marked as remove - $query->where(fn($q)=>$q->where('remove','<>',TRUE)); + $query + ->where(function($q) { + $q->when($this->attributes['signature'], + fn($q)=>$q->where('signature','=',$this->attributes['signature'])) + ->orWhere('file_signature','=',$this->attributes['file_signature']); }) - $query->where(function($q) { - $q->when($this->attributes['signature'],fn($q)=>$q->where('signature','=',$this->attributes['signature'])) - ->orWhere('file_signature','=',$this->attributes['file_signature']) + // Where the signature is the same + ->orWhere(function($q) { + // Or they have the same time taken with the same camera + if ($this->attributes['created'] && $this->software_id) { + $q->where(fn($q)=>$q->where('created','=',$this->attributes['created']) + ->orWhere('created_manual','=',$this->attributes['created'])); - // Where the signature is the same - ->orWhere(function($q) { - // Or they have the same time taken with the same camera - if ($this->attributes['created'] && $this->software_id) { - $q->where(fn($q)=>$q->where('created','=',$this->attributes['created']) - ->orWhere('created_manual','=',$this->attributes['created'])); + if (static::$includeSubSecTime) + $q->where('subsectime','=',Arr::get($this->attributes,'subsectime')); - if (static::$includeSubSecTime) - $q->where('subsectime','=',Arr::get($this->attributes,'subsectime')); + $q->where('software_id','=',$this->attributes['software_id']); - $q->where('software_id','=',$this->attributes['software_id']); + } elseif ($this->attributes['created_manual'] && $this->software_id) { + $q->where(fn($q)=>$q->where('created','=',$this->attributes['created_manual']) + ->orWhere('created_manual','=',$this->attributes['created_manual'])); - } elseif ($this->attributes['created_manual'] && $this->software_id) { - $q->where(fn($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')); - if (static::$includeSubSecTime) - $q->where('subsectime','=',Arr::get($this->attributes,'subsectime')); - - $q->where('software_id','=',$this->attributes['software_id']); - } - }); - }); + $q->where('software_id','=',$this->attributes['software_id']); + } + }); return $query; } @@ -413,7 +411,7 @@ abstract class Catalog extends Model // Test if the target dir is writable // @todo The target dir may not exist yet, so we should check that a parent exists and is writable. - $this->move_reason = 'Target parent dir doesnt is not writable'; + $this->move_reason = 'Target parent dir is not writable'; if (! $this->isParentWritable(dirname($this->file_name_rel(FALSE)))) return FALSE;