Fix to getDirty() when using MD5Updates Trait on attributes

This commit is contained in:
Deon George 2025-01-16 10:33:45 +11:00
parent 6e06caa83b
commit 960e0de5c8
4 changed files with 4 additions and 24 deletions

View File

@ -233,10 +233,8 @@ class Attribute implements \Countable, \ArrayAccess
*/ */
public function isDirty(): bool public function isDirty(): bool
{ {
if ($this->oldValues->count() !== $this->values->count()) return ($this->oldValues->count() !== $this->values->count())
return TRUE; || ($this->values->diff($this->oldValues)->count() !== 0);
return $this->values->diff($this->oldValues)->count() !== 0;
} }
public function oldValues(array $array): void public function oldValues(array $array): void

View File

@ -14,13 +14,6 @@ final class JpegPhoto extends Binary
{ {
use MD5Updates; 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 public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View
{ {
return view('components.attribute.binary.jpegphoto') return view('components.attribute.binary.jpegphoto')

View File

@ -57,16 +57,8 @@ class Entry extends Model
{ {
$key = $this->normalizeAttributeKey($key); $key = $this->normalizeAttributeKey($key);
if ((! array_key_exists($key,$this->original)) && (! $this->objects->has($key))) return ((! array_key_exists($key,$this->original)) && (! $this->objects->has($key)))
return TRUE; || (! $this->getObject($key)->isDirty());
$current = $this->attributes[$key];
$original = $this->objects->get($key)->values;
if ($current === $original)
return TRUE;
return ! $this->getObject($key)->isDirty();
} }
public static function query(bool $noattrs=false): Builder public static function query(bool $noattrs=false): Builder

View File

@ -11,9 +11,6 @@ trait MD5Updates
{ {
public function isDirty(): bool public function isDirty(): bool
{ {
if (! parent::isDirty())
return TRUE;
foreach ($this->values->diff($this->oldValues) as $key => $value) foreach ($this->values->diff($this->oldValues) as $key => $value)
if (md5(Arr::get($this->oldValues,$key)) !== $value) if (md5(Arr::get($this->oldValues,$key)) !== $value)
return TRUE; return TRUE;