From ae6badf5c079b40c44dc6c443b9a67b9fa06af83 Mon Sep 17 00:00:00 2001 From: David Craig Date: Fri, 11 Nov 2016 16:18:41 +1300 Subject: [PATCH] Fix copying child pages to subsite --- code/extensions/SiteTreeSubsites.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/code/extensions/SiteTreeSubsites.php b/code/extensions/SiteTreeSubsites.php index 5a8c979..a3b2f54 100644 --- a/code/extensions/SiteTreeSubsites.php +++ b/code/extensions/SiteTreeSubsites.php @@ -213,10 +213,12 @@ class SiteTreeSubsites extends DataExtension * 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 bool $includeChildren Recursively copy child Pages. + * @param int $parentID Where to place the Page in the SiteTree's structure. * * @return SiteTree duplicated page */ - public function duplicateToSubsite($subsiteID = null, $includeChildren = false) + public function duplicateToSubsite($subsiteID = null, $includeChildren = false, $parentID = 0) { if ($subsiteID instanceof Subsite) { $subsiteID = $subsiteID->ID; @@ -236,21 +238,20 @@ class SiteTreeSubsites extends DataExtension $subsiteID = ($subsiteID ? $subsiteID : $oldSubsite); $page->SubsiteID = $subsiteID; - // Remove parent ID, since this parent belongs to another subsite - $page->ParentID = 0; + $page->ParentID = $parentID; // MasterPageID is here for legacy purposes, to satisfy the subsites_relatedpages module $page->MasterPageID = $this->owner->ID; $page->write(); + Subsite::changeSubsite($oldSubsite); + if($includeChildren) { foreach($this->owner->AllChildren() as $child) { - $child->duplicateToSubsite($subsiteID, $includeChildren); + $child->duplicateToSubsite($subsiteID, $includeChildren, $page->ID); } } - Subsite::changeSubsite($oldSubsite); - return $page; }