Fix copying child pages to subsite

This commit is contained in:
David Craig 2016-11-11 16:18:41 +13:00
parent 81c95c9f3e
commit ae6badf5c0
No known key found for this signature in database
GPG Key ID: D4AC70FF9B3F27E5
1 changed files with 7 additions and 6 deletions

View File

@ -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;
}