public function duplicate($doWrite = true, $manyMany = 'many_many')
    {
        $duplicate = parent::duplicate($doWrite);

        $oldSubsiteID = SubsiteState::singleton()->getSubsiteId();
        self::changeSubsite($this->ID);

        /*
         * Copy data from this object to the given subsite. Does this using an iterative depth-first search.
         * This will make sure that the new parents on the new subsite are correct, and there are no funny
         * issues with having to check whether or not the new parents have been added to the site tree
         * when a page, etc, is duplicated
         */
        $stack = [[0, 0]];
        while (count($stack) > 0) {
            list($sourceParentID, $destParentID) = array_pop($stack);
            $children = Versioned::get_by_stage('Page', 'Live', "\"ParentID\" = $sourceParentID", '');

            if ($children) {
                foreach ($children as $child) {
                    self::changeSubsite($duplicate->ID); //Change to destination subsite

                    $childClone = $child->duplicateToSubsite($duplicate, false);
                    $childClone->ParentID = $destParentID;
                    $childClone->writeToStage('Stage');
                    $childClone->copyVersionToStage('Stage', 'Live');

                    self::changeSubsite($this->ID); //Change Back to this subsite

                    array_push($stack, [$child->ID, $childClone->ID]);
                }
            }
        }

        self::changeSubsite($oldSubsiteID);

        return $duplicate;
    }
public function duplicate($doWrite = true, $manyMany = 'many_many')
    {
        $duplicate = parent::duplicate($doWrite);

        $oldSubsiteID = SubsiteState::singleton()->getSubsiteId();
        self::changeSubsite($this->ID);

        /*
         * Copy data from this object to the given subsite. Does this using an iterative depth-first search.
         * This will make sure that the new parents on the new subsite are correct, and there are no funny
         * issues with having to check whether or not the new parents have been added to the site tree
         * when a page, etc, is duplicated
         */
        $stack = [[0, 0]];
        while (count($stack) > 0) {
            list($sourceParentID, $destParentID) = array_pop($stack);
            $children = Versioned::get_by_stage('Page', 'Live', "\"ParentID\" = $sourceParentID", '');

            if ($children) {
                foreach ($children as $child) {
                    self::changeSubsite($duplicate->ID); //Change to destination subsite

                    $childClone = $child->duplicateToSubsite($duplicate, false);
                    $childClone->ParentID = $destParentID;
                    $childClone->writeToStage('Stage');
                    $childClone->copyVersionToStage('Stage', 'Live');

                    self::changeSubsite($this->ID); //Change Back to this subsite

                    array_push($stack, [$child->ID, $childClone->ID]);
                }
            }
        }

        self::changeSubsite($oldSubsiteID);

        return $duplicate;
    }
public function duplicate ( $ doWrite = true , $ manyMany = 'many_many' ) { $ duplicate = parent :: duplicate ( $ doWrite ) ; $ oldSubsiteID = SubsiteState :: singleton ( ) -> getSubsiteId ( ) ; self :: changeSubsite ( $ this -> ID ) ; /*
         * Copy data from this object to the given subsite. Does this using an iterative depth-first search.
         * This will make sure that the new parents on the new subsite are correct, and there are no funny
         * issues with having to check whether or not the new parents have been added to the site tree
         * when a page, etc, is duplicated
         */ $ stack = [ [ 0 , 0 ] ] ; while ( count ( $ stack ) > 0 ) { list ( $ sourceParentID , $ destParentID ) = array_pop ( $ stack ) ; $ children = Versioned :: get_by_stage ( 'Page' , 'Live' , "\"ParentID\" = $sourceParentID" , '' ) ; if ( $ children ) { foreach ( $ children as $ child ) { self :: changeSubsite ( $ duplicate -> ID ) ; //Change to destination subsite $ childClone = $ child -> duplicateToSubsite ( $ duplicate , false ) ; $ childClone -> ParentID = $ destParentID ; $ childClone -> writeToStage ( 'Stage' ) ; $ childClone -> copyVersionToStage ( 'Stage' , 'Live' ) ; self :: changeSubsite ( $ this -> ID ) ; //Change Back to this subsite array_push ( $ stack , [ $ child -> ID , $ childClone -> ID ] ) ; } } } self :: changeSubsite ( $ oldSubsiteID ) ; return $ duplicate ; }
Duplicate this subsite
@param bool $doWrite
@param string $manyMany
@return DataObject
Duplicate this subsite