Commit 1085f1bd by Carsten Brandt

cleanup after #4092

fixes #4086
parent 2d2c9f03
...@@ -7,6 +7,7 @@ Yii Framework 2 elasticsearch extension Change Log ...@@ -7,6 +7,7 @@ Yii Framework 2 elasticsearch extension Change Log
- Bug #3587: Fixed an issue with storing empty records (cebe) - Bug #3587: Fixed an issue with storing empty records (cebe)
- Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe) - Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe)
- Enh #3527: Added `highlight` property to Query and ActiveRecord. (Borales) - Enh #3527: Added `highlight` property to Query and ActiveRecord. (Borales)
- Enh #4086: changedAttributes of afterSave Event now contain old values (dizews)
- Enh: Make error messages more readable in HTML output (cebe) - Enh: Make error messages more readable in HTML output (cebe)
- Chg: asArray in ActiveQuery is now equal to using the normal Query. This means, that the output structure has changed and `with` is supported anymore. (cebe) - Chg: asArray in ActiveQuery is now equal to using the normal Query. This means, that the output structure has changed and `with` is supported anymore. (cebe)
- Chg: Deletion of a record is now also considered successful if the record did not exist. (cebe) - Chg: Deletion of a record is now also considered successful if the record did not exist. (cebe)
......
...@@ -264,7 +264,7 @@ abstract class ActiveRecord extends BaseActiveRecord ...@@ -264,7 +264,7 @@ abstract class ActiveRecord extends BaseActiveRecord
$changedAttributes = []; $changedAttributes = [];
foreach ($values as $name => $value) { foreach ($values as $name => $value) {
$changedAttributes[$name] = $this->getOldAttribute($name); $changedAttributes[$name] = $this->getOldAttribute($name);
$this->setOldAttribute($name, $this->getAttribute($name)); $this->setOldAttribute($name, $value);
} }
$this->afterSave(false, $changedAttributes); $this->afterSave(false, $changedAttributes);
......
...@@ -8,6 +8,7 @@ Yii Framework 2 mongodb extension Change Log ...@@ -8,6 +8,7 @@ Yii Framework 2 mongodb extension Change Log
- Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe) - Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe)
- Enh #3778: Gii generator for Active Record model added (klimov-paul) - Enh #3778: Gii generator for Active Record model added (klimov-paul)
- Enh #3947: Migration support added (klimov-paul) - Enh #3947: Migration support added (klimov-paul)
- Enh #4086: changedAttributes of afterSave Event now contain old values (dizews)
2.0.0-beta April 13, 2014 2.0.0-beta April 13, 2014
......
...@@ -200,7 +200,7 @@ abstract class ActiveRecord extends \yii\mongodb\ActiveRecord ...@@ -200,7 +200,7 @@ abstract class ActiveRecord extends \yii\mongodb\ActiveRecord
$changedAttributes = []; $changedAttributes = [];
foreach ($values as $name => $value) { foreach ($values as $name => $value) {
$changedAttributes[$name] = $this->getOldAttribute($name); $changedAttributes[$name] = $this->getOldAttribute($name);
$this->setOldAttribute($name, $this->getAttribute($name)); $this->setOldAttribute($name, $value);
} }
$this->afterSave(false, $changedAttributes); $this->afterSave(false, $changedAttributes);
......
...@@ -5,6 +5,7 @@ Yii Framework 2 redis extension Change Log ...@@ -5,6 +5,7 @@ Yii Framework 2 redis extension Change Log
-------------------------- --------------------------
- Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe) - Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe)
- Enh #4086: changedAttributes of afterSave Event now contain old values (dizews)
2.0.0-beta April 13, 2014 2.0.0-beta April 13, 2014
......
...@@ -534,7 +534,7 @@ abstract class ActiveRecord extends BaseActiveRecord ...@@ -534,7 +534,7 @@ abstract class ActiveRecord extends BaseActiveRecord
$changedAttributes = []; $changedAttributes = [];
foreach ($values as $name => $value) { foreach ($values as $name => $value) {
$changedAttributes[$name] = $this->getOldAttribute($name); $changedAttributes[$name] = $this->getOldAttribute($name);
$this->setOldAttribute($name, $this->getAttribute($name)); $this->setOldAttribute($name, $value);
} }
$this->afterSave(false, $changedAttributes); $this->afterSave(false, $changedAttributes);
......
...@@ -6,8 +6,9 @@ Yii Framework 2 sphinx extension Change Log ...@@ -6,8 +6,9 @@ Yii Framework 2 sphinx extension Change Log
- Bug #3668: Escaping of the special characters at 'MATCH' statement added (klimov-paul) - Bug #3668: Escaping of the special characters at 'MATCH' statement added (klimov-paul)
- Bug #4018: AR relation eager loading does not work with db models (klimov-paul) - Bug #4018: AR relation eager loading does not work with db models (klimov-paul)
- Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue)
- Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe) - Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe)
- Enh #4086: changedAttributes of afterSave Event now contain old values (dizews)
- Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue)
- Chg #2287: Split `yii\sphinx\ColumnSchema::typecast()` into two methods `phpTypecast()` and `dbTypecast()` to allow specifying PDO type explicitly (cebe) - Chg #2287: Split `yii\sphinx\ColumnSchema::typecast()` into two methods `phpTypecast()` and `dbTypecast()` to allow specifying PDO type explicitly (cebe)
......
...@@ -122,7 +122,7 @@ Yii Framework 2 Change Log ...@@ -122,7 +122,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 #4086: changedAttributes of afterSave Event now contain 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)
......
...@@ -61,7 +61,7 @@ Upgrade from Yii 2.0 Beta ...@@ -61,7 +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. `$changedAttributes` contains the 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
......
...@@ -717,7 +717,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface ...@@ -717,7 +717,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
$changedAttributes = []; $changedAttributes = [];
foreach ($values as $name => $value) { foreach ($values as $name => $value) {
$changedAttributes[$name] = $this->_oldAttributes[$name]; $changedAttributes[$name] = $this->_oldAttributes[$name];
$this->_oldAttributes[$name] = $this->_attributes[$name]; $this->_oldAttributes[$name] = $value;
} }
$this->afterSave(false, $changedAttributes); $this->afterSave(false, $changedAttributes);
...@@ -878,6 +878,10 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface ...@@ -878,6 +878,10 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
* @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 old values of attributes that had changed and were saved. * @param array $changedAttributes The old values of attributes that had changed and were saved.
* You can use this parameter to take action based on the changes made for example send an email
* when the password had changed or implement audit trail that tracks all the changes.
* `$changedAttributes` gives you the old attribute values while the active record (`$this`) has
* already the new, updated values.
*/ */
public function afterSave($insert, $changedAttributes) public function afterSave($insert, $changedAttributes)
{ {
......
...@@ -827,12 +827,14 @@ trait ActiveRecordTestTrait ...@@ -827,12 +827,14 @@ trait ActiveRecordTestTrait
$customerClass = $this->getCustomerClass(); $customerClass = $this->getCustomerClass();
/* @var $this TestCase|ActiveRecordTestTrait */ /* @var $this TestCase|ActiveRecordTestTrait */
// save // save
/* @var $customer Customer */
$customer = $customerClass::findOne(2); $customer = $customerClass::findOne(2);
$this->assertTrue($customer instanceof $customerClass); $this->assertTrue($customer instanceof $customerClass);
$this->assertEquals('user2', $customer->name); $this->assertEquals('user2', $customer->name);
$this->assertFalse($customer->isNewRecord); $this->assertFalse($customer->isNewRecord);
static::$afterSaveNewRecord = null; static::$afterSaveNewRecord = null;
static::$afterSaveInsert = null; static::$afterSaveInsert = null;
$this->assertEmpty($customer->dirtyAttributes);
$customer->name = 'user2x'; $customer->name = 'user2x';
$customer->save(); $customer->save();
......
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