mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #7357 from cakephp/issue-7076
Always update updated/modified columns when a fieldList is used.
This commit is contained in:
commit
2d2c5be543
2 changed files with 36 additions and 3 deletions
|
@ -1835,7 +1835,12 @@ class Model extends Object implements CakeEventListener {
|
|||
$now = time();
|
||||
|
||||
foreach ($dateFields as $updateCol) {
|
||||
if (in_array($updateCol, $fields) || !$this->hasField($updateCol)) {
|
||||
$fieldHasValue = in_array($updateCol, $fields);
|
||||
$fieldInWhitelist = (
|
||||
count($this->whitelist) === 0 ||
|
||||
in_array($updateCol, $this->whitelist)
|
||||
);
|
||||
if (($fieldHasValue && $fieldInWhitelist) || !$this->hasField($updateCol)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -387,6 +387,34 @@ class ModelWriteTest extends BaseModelTest {
|
|||
$this->assertEquals($whitelist, $model->whitelist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that save() with a fieldList continues to write
|
||||
* updated in all cases.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSaveUpdatedWithFieldList() {
|
||||
$this->loadFixtures('Post', 'Author');
|
||||
$model = ClassRegistry::init('Post');
|
||||
$original = $model->find('first', array(
|
||||
'conditions' => array('Post.id' => 1)
|
||||
));
|
||||
$data = array(
|
||||
'Post' => array(
|
||||
'id' => 1,
|
||||
'title' => 'New title',
|
||||
'updated' => '1999-01-01 00:00:00',
|
||||
)
|
||||
);
|
||||
$model->save($data, array(
|
||||
'fieldList' => array('title')
|
||||
));
|
||||
$new = $model->find('first', array(
|
||||
'conditions' => array('Post.id' => 1)
|
||||
));
|
||||
$this->assertGreaterThan($original['Post']['updated'], $new['Post']['updated']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test save() resets the whitelist after afterSave
|
||||
*
|
||||
|
@ -1960,8 +1988,8 @@ class ModelWriteTest extends BaseModelTest {
|
|||
'title' => 'New Article With Tags and fieldList',
|
||||
'body' => '',
|
||||
'published' => 'N',
|
||||
'created' => '',
|
||||
'updated' => ''
|
||||
'created' => static::date(),
|
||||
'updated' => static::date(),
|
||||
),
|
||||
'Tag' => array(
|
||||
0 => array(
|
||||
|
|
Loading…
Reference in a new issue