mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge branch '3.5' into 3.6
This commit is contained in:
commit
921f615e19
@ -1378,6 +1378,12 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
// Check changes exist, abort if there are none
|
// Check changes exist, abort if there are none
|
||||||
$hasChanges = $this->updateChanges($isNewRecord);
|
$hasChanges = $this->updateChanges($isNewRecord);
|
||||||
if($hasChanges || $forceWrite || $isNewRecord) {
|
if($hasChanges || $forceWrite || $isNewRecord) {
|
||||||
|
|
||||||
|
// Ensure Created and LastEdited are populated
|
||||||
|
if(!isset($this->record['Created'])) {
|
||||||
|
$this->record['Created'] = $now;
|
||||||
|
}
|
||||||
|
$this->record['LastEdited'] = $now;
|
||||||
// New records have their insert into the base data table done first, so that they can pass the
|
// New records have their insert into the base data table done first, so that they can pass the
|
||||||
// generated primary key on to the rest of the manipulation
|
// generated primary key on to the rest of the manipulation
|
||||||
$baseTable = ClassInfo::baseDataClass($this->class);
|
$baseTable = ClassInfo::baseDataClass($this->class);
|
||||||
@ -1397,12 +1403,6 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
$this->invokeWithExtensions('onAfterSkippedWrite');
|
$this->invokeWithExtensions('onAfterSkippedWrite');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure Created and LastEdited are populated
|
|
||||||
if(!isset($this->record['Created'])) {
|
|
||||||
$this->record['Created'] = $now;
|
|
||||||
}
|
|
||||||
$this->record['LastEdited'] = $now;
|
|
||||||
|
|
||||||
// Write relations as necessary
|
// Write relations as necessary
|
||||||
if($writeComponents) $this->writeComponents(true);
|
if($writeComponents) $this->writeComponents(true);
|
||||||
|
|
||||||
|
@ -357,6 +357,23 @@ class DataObjectTest extends SapphireTest {
|
|||||||
$this->assertEquals(1, $players->limit(5, 3)->count());
|
$this->assertEquals(1, $players->limit(5, 3)->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testWriteNoChangesDoesntUpdateLastEdited() {
|
||||||
|
// set mock now so we can be certain of LastEdited time for our test
|
||||||
|
SS_Datetime::set_mock_now('2017-01-01 00:00:00');
|
||||||
|
$obj = new DataObjectTest_Player();
|
||||||
|
$obj->FirstName = 'Test';
|
||||||
|
$obj->Surname = 'Plater';
|
||||||
|
$obj->Email = 'test.player@example.com';
|
||||||
|
$obj->write();
|
||||||
|
$writtenObj = DataObjectTest_Player::get()->byID($obj->ID);
|
||||||
|
$this->assertEquals('2017-01-01 00:00:00', $writtenObj->LastEdited);
|
||||||
|
|
||||||
|
// set mock now so we get a new LastEdited if, for some reason, it's updated
|
||||||
|
SS_Datetime::set_mock_now('2017-02-01 00:00:00');
|
||||||
|
$writtenObj->write();
|
||||||
|
$this->assertEquals('2017-01-01 00:00:00', $writtenObj->LastEdited);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test writing of database columns which don't correlate to a DBField,
|
* Test writing of database columns which don't correlate to a DBField,
|
||||||
* e.g. all relation fields on has_one/has_many like "ParentID".
|
* e.g. all relation fields on has_one/has_many like "ParentID".
|
||||||
|
Loading…
Reference in New Issue
Block a user