Commit 44f20c61 by Vladimir Zbrailov

changedAttributes of AfterSaveEvent contain an old values

parent 06f27758
...@@ -152,6 +152,7 @@ Yii Framework 2 Change Log ...@@ -152,6 +152,7 @@ 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 #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 #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 #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: 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: 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) - Chg: `yii\grid\DataColumn::getDataCellValue()` visibility is now `public` to allow accessing the value from a GridView directly (cebe)
......
...@@ -462,8 +462,9 @@ class ActiveRecord extends BaseActiveRecord ...@@ -462,8 +462,9 @@ class ActiveRecord extends BaseActiveRecord
} }
} }
$changedAttributes = array_fill_keys(array_keys($values), null);
$this->setOldAttributes($values); $this->setOldAttributes($values);
$this->afterSave(true, $values); $this->afterSave(true, $changedAttributes);
return true; return true;
} }
......
...@@ -714,10 +714,12 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface ...@@ -714,10 +714,12 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
throw new StaleObjectException('The object being updated is outdated.'); throw new StaleObjectException('The object being updated is outdated.');
} }
$changedAttributes = [];
foreach ($values as $name => $value) { foreach ($values as $name => $value) {
$changedAttributes[$name] = $this->_oldAttributes[$name];
$this->_oldAttributes[$name] = $this->_attributes[$name]; $this->_oldAttributes[$name] = $this->_attributes[$name];
} }
$this->afterSave(false, $values); $this->afterSave(false, $changedAttributes);
return $rows; return $rows;
} }
...@@ -875,7 +877,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface ...@@ -875,7 +877,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
* the event is triggered. * the event is triggered.
* @param boolean $insert whether this method called while inserting a record. * @param boolean $insert whether this method called while inserting a record.
* If false, it means the method is called while updating a record. * If false, it means the method is called while updating a record.
* @param array $changedAttributes The attribute values that had changed and were saved. * @param array $changedAttributes The attribute values that had changed and were saved contain old values.
*/ */
public function afterSave($insert, $changedAttributes) public function afterSave($insert, $changedAttributes)
{ {
......
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