Merge pull request #6425 from andrewandante/bugfix/duplicating-copies-created-dbfield

remove Created field on duplicate
This commit is contained in:
Damian Mooyman 2016-12-21 09:43:53 +13:00 committed by GitHub
commit fd9b872cb5
2 changed files with 7 additions and 2 deletions

View File

@ -531,7 +531,9 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
*/
public function duplicate($doWrite = true) {
$className = $this->class;
$clone = new $className( $this->toMap(), false, $this->model );
$map = $this->toMap();
unset($map['Created']);
$clone = new $className( $map, false, $this->model );
$clone->ID = 0;
$clone->invokeWithExtensions('onBeforeDuplicate', $this, $doWrite);

View File

@ -11,10 +11,11 @@ class DataObjectDuplicationTest extends SapphireTest {
);
public function testDuplicate() {
SS_Datetime::set_mock_now('2016-01-01 01:01:01');
$orig = new DataObjectDuplicateTestClass1();
$orig->text = 'foo';
$orig->write();
SS_Datetime::set_mock_now('2016-01-02 01:01:01');
$duplicate = $orig->duplicate();
$this->assertInstanceOf('DataObjectDuplicateTestClass1', $duplicate,
'Creates the correct type'
@ -28,6 +29,8 @@ class DataObjectDuplicationTest extends SapphireTest {
$this->assertEquals(2, DataObjectDuplicateTestClass1::get()->Count(),
'Only creates a single duplicate'
);
$this->assertEquals(SS_Datetime::now()->Nice(), $duplicate->dbObject('Created')->Nice());
$this->assertNotEquals($orig->dbObject('Created')->Nice(), $duplicate->dbObject('Created')->Nice());
}
public function testDuplicateHasOne() {