From ca136225cb723310effa874425cd07668776e35a Mon Sep 17 00:00:00 2001 From: Yurii Date: Wed, 4 Mar 2026 15:37:04 +0200 Subject: [PATCH] ref --- application/Espo/ORM/BaseEntity.php | 81 ++------------------- application/Espo/ORM/Util.php | 108 ++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 76 deletions(-) create mode 100644 application/Espo/ORM/Util.php diff --git a/application/Espo/ORM/BaseEntity.php b/application/Espo/ORM/BaseEntity.php index 991b58adeb..fbe8974d26 100644 --- a/application/Espo/ORM/BaseEntity.php +++ b/application/Espo/ORM/BaseEntity.php @@ -809,11 +809,11 @@ class BaseEntity implements Entity /** @var string $type */ $type = $this->getAttributeType($name); - return !self::areValuesEqual( - $type, - $this->get($name), - $this->getFetched($name), - $this->getAttributeParam($name, 'isUnordered') ?? false + return !Util::areValuesEqual( + type: $type, + v1: $this->get($name), + v2: $this->getFetched($name), + isUnordered: $this->getAttributeParam($name, 'isUnordered') ?? false, ); } @@ -825,77 +825,6 @@ class BaseEntity implements Entity return $this->writtenMap[$name] ?? false; } - /** - * @param mixed $v1 - * @param mixed $v2 - */ - protected static function areValuesEqual(string $type, $v1, $v2, bool $isUnordered = false): bool - { - if ($type === self::JSON_ARRAY) { - if (is_array($v1) && is_array($v2)) { - if ($isUnordered) { - sort($v1); - sort($v2); - } - - if ($v1 != $v2) { - return false; - } - - foreach ($v1 as $i => $itemValue) { - if (is_object($itemValue) && is_object($v2[$i])) { - if (!self::areValuesEqual(self::JSON_OBJECT, $itemValue, $v2[$i])) { - return false; - } - - continue; - } - - if ($itemValue !== $v2[$i]) { - return false; - } - } - - return true; - } - } else if ($type === self::JSON_OBJECT) { - if (is_object($v1) && is_object($v2)) { - if ($v1 != $v2) { - return false; - } - - $a1 = get_object_vars($v1); - $a2 = get_object_vars($v2); - - foreach (get_object_vars($v1) as $key => $itemValue) { - if (is_object($a1[$key]) && is_object($a2[$key])) { - if (!self::areValuesEqual(self::JSON_OBJECT, $a1[$key], $a2[$key])) { - return false; - } - - continue; - } - - if (is_array($a1[$key]) && is_array($a2[$key])) { - if (!self::areValuesEqual(self::JSON_ARRAY, $a1[$key], $a2[$key])) { - return false; - } - - continue; - } - - if ($a1[$key] !== $a2[$key]) { - return false; - } - } - - return true; - } - } - - return $v1 === $v2; - } - /** * Set a fetched value for a specific attribute. */ diff --git a/application/Espo/ORM/Util.php b/application/Espo/ORM/Util.php new file mode 100644 index 0000000000..283d7354c5 --- /dev/null +++ b/application/Espo/ORM/Util.php @@ -0,0 +1,108 @@ +. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU Affero General Public License version 3. + * + * In accordance with Section 7(b) of the GNU Affero General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. + ************************************************************************/ + +namespace Espo\ORM; + +use Espo\ORM\Type\AttributeType; + +/** + * @internal + */ +class Util +{ + /** + * @internal + */ + public static function areValuesEqual(string $type, mixed $v1, mixed $v2, bool $isUnordered = false): bool + { + if ($type === AttributeType::JSON_ARRAY) { + if (is_array($v1) && is_array($v2)) { + if ($isUnordered) { + sort($v1); + sort($v2); + } + + if ($v1 != $v2) { + return false; + } + + foreach ($v1 as $i => $itemValue) { + if (is_object($itemValue) && is_object($v2[$i])) { + if (!self::areValuesEqual(AttributeType::JSON_OBJECT, $itemValue, $v2[$i])) { + return false; + } + + continue; + } + + if ($itemValue !== $v2[$i]) { + return false; + } + } + + return true; + } + } else if ($type === AttributeType::JSON_OBJECT) { + if (is_object($v1) && is_object($v2)) { + if ($v1 != $v2) { + return false; + } + + $a1 = get_object_vars($v1); + $a2 = get_object_vars($v2); + + foreach (get_object_vars($v1) as $key => $itemValue) { + if (is_object($a1[$key]) && is_object($a2[$key])) { + if (!self::areValuesEqual(AttributeType::JSON_OBJECT, $a1[$key], $a2[$key])) { + return false; + } + + continue; + } + + if (is_array($a1[$key]) && is_array($a2[$key])) { + if (!self::areValuesEqual(AttributeType::JSON_ARRAY, $a1[$key], $a2[$key])) { + return false; + } + + continue; + } + + if ($a1[$key] !== $a2[$key]) { + return false; + } + } + + return true; + } + } + + return $v1 === $v2; + } +}