diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index b92cac9ea0..fdc8310da3 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -24,6 +24,7 @@ Yii Framework 2 Change Log - Bug #19770: Fix `yii\mutex\MysqlMutex` `keyPrefix` expression param binding (kamarton) - Enh #19794: Add caching in `yii\web\Request` for `getUserIP()` and `getSecureForwardedHeaderTrustedParts()` (rhertogh) - Bug #19795: Fix `yii\web\Response::redirect()` to prevent setting headers with URL containing new line character (bizley) +- Enh #19804: Remove the unnecessary call to `$this->oldAttributes` in `BaseActiveRecord::getDirtyAttributes()` (thiagotalma) 2.0.47 November 18, 2022 ------------------------ diff --git a/framework/db/BaseActiveRecord.php b/framework/db/BaseActiveRecord.php index 67a55d7884..3e0dd316e5 100644 --- a/framework/db/BaseActiveRecord.php +++ b/framework/db/BaseActiveRecord.php @@ -639,7 +639,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface } } else { foreach ($this->_attributes as $name => $value) { - if (isset($names[$name]) && (!array_key_exists($name, $this->_oldAttributes) || $this->isAttributeDirty($name, $value))) { + if (isset($names[$name]) && (!array_key_exists($name, $this->_oldAttributes) || $this->isValueDifferent($value, $this->_oldAttributes[$name]))) { $attributes[$name] = $value; } } @@ -1756,18 +1756,18 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface } /** - * @param string $attribute - * @param mixed $value + * @param mixed $newValue + * @param mixed $oldValue * @return bool + * @since 2.0.48 */ - private function isAttributeDirty($attribute, $value) + private function isValueDifferent($newValue, $oldValue) { - $old_attribute = $this->oldAttributes[$attribute]; - if (is_array($value) && is_array($this->oldAttributes[$attribute])) { - $value = ArrayHelper::recursiveSort($value); - $old_attribute = ArrayHelper::recursiveSort($old_attribute); + if (is_array($newValue) && is_array($oldValue)) { + $newValue = ArrayHelper::recursiveSort($newValue); + $oldValue = ArrayHelper::recursiveSort($oldValue); } - return $value !== $old_attribute; + return $newValue !== $oldValue; } }