From c50bc91772af2b400dbcd664f187730b25ba148b Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Mon, 13 Jun 2016 15:47:47 +1200 Subject: [PATCH] API Cleanup inconsistent SiteTree::duplicate API --- code/model/SiteTree.php | 23 +++++------------------ tests/model/SiteTreeTest.php | 8 ++++++++ 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php index 05606620..cf95e4e8 100755 --- a/code/model/SiteTree.php +++ b/code/model/SiteTree.php @@ -609,26 +609,13 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid } /** - * Create a duplicate of this node. Doesn't affect joined data - create a custom overloading of this if you need - * such behaviour. + * Reset Sort on duped page * - * @param bool $doWrite Whether to write the new object before returning it - * @return self The duplicated object + * @param SiteTree $original + * @param bool $doWrite */ - public function duplicate($doWrite = true) { - - $page = parent::duplicate(false); - $page->Sort = 0; - $this->invokeWithExtensions('onBeforeDuplicate', $page); - - if($doWrite) { - $page->write(); - - $page = $this->duplicateManyManyRelations($this, $page); - } - $this->invokeWithExtensions('onAfterDuplicate', $page); - - return $page; + public function onBeforeDuplicate($original, $doWrite) { + $this->Sort = 0; } /** diff --git a/tests/model/SiteTreeTest.php b/tests/model/SiteTreeTest.php index b3f0ba42..0e786a44 100644 --- a/tests/model/SiteTreeTest.php +++ b/tests/model/SiteTreeTest.php @@ -368,6 +368,14 @@ class SiteTreeTest extends SapphireTest { $this->assertFalse(DataObject::get_by_id('Page', $pageStaffDuplicate->ID)); } + public function testDuplicate() { + $pageAbout = $this->objFromFixture('Page', 'about'); + $dupe = $pageAbout->duplicate(); + $this->assertEquals($pageAbout->Title, $dupe->Title); + $this->assertNotEquals($pageAbout->URLSegment, $dupe->URLSegment); + $this->assertNotEquals($pageAbout->Sort, $dupe->Sort); + } + public function testDeleteFromLiveOperatesRecursively() { Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', false); $this->logInWithPermission('ADMIN');