Commit f9febd00 by Vladimir Zbrailov

unify changedAttributes of afterSave in extensions

parent 7113a23a
......@@ -416,8 +416,9 @@ class ActiveRecord extends BaseActiveRecord
$this->_version = $response['_version'];
$this->_score = null;
$changedAttributes = array_fill_keys(array_keys($values), null);
$this->setOldAttributes($values);
$this->afterSave(true, $values);
$this->afterSave(true, $changedAttributes);
return true;
}
......
......@@ -224,8 +224,9 @@ abstract class ActiveRecord extends BaseActiveRecord
$this->setAttribute('_id', $newId);
$values['_id'] = $newId;
$changedAttributes = array_fill_keys(array_keys($values), null);
$this->setOldAttributes($values);
$this->afterSave(true, $values);
$this->afterSave(true, $changedAttributes);
return true;
}
......@@ -260,10 +261,12 @@ abstract class ActiveRecord extends BaseActiveRecord
throw new StaleObjectException('The object being updated is outdated.');
}
$changedAttributes = [];
foreach ($values as $name => $value) {
$changedAttributes[$name] = $this->getOldAttribute($name);
$this->setOldAttribute($name, $this->getAttribute($name));
}
$this->afterSave(false, $values);
$this->afterSave(false, $changedAttributes);
return $rows;
}
......
......@@ -127,8 +127,9 @@ abstract class ActiveRecord extends \yii\mongodb\ActiveRecord
$this->setAttribute('_id', $newId);
$values['_id'] = $newId;
$changedAttributes = array_fill_keys(array_keys($values), null);
$this->setOldAttributes($values);
$this->afterSave(true, $values);
$this->afterSave(true, $changedAttributes);
return true;
}
......@@ -196,10 +197,12 @@ abstract class ActiveRecord extends \yii\mongodb\ActiveRecord
}
}
$changedAttributes = [];
foreach ($values as $name => $value) {
$changedAttributes[$name] = $this->getOldAttribute($name);
$this->setOldAttribute($name, $this->getAttribute($name));
}
$this->afterSave(false, $values);
$this->afterSave(false, $changedAttributes);
return $rows;
}
......
......@@ -124,8 +124,9 @@ class ActiveRecord extends BaseActiveRecord
}
$db->executeCommand('HMSET', $args);
$changedAttributes = array_fill_keys(array_keys($values), null);
$this->setOldAttributes($values);
$this->afterSave(true, $values);
$this->afterSave(true, $changedAttributes);
return true;
}
......
......@@ -395,8 +395,9 @@ abstract class ActiveRecord extends BaseActiveRecord
return false;
}
$changedAttributes = array_fill_keys(array_keys($values), null);
$this->setOldAttributes($values);
$this->afterSave(true, $values);
$this->afterSave(true, $changedAttributes);
return true;
}
......@@ -530,10 +531,12 @@ abstract class ActiveRecord extends BaseActiveRecord
}
}
$changedAttributes = [];
foreach ($values as $name => $value) {
$changedAttributes[$name] = $this->getOldAttribute($name);
$this->setOldAttribute($name, $this->getAttribute($name));
}
$this->afterSave(false, $values);
$this->afterSave(false, $changedAttributes);
return $rows;
}
......
......@@ -121,6 +121,7 @@ Yii Framework 2 Change Log
- Added note about the fact that intl is required for non-latin languages to requirements checker.
- Enh #4028: Added ability to `yii\widgets\Menu` to encode each item's label separately (creocoder, umneeq)
- Enh #4080: Added proper handling and support of the symlinked directories in `FileHelper`, added $options parameter in `FileHelper::removeDirectory()` (resurtm)
- Enh #4086: changedAttributes of AfterSaveEvent contain an old values (dizews)
- Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue)
- Enh: Supported adding a new response formatter without the need to reconfigure existing formatters (qiangxue)
- Enh: Added `yii\web\UrlManager::addRules()` to simplify adding new URL rules (qiangxue)
......@@ -152,7 +153,6 @@ Yii Framework 2 Change Log
- Chg #3956: Flash messages set via `Yii::$app->session->setFlash()` will be removed only if they are accessed (qiangxue)
- Chg #3989: The default value for `yii\log\FileTarget::$rotateByCopy` now defaults to true to work on windows by default (cebe)
- Chg #4071: `mail` component renamed to `mailer`, `yii\log\EmailTarget::$mail` renamed to `yii\log\EmailTarget::$mailer` (samdark)
- Chg #4086: changedAttributes of AfterSaveEvent contain an old values (dizews)
- Chg: Replaced `clearAll()` and `clearAllAssignments()` in `yii\rbac\ManagerInterface` with `removeAll()`, `removeAllRoles()`, `removeAllPermissions()`, `removeAllRules()` and `removeAllAssignments()` (qiangxue)
- Chg: Added `$user` as the first parameter of `yii\rbac\Rule::execute()` (qiangxue)
- Chg: `yii\grid\DataColumn::getDataCellValue()` visibility is now `public` to allow accessing the value from a GridView directly (cebe)
......
......@@ -61,6 +61,7 @@ Upgrade from Yii 2.0 Beta
* The behavior and signature of `ActiveRecord::afterSave()` has changed. `ActiveRecord::$isNewRecord` will now always be
false in afterSave and also dirty attributes are not available. This change has been made to have a more consistent and
expected behavior. The changed attributes are now available in the new parameter of afterSave() `$changedAttributes`.
The `$changedAttributes` contain an old values of attributes that had changed and were saved.
* `ActiveRecord::updateAttributes()` has been changed to not trigger events and not respect optimistic locking anymore to
differentiate it more from calling `update(false)` and to ensure it can be used in `afterSave()` without triggering infinite
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment