Merge pull request #266 from SomarDesignStudios/pulls/fix-copy-child-pages

Fix copying child pages to subsite
This commit is contained in:
Daniel Hensby 2016-11-11 10:55:07 +00:00 committed by GitHub
commit 2cce5e1606

View File

@ -213,10 +213,12 @@ class SiteTreeSubsites extends DataExtension
* Create a duplicate of this page and save it to another subsite * Create a duplicate of this page and save it to another subsite
* *
* @param int|Subsite $subsiteID The Subsite to copy to, or its ID * @param int|Subsite $subsiteID The Subsite to copy to, or its ID
* @param bool $includeChildren Recursively copy child Pages.
* @param int $parentID Where to place the Page in the SiteTree's structure.
* *
* @return SiteTree duplicated page * @return SiteTree duplicated page
*/ */
public function duplicateToSubsite($subsiteID = null, $includeChildren = false) public function duplicateToSubsite($subsiteID = null, $includeChildren = false, $parentID = 0)
{ {
if ($subsiteID instanceof Subsite) { if ($subsiteID instanceof Subsite) {
$subsiteID = $subsiteID->ID; $subsiteID = $subsiteID->ID;
@ -236,21 +238,20 @@ class SiteTreeSubsites extends DataExtension
$subsiteID = ($subsiteID ? $subsiteID : $oldSubsite); $subsiteID = ($subsiteID ? $subsiteID : $oldSubsite);
$page->SubsiteID = $subsiteID; $page->SubsiteID = $subsiteID;
// Remove parent ID, since this parent belongs to another subsite $page->ParentID = $parentID;
$page->ParentID = 0;
// MasterPageID is here for legacy purposes, to satisfy the subsites_relatedpages module // MasterPageID is here for legacy purposes, to satisfy the subsites_relatedpages module
$page->MasterPageID = $this->owner->ID; $page->MasterPageID = $this->owner->ID;
$page->write(); $page->write();
Subsite::changeSubsite($oldSubsite);
if($includeChildren) { if($includeChildren) {
foreach($this->owner->AllChildren() as $child) { foreach($this->owner->AllChildren() as $child) {
$child->duplicateToSubsite($subsiteID, $includeChildren); $child->duplicateToSubsite($subsiteID, $includeChildren, $page->ID);
} }
} }
Subsite::changeSubsite($oldSubsite);
return $page; return $page;
} }