mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-25 19:20:29 +08:00
unify changedAttributes of afterSave in extensions
This commit is contained in:
@@ -416,8 +416,9 @@ class ActiveRecord extends BaseActiveRecord
|
|||||||
$this->_version = $response['_version'];
|
$this->_version = $response['_version'];
|
||||||
$this->_score = null;
|
$this->_score = null;
|
||||||
|
|
||||||
|
$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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -224,8 +224,9 @@ abstract class ActiveRecord extends BaseActiveRecord
|
|||||||
$this->setAttribute('_id', $newId);
|
$this->setAttribute('_id', $newId);
|
||||||
$values['_id'] = $newId;
|
$values['_id'] = $newId;
|
||||||
|
|
||||||
|
$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;
|
||||||
}
|
}
|
||||||
@@ -260,10 +261,12 @@ abstract class ActiveRecord extends BaseActiveRecord
|
|||||||
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->getOldAttribute($name);
|
||||||
$this->setOldAttribute($name, $this->getAttribute($name));
|
$this->setOldAttribute($name, $this->getAttribute($name));
|
||||||
}
|
}
|
||||||
$this->afterSave(false, $values);
|
$this->afterSave(false, $changedAttributes);
|
||||||
|
|
||||||
return $rows;
|
return $rows;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,8 +127,9 @@ abstract class ActiveRecord extends \yii\mongodb\ActiveRecord
|
|||||||
$this->setAttribute('_id', $newId);
|
$this->setAttribute('_id', $newId);
|
||||||
$values['_id'] = $newId;
|
$values['_id'] = $newId;
|
||||||
|
|
||||||
|
$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;
|
||||||
}
|
}
|
||||||
@@ -196,10 +197,12 @@ abstract class ActiveRecord extends \yii\mongodb\ActiveRecord
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$changedAttributes = [];
|
||||||
foreach ($values as $name => $value) {
|
foreach ($values as $name => $value) {
|
||||||
|
$changedAttributes[$name] = $this->getOldAttribute($name);
|
||||||
$this->setOldAttribute($name, $this->getAttribute($name));
|
$this->setOldAttribute($name, $this->getAttribute($name));
|
||||||
}
|
}
|
||||||
$this->afterSave(false, $values);
|
$this->afterSave(false, $changedAttributes);
|
||||||
|
|
||||||
return $rows;
|
return $rows;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,8 +124,9 @@ class ActiveRecord extends BaseActiveRecord
|
|||||||
}
|
}
|
||||||
$db->executeCommand('HMSET', $args);
|
$db->executeCommand('HMSET', $args);
|
||||||
|
|
||||||
|
$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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -395,8 +395,9 @@ abstract class ActiveRecord extends BaseActiveRecord
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setOldAttributes($values);
|
$changedAttributes = array_fill_keys(array_keys($values), null);
|
||||||
$this->afterSave(true, $values);
|
$this->setOldAttributes($values);
|
||||||
|
$this->afterSave(true, $changedAttributes);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -530,10 +531,12 @@ abstract class ActiveRecord extends BaseActiveRecord
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$changedAttributes = [];
|
||||||
foreach ($values as $name => $value) {
|
foreach ($values as $name => $value) {
|
||||||
|
$changedAttributes[$name] = $this->getOldAttribute($name);
|
||||||
$this->setOldAttribute($name, $this->getAttribute($name));
|
$this->setOldAttribute($name, $this->getAttribute($name));
|
||||||
}
|
}
|
||||||
$this->afterSave(false, $values);
|
$this->afterSave(false, $changedAttributes);
|
||||||
|
|
||||||
return $rows;
|
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.
|
- 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 #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 #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: 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: 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)
|
- 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 #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)
|
||||||
|
|||||||
@@ -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
|
* 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
|
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`.
|
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
|
* `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
|
differentiate it more from calling `update(false)` and to ensure it can be used in `afterSave()` without triggering infinite
|
||||||
|
|||||||
Reference in New Issue
Block a user