From 960e0de5c81d5e3f904b76803bf7a906a93dcf34 Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 16 Jan 2025 10:33:45 +1100 Subject: [PATCH] Fix to getDirty() when using MD5Updates Trait on attributes --- app/Classes/LDAP/Attribute.php | 6 ++---- app/Classes/LDAP/Attribute/Binary/JpegPhoto.php | 7 ------- app/Ldap/Entry.php | 12 ++---------- app/Traits/MD5Updates.php | 3 --- 4 files changed, 4 insertions(+), 24 deletions(-) diff --git a/app/Classes/LDAP/Attribute.php b/app/Classes/LDAP/Attribute.php index 272a13f..a6b7133 100644 --- a/app/Classes/LDAP/Attribute.php +++ b/app/Classes/LDAP/Attribute.php @@ -233,10 +233,8 @@ class Attribute implements \Countable, \ArrayAccess */ public function isDirty(): bool { - if ($this->oldValues->count() !== $this->values->count()) - return TRUE; - - return $this->values->diff($this->oldValues)->count() !== 0; + return ($this->oldValues->count() !== $this->values->count()) + || ($this->values->diff($this->oldValues)->count() !== 0); } public function oldValues(array $array): void diff --git a/app/Classes/LDAP/Attribute/Binary/JpegPhoto.php b/app/Classes/LDAP/Attribute/Binary/JpegPhoto.php index b1a68fe..50cf37c 100644 --- a/app/Classes/LDAP/Attribute/Binary/JpegPhoto.php +++ b/app/Classes/LDAP/Attribute/Binary/JpegPhoto.php @@ -14,13 +14,6 @@ final class JpegPhoto extends Binary { use MD5Updates; - public function __construct(string $name,array $values) - { - parent::__construct($name,$values); - - $this->internal = FALSE; - } - public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View { return view('components.attribute.binary.jpegphoto') diff --git a/app/Ldap/Entry.php b/app/Ldap/Entry.php index f8a85b9..b0b6705 100644 --- a/app/Ldap/Entry.php +++ b/app/Ldap/Entry.php @@ -57,16 +57,8 @@ class Entry extends Model { $key = $this->normalizeAttributeKey($key); - if ((! array_key_exists($key,$this->original)) && (! $this->objects->has($key))) - return TRUE; - - $current = $this->attributes[$key]; - $original = $this->objects->get($key)->values; - - if ($current === $original) - return TRUE; - - return ! $this->getObject($key)->isDirty(); + return ((! array_key_exists($key,$this->original)) && (! $this->objects->has($key))) + || (! $this->getObject($key)->isDirty()); } public static function query(bool $noattrs=false): Builder diff --git a/app/Traits/MD5Updates.php b/app/Traits/MD5Updates.php index 85c442d..2e9a413 100644 --- a/app/Traits/MD5Updates.php +++ b/app/Traits/MD5Updates.php @@ -11,9 +11,6 @@ trait MD5Updates { public function isDirty(): bool { - if (! parent::isDirty()) - return TRUE; - foreach ($this->values->diff($this->oldValues) as $key => $value) if (md5(Arr::get($this->oldValues,$key)) !== $value) return TRUE;