mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
API Cleanup inconsistent SiteTree::duplicate API
This commit is contained in:
parent
9feec1f1da
commit
c50bc91772
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user