public function copyPage(
        SiteEntity $destinationSite,
        PageEntity $pageToCopy,
        $pageData,
        $pageRevisionId = null,
        $publishNewPage = false,
        $doFlush = true
    ) {

        if (empty($pageData['name'])) {
            throw new InvalidArgumentException(
                'Missing needed information (name) to create page copy.'
            );
        }

        if (empty($pageData['createdByUserId'])) {
            throw new InvalidArgumentException(
                'Missing needed information (createdByUserId) to create page copy.'
            );
        }

        if (empty($pageData['createdReason'])) {
            $pageData['createdReason'] = 'Copy page in ' . get_class($this);
        }

        if (empty($pageData['author'])) {
            throw new InvalidArgumentException(
                'Missing needed information (author) to create page copy.'
            );
        }

        // Values cannot be changed
        unset($pageData['pageId']);
        unset($pageData['createdDate']);
        unset($pageData['lastPublished']);

        $pageData['site'] = $destinationSite;

        $clonedPage = $pageToCopy->newInstance(
            $pageData['createdByUserId'],
            $pageData['createdReason']
        );
        $clonedPage->populate($pageData);

        $this->assertCanCreateSitePage(
            $clonedPage->getSite(),
            $clonedPage->getName(),
            $clonedPage->getPageType()
        );

        $revisionToUse = $clonedPage->getStagedRevision();

        if (!empty($pageRevisionId)) {
            $sourceRevision = $pageToCopy->getRevisionById($pageRevisionId);

            if (empty($sourceRevision)) {
                throw new PageNotFoundException(
                    'Page revision not found.'
                );
            }

            $revisionToUse = $sourceRevision->newInstance(
                $pageData['createdByUserId'],
                $pageData['createdReason']
            );
            $clonedPage->setRevisions([]);
            $clonedPage->addRevision($revisionToUse);
        }

        if (empty($revisionToUse)) {
            throw new RuntimeException(
                'Page revision not found.'
            );
        }

        if ($publishNewPage) {
            $clonedPage->setPublishedRevision($revisionToUse);
        } else {
            $clonedPage->setStagedRevision($revisionToUse);
        }

        $destinationSite->addPage($clonedPage);

        $this->_em->persist($clonedPage);

        if ($doFlush) {
            $this->_em->flush($clonedPage);
        }

        return $clonedPage;
    }
public function copyPage(
        SiteEntity $destinationSite,
        PageEntity $pageToCopy,
        $pageData,
        $pageRevisionId = null,
        $publishNewPage = false,
        $doFlush = true
    ) {

        if (empty($pageData['name'])) {
            throw new InvalidArgumentException(
                'Missing needed information (name) to create page copy.'
            );
        }

        if (empty($pageData['createdByUserId'])) {
            throw new InvalidArgumentException(
                'Missing needed information (createdByUserId) to create page copy.'
            );
        }

        if (empty($pageData['createdReason'])) {
            $pageData['createdReason'] = 'Copy page in ' . get_class($this);
        }

        if (empty($pageData['author'])) {
            throw new InvalidArgumentException(
                'Missing needed information (author) to create page copy.'
            );
        }

        // Values cannot be changed
        unset($pageData['pageId']);
        unset($pageData['createdDate']);
        unset($pageData['lastPublished']);

        $pageData['site'] = $destinationSite;

        $clonedPage = $pageToCopy->newInstance(
            $pageData['createdByUserId'],
            $pageData['createdReason']
        );
        $clonedPage->populate($pageData);

        $this->assertCanCreateSitePage(
            $clonedPage->getSite(),
            $clonedPage->getName(),
            $clonedPage->getPageType()
        );

        $revisionToUse = $clonedPage->getStagedRevision();

        if (!empty($pageRevisionId)) {
            $sourceRevision = $pageToCopy->getRevisionById($pageRevisionId);

            if (empty($sourceRevision)) {
                throw new PageNotFoundException(
                    'Page revision not found.'
                );
            }

            $revisionToUse = $sourceRevision->newInstance(
                $pageData['createdByUserId'],
                $pageData['createdReason']
            );
            $clonedPage->setRevisions([]);
            $clonedPage->addRevision($revisionToUse);
        }

        if (empty($revisionToUse)) {
            throw new RuntimeException(
                'Page revision not found.'
            );
        }

        if ($publishNewPage) {
            $clonedPage->setPublishedRevision($revisionToUse);
        } else {
            $clonedPage->setStagedRevision($revisionToUse);
        }

        $destinationSite->addPage($clonedPage);

        $this->_em->persist($clonedPage);

        if ($doFlush) {
            $this->_em->flush($clonedPage);
        }

        return $clonedPage;
    }
public function copyPage ( SiteEntity $ destinationSite , PageEntity $ pageToCopy , $ pageData , $ pageRevisionId = null , $ publishNewPage = false , $ doFlush = true ) { if ( empty ( $ pageData [ 'name' ] ) ) { throw new InvalidArgumentException ( 'Missing needed information (name) to create page copy.' ) ; } if ( empty ( $ pageData [ 'createdByUserId' ] ) ) { throw new InvalidArgumentException ( 'Missing needed information (createdByUserId) to create page copy.' ) ; } if ( empty ( $ pageData [ 'createdReason' ] ) ) { $ pageData [ 'createdReason' ] = 'Copy page in ' . get_class ( $ this ) ; } if ( empty ( $ pageData [ 'author' ] ) ) { throw new InvalidArgumentException ( 'Missing needed information (author) to create page copy.' ) ; } // Values cannot be changed unset ( $ pageData [ 'pageId' ] ) ; unset ( $ pageData [ 'createdDate' ] ) ; unset ( $ pageData [ 'lastPublished' ] ) ; $ pageData [ 'site' ] = $ destinationSite ; $ clonedPage = $ pageToCopy -> newInstance ( $ pageData [ 'createdByUserId' ] , $ pageData [ 'createdReason' ] ) ; $ clonedPage -> populate ( $ pageData ) ; $ this -> assertCanCreateSitePage ( $ clonedPage -> getSite ( ) , $ clonedPage -> getName ( ) , $ clonedPage -> getPageType ( ) ) ; $ revisionToUse = $ clonedPage -> getStagedRevision ( ) ; if ( ! empty ( $ pageRevisionId ) ) { $ sourceRevision = $ pageToCopy -> getRevisionById ( $ pageRevisionId ) ; if ( empty ( $ sourceRevision ) ) { throw new PageNotFoundException ( 'Page revision not found.' ) ; } $ revisionToUse = $ sourceRevision -> newInstance ( $ pageData [ 'createdByUserId' ] , $ pageData [ 'createdReason' ] ) ; $ clonedPage -> setRevisions ( [ ] ) ; $ clonedPage -> addRevision ( $ revisionToUse ) ; } if ( empty ( $ revisionToUse ) ) { throw new RuntimeException ( 'Page revision not found.' ) ; } if ( $ publishNewPage ) { $ clonedPage -> setPublishedRevision ( $ revisionToUse ) ; } else { $ clonedPage -> setStagedRevision ( $ revisionToUse ) ; } $ destinationSite -> addPage ( $ clonedPage ) ; $ this -> _em -> persist ( $ clonedPage ) ; if ( $ doFlush ) { $ this -> _em -> flush ( $ clonedPage ) ; } return $ clonedPage ; }
Copy a page

@param SiteEntity $destinationSite Site Entity to copy page to
@param PageEntity $pageToCopy Page Entity to copy
@param array $pageData Array of data to populate the page entity
@param null $pageRevisionId Page Revision ID to use for copy.  Defaults to currently published
@param bool $publishNewPage Publish page instead of setting to staged
@param bool $doFlush Force flush

@return PageEntity
Copy a page