mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG: DataObject::write overwrites Created on first write
This commit is contained in:
parent
43cd54bb25
commit
f2a709d849
@ -1147,7 +1147,13 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
if($idx == 0) {
|
||||
$manipulation[$class]['fields']["LastEdited"] = "'".SS_Datetime::now()->Rfc2822()."'";
|
||||
if($dbCommand == 'insert') {
|
||||
$manipulation[$class]['fields']["Created"] = "'".SS_Datetime::now()->Rfc2822()."'";
|
||||
if(!empty($this->record["Created"])) {
|
||||
$manipulation[$class]['fields']["Created"]
|
||||
= DB::getConn()->prepStringForDB($this->record["Created"]);
|
||||
} else {
|
||||
$manipulation[$class]['fields']["Created"]
|
||||
= DB::getConn()->prepStringForDB(SS_Datetime::now()->Rfc2822());
|
||||
}
|
||||
//echo "<li>$this->class - " .get_class($this);
|
||||
$manipulation[$class]['fields']["ClassName"]
|
||||
= DB::getConn()->prepStringForDB($this->class);
|
||||
|
@ -1127,7 +1127,24 @@ class DataObjectTest extends SapphireTest {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testWriteOverwritesCreated() {
|
||||
// Previously, if you set DataObject::$Created before the object was first written, it would be overwritten
|
||||
$pastdate = new SS_DateTime();
|
||||
$pastdate->setValue(Date::past_date(1));
|
||||
|
||||
$obj = new DataObjectTest_Player();
|
||||
$obj->Created = $pastdate->Value;
|
||||
$obj->write();
|
||||
|
||||
$objID = $obj->ID;
|
||||
|
||||
unset($obj);
|
||||
DataObject::reset();
|
||||
|
||||
$obj = DataObjectTest_Player::get()->byID($objID);
|
||||
|
||||
$this->assertEquals($pastdate->Value, $obj->Created);
|
||||
}
|
||||
}
|
||||
|
||||
class DataObjectTest_Player extends Member implements TestOnly {
|
||||
|
Loading…
Reference in New Issue
Block a user