/** * Get resource provider with mocks * * @param bool $skipSite Skip Site Mock setup * * @return ResourceProvider */ protected function getProviderWithMocks($skipSite = false) { $mockReturn = []; $currdomain = new Domain(); $currdomain->setDomainName('curr.reliv.com'); $currpage = new Page(); $currpage->setName('curr-page'); $currsite = new Site(); $currsite->setDomain($currdomain); $currsite->setSiteId(1); $currsite->addPage($currpage); if (!$skipSite) { $domain = new Domain(); $domain->setDomainName('test.reliv.com'); $page = new Page(); $page->setName('test-page'); $site = new Site(); $site->setDomain($domain); $site->setSiteId(10); $site->addPage($page); $mockReturn[] = $site; } $mockSiteRepo = $this->getMockBuilder('\\Rcm\\Repository\\Site')->disableOriginalConstructor()->getMock(); $mockSiteRepo->expects($this->any())->method('getSites')->will($this->returnValue($mockReturn)); /** @var \Rcm\Repository\Site $mockSiteRepo */ /** @var \Rcm\Service\PluginManager $mockPluginManager */ return new ResourceProvider($this->config, $mockSiteRepo, $currsite); }
/** * Update config place holders with correct data * * @param $item * @param $key * @param $revisionNumber * * @return void */ protected function updatePlaceHolders(&$item, $key, $revisionNumber) { if (empty($this->page)) { return; } $find = [':rcmPageName', ':rcmPageType', ':rcmPageRevision']; $replace = [$this->page->getName(), $this->page->getPageType(), $revisionNumber]; $item = str_replace($find, $replace, $item); }
/** * create * * @param mixed $data * * @return mixed|ApiJsonModel|\Zend\Stdlib\ResponseInterface */ public function create($data) { //ACCESS CHECK if (!$this->rcmIsAllowed('sites', 'admin')) { $this->getResponse()->setStatusCode(Response::STATUS_CODE_401); return $this->getResponse(); } $siteId = $this->getRequestSiteId(); $site = $this->getSite($siteId); if (empty($site)) { return new ApiJsonModel(null, 1, "Site was not found with id {$siteId}."); } // // // $inputFilter = new SitePageDuplicateInputFilter(); $inputFilter->setData($data); if (!$inputFilter->isValid()) { return new ApiJsonModel([], 1, 'Some values are missing or invalid for page duplication.', $inputFilter->getMessages()); } $data = $inputFilter->getValues(); $destinationSite = $this->getSite($data['destinationSiteId']); if (empty($destinationSite)) { return new ApiJsonModel(null, 1, "Destination site was not found with id {$data['destinationSiteId']}."); } $page = $this->getPage($site, $data['pageId']); $newPage = new Page(); $newPage->populate($data); if (empty($page)) { return new ApiJsonModel(null, 1, "Source page was not found with id {$data['pageId']}."); } if ($this->hasPage($destinationSite, $newPage->getName(), $newPage->getPageType())) { return new ApiJsonModel(null, 1, 'Page already exists, duplicates cannot be created'); } // force author to current user $newPage->setAuthor($this->getCurrentAuthor()); try { $newPage = $this->getPageRepo()->copyPage($destinationSite, $page, $newPage->toArray(), null, true); } catch (\Exception $e) { return new ApiJsonModel(null, 1, $e->getMessage()); } $apiResponse = new SitePageApiResponse(); $apiResponse->populate($newPage->toArray()); return new ApiJsonModel($apiResponse, 0, "Success: Duplicated page to site {$data['destinationSiteId']}"); }
/** * isPageAllowedForReading * * @param Page $page * * @return bool */ public function isPageAllowedForReading(Page $page) { $allowed = $this->rcmUserService->isAllowed($this->buildPageResourceId($page->getSite()->getSiteId(), $page->getPageType(), $page->getName()), 'read', 'Rcm\\Acl\\ResourceProvider'); /* ltrim added for BC */ $currentPage = $page->getName(); $siteLoginPage = ltrim($page->getSite()->getLoginPage(), '/'); $notAuthorizedPage = ltrim($page->getSite()->getNotAuthorizedPage(), '/'); $notFoundPage = ltrim($page->getSite()->getNotFoundPage(), '/'); if ($siteLoginPage == $currentPage || $notAuthorizedPage == $currentPage || $notFoundPage == $currentPage) { $allowed = true; } return $allowed; }
/** * Set Site Layout * * @param MvcEvent $event Zend MVC Event object * * @return null */ public function setSiteLayout(MvcEvent $event) { /** @var \Zend\View\Model\ViewModel $viewModel */ $viewModel = $event->getViewModel(); /* Add on for non CMS pages */ $fakePage = new Page(); $fakeRevision = new Revision(); $fakePage->setCurrentRevision($fakeRevision); $currentSite = $this->getCurrentSite(); $viewModel->setVariable('page', $fakePage); $viewModel->setVariable('site', $currentSite); $template = $this->getSiteLayoutTemplate(); $viewModel->setTemplate('layout/' . $template); return null; }
/** * getRevisionLink * * @param Page $page * @param RevisionEntity $revision * * @return string */ public function getRevisionLink(Page $page, RevisionEntity $revision) { $view = $this->getView(); $revisionId = $revision->getRevisionId(); $publishedId = $page->getPublishedRevision(); $stagedId = $page->getStagedRevision(); if (!empty($publishedId) && $publishedId->getRevisionId() == $revision->getRevisionId() || !empty($stagedId) && $stagedId->getRevisionId() == $revision->getRevisionId()) { $revisionId = null; } $html = '<a href="' . $view->urlToPage($page->getName(), $page->getPageType(), $revisionId) . '">'; $html .= $this->getRevisionType($page, $revision) . ' - ' . $revision->getAuthor(); $html .= '</a>'; return $html; }
/** * Set the parent page. Used to generate breadcrumbs or navigation * * @param Page $parent Parent Page Entity * * @return void */ public function setParent(Page $parent) { $this->parent = $parent; $this->parentId = $parent->getPageId(); }
/** * @param $pageName * @param $pageData * * @return \Rcm\Entity\Page */ protected function getNewPage(Site $site, $pageName, $pageData) { $em = $this->entityManager; $page = new Page(); $page->setName($pageName); $page->setAuthor("Create Script"); $page->setCreatedDate(new \DateTime()); $page->setLastPublished(new \DateTime()); $page->setSite($site); if (!empty($pageData['siteLayoutOverride'])) { $page->setSiteLayoutOverride($pageData['siteLayoutOverride']); } if (!empty($pageData['pageTitle'])) { $page->setPageTitle($pageData['pageTitle']); } if (!empty($pageData['description'])) { $page->setPageTitle($pageData['description']); } if (!empty($pageData['keywords'])) { $page->setKeywords($pageData['keywords']); } if (!empty($pageData['pageType'])) { $page->setPageType($pageData['pageType']); } if (!empty($pageData['pageLayout'])) { $page->setPageLayout($pageData['pageLayout']); } else { $page->setPageLayout('default'); } $revision = $this->getNewPageRevision($pageData['containers']); $page->addRevision($revision); $page->setPublishedRevision($revision); $em->persist($page); return $page; }
/** * prepPageRevisionForDisplay * * @param Page $page * @param null $pageRevisionId * * @return void|Response */ public function prepPageRevisionForDisplay(Page $page, $pageRevisionId = null) { // First Check for a page Revision if (!empty($pageRevisionId)) { $userCanSeeRevisions = $this->shouldShowRevisions($page->getSite()->getSiteId(), $page->getName(), $page->getPageType()); if ($userCanSeeRevisions) { $revision = $page->getRevisionById($pageRevisionId); if (!empty($revision) || $revision instanceof Revision) { $page->setCurrentRevision($revision); } return; } else { return $this->redirectToPage($page->getName(), $page->getPageType()); } } // Check for staging if ($this->rcmIsSiteAdmin($page->getSite())) { $revision = $page->getStagedRevision(); if (!empty($revision) || $revision instanceof Revision) { $page->setCurrentRevision($revision); return; } } // Finally look for published revision $revision = $page->getPublishedRevision(); if (!empty($revision) || $revision instanceof Revision) { $page->setCurrentRevision($revision); } return; }
public function testUtilities() { $data = []; $data['name'] = 'testname'; $data['pageTitle'] = 'TESTTITLE'; $data['pageType'] = 'n'; $data['description'] = 'TESTDESC'; $data['keywords'] = 'KEY,WORD'; $data['author'] = 'TESTAUTHOR'; $data['pageLayout'] = 'TESTPAGELAYOUT'; $data['siteLayoutOverride'] = 'TESTLAYOUTOVERRIDE'; $data['parent'] = null; $obj1 = new Page(); $obj1->populate($data); $this->assertEquals($data['name'], $obj1->getName()); $this->assertEquals($data['pageTitle'], $obj1->getPageTitle()); $this->assertEquals($data['pageType'], $obj1->getPageType()); $this->assertEquals($data['description'], $obj1->getDescription()); $this->assertEquals($data['keywords'], $obj1->getKeywords()); $this->assertEquals($data['author'], $obj1->getAuthor()); $this->assertEquals($data['pageLayout'], $obj1->getPageLayout()); $this->assertEquals($data['siteLayoutOverride'], $obj1->getSiteLayoutOverride()); $this->assertEquals($data['parent'], $obj1->getParent()); $data['parent'] = new Page(); $obj1->populate($data); $this->assertEquals($data['parent'], $obj1->getParent()); // $json = json_encode($obj1); $this->assertJson($json); $iterator = $obj1->getIterator(); $this->assertInstanceOf('\\ArrayIterator', $iterator); $array = $obj1->toArray([]); $this->assertEquals($data['name'], $array['name']); $this->assertEquals($data['pageTitle'], $array['pageTitle']); $this->assertEquals($data['pageType'], $array['pageType']); $this->assertEquals($data['description'], $array['description']); $this->assertEquals($data['keywords'], $array['keywords']); $this->assertEquals($data['author'], $array['author']); $this->assertEquals($data['pageLayout'], $array['pageLayout']); $this->assertEquals($data['siteLayoutOverride'], $array['siteLayoutOverride']); $this->assertEquals($data['parent'], $array['parent']); }
/** * Get all Page Resources * * @param Page $page Rcm Page Entity * @param Site $site Rcm Site Entity * * @return mixed */ protected function getPageResources(Page $page, Site $site) { $primaryDomainName = $site->getDomain()->getDomainName(); $siteId = $site->getSiteId(); $pageName = $page->getName(); $pageType = $page->getPageType(); $return['sites.' . $siteId . '.pages.' . $pageType . '.' . $pageName] = ['resourceId' => 'sites.' . $siteId . '.pages.' . $pageType . '.' . $pageName, 'parentResourceId' => 'sites.' . $siteId . '.pages', 'name' => $primaryDomainName . ' - pages - ' . $pageName, 'description' => "Resource for page '{$pageName}'" . " of type '{$pageType}' on site '{$primaryDomainName}'"]; $return['sites.' . $siteId . '.pages.' . $pageType . '.' . $pageName] = array_merge($this->resources['pages'], $return['sites.' . $siteId . '.pages.' . $pageType . '.' . $pageName]); return $return; }
/** * Test Clone * * @return void * * @covers \Rcm\Entity\Site */ public function testClone() { $domain = new Domain(); $domain->setDomainId(23); $language = new Language(); $language->setLanguageId(55); $country = new Country(); $country->setIso3('USA'); $site = ['siteId' => '1000', 'owner' => 'wshafer', 'domain' => $domain, 'theme' => 'theme1', 'siteLayout' => 'layoutOne', 'siteTitle' => 'My Title', 'language' => $language, 'status' => Site::STATUS_ACTIVE, 'favicon' => 'icon.jpg', 'loginRequired' => true, 'loginPage' => 'login.html', 'aclRoles' => 'role1,role2', 'pages' => [0 => ['pageId' => '200', 'name' => 'pageOne', 'author' => 'Westin Shafer', 'createdDate' => new \DateTime('yesterday'), 'lastPublished' => new \DateTime('yesterday'), 'revisions' => [0 => ['revisionId' => 100, 'author' => 'Westin Shafer', 'createdDate' => new \DateTime('yesterday'), 'publishedDate' => new \DateTime('yesterday'), 'published' => true, 'md5' => 'revisionMD5', 'instances' => [0 => ['pluginWrapperId' => 43, 'layoutContainer' => 'layoutOne', 'renderOrder' => 0, 'height' => 32, 'width' => 100, 'divFloat' => 'right', 'instance' => ['pluginInstanceId' => 80, 'plugin' => 'MockPlugin', 'siteWide' => false, 'displayName' => null, 'instanceConfig' => ['var1' => 1, 'var2' => 2], 'md5' => 'firstMd5']], 1 => ['pluginWrapperId' => 45, 'layoutContainer' => 'layoutTwo', 'renderOrder' => 1, 'height' => 33, 'width' => 101, 'divFloat' => 'none', 'instance' => ['pluginInstanceId' => 81, 'plugin' => 'MockPlugin2', 'siteWide' => true, 'displayName' => 'TestSiteWide', 'instanceConfig' => ['var3' => 3, 'var4' => 4], 'md5' => 'secondMd5']]]], 1 => ['revisionId' => 101, 'author' => 'Westin Shafer', 'createdDate' => new \DateTime('-1 month'), 'publishedDate' => new \DateTime('-1 month'), 'published' => false, 'md5' => 'revision2MD5', 'instances' => [0 => ['pluginWrapperId' => 47, 'layoutContainer' => 'layoutThree', 'renderOrder' => 2, 'height' => 33, 'width' => 102, 'divFloat' => 'right', 'instance' => ['pluginInstanceId' => 82, 'plugin' => 'MockPlugin3', 'siteWide' => false, 'displayName' => null, 'instanceConfig' => ['var1' => 1, 'var2' => 2], 'md5' => 'firstMd5']], 1 => ['pluginWrapperId' => 49, 'layoutContainer' => 'layoutFour', 'renderOrder' => 3, 'height' => 34, 'width' => 103, 'divFloat' => 'left', 'instance' => ['pluginInstanceId' => 83, 'plugin' => 'MockPlugin4', 'siteWide' => true, 'displayName' => 'TestSiteWide2', 'instanceConfig' => ['var3' => 3, 'var4' => 4], 'md5' => 'secondMd5']]]]]], 1 => ['pageId' => '200', 'name' => 'pageOne', 'author' => 'Westin Shafer', 'createdDate' => new \DateTime('yesterday'), 'lastPublished' => new \DateTime('yesterday'), 'revisions' => [0 => ['revisionId' => 100, 'author' => 'Westin Shafer', 'createdDate' => new \DateTime('yesterday'), 'publishedDate' => new \DateTime('yesterday'), 'published' => true, 'md5' => 'revisionMD5', 'instances' => [0 => ['pluginWrapperId' => 61, 'layoutContainer' => 'layoutOne', 'renderOrder' => 0, 'height' => 32, 'width' => 100, 'divFloat' => 'right', 'instance' => ['pluginInstanceId' => 84, 'plugin' => 'MockPlugin', 'siteWide' => false, 'displayName' => null, 'instanceConfig' => ['var1' => 1, 'var2' => 2], 'md5' => 'firstMd5']], 1 => ['pluginWrapperId' => 60, 'layoutContainer' => 'layoutTwo', 'renderOrder' => 1, 'height' => 33, 'width' => 101, 'divFloat' => 'none', 'instance' => ['pluginInstanceId' => 85, 'plugin' => 'MockPlugin2', 'siteWide' => true, 'displayName' => 'TestSiteWide', 'instanceConfig' => ['var3' => 3, 'var4' => 4], 'md5' => 'secondMd5']]]], 1 => ['revisionId' => 101, 'author' => 'Westin Shafer', 'createdDate' => new \DateTime('-1 month'), 'publishedDate' => new \DateTime('-1 month'), 'published' => false, 'md5' => 'revision2MD5', 'instances' => [0 => ['pluginWrapperId' => 63, 'layoutContainer' => 'layoutThree', 'renderOrder' => 2, 'height' => 33, 'width' => 102, 'divFloat' => 'right', 'instance' => ['pluginInstanceId' => 86, 'plugin' => 'MockPlugin3', 'siteWide' => false, 'displayName' => null, 'instanceConfig' => ['var1' => 1, 'var2' => 2], 'md5' => 'firstMd5']], 1 => ['pluginWrapperId' => 49, 'layoutContainer' => 'layoutFour', 'renderOrder' => 3, 'height' => 34, 'width' => 103, 'divFloat' => 'left', 'instance' => ['pluginInstanceId' => 87, 'plugin' => 'MockPlugin4', 'siteWide' => true, 'displayName' => 'TestSiteWide2', 'instanceConfig' => ['var3' => 3, 'var4' => 4], 'md5' => 'secondMd5']]]]]]], 'containers' => [0 => ['containerId' => '200', 'name' => 'containerOne', 'author' => 'Westin Shafer', 'createdDate' => new \DateTime('yesterday'), 'lastPublished' => new \DateTime('yesterday'), 'revisions' => [0 => ['revisionId' => 100, 'author' => 'Westin Shafer', 'createdDate' => new \DateTime('yesterday'), 'publishedDate' => new \DateTime('yesterday'), 'published' => true, 'md5' => 'revisionMD5', 'instances' => [0 => ['pluginWrapperId' => 43, 'layoutContainer' => 'layoutOne', 'renderOrder' => 0, 'height' => 32, 'width' => 100, 'divFloat' => 'right', 'instance' => ['pluginInstanceId' => 998, 'plugin' => 'MockPlugin', 'siteWide' => false, 'displayName' => null, 'instanceConfig' => ['var1' => 1, 'var2' => 2], 'md5' => 'firstMd5']], 1 => ['pluginWrapperId' => 45, 'layoutContainer' => 'layoutTwo', 'renderOrder' => 1, 'height' => 33, 'width' => 101, 'divFloat' => 'none', 'instance' => ['pluginInstanceId' => 88, 'plugin' => 'MockPlugin2', 'siteWide' => true, 'displayName' => 'TestSiteWide', 'instanceConfig' => ['var3' => 3, 'var4' => 4], 'md5' => 'secondMd5']]]], 1 => ['revisionId' => 101, 'author' => 'Westin Shafer', 'createdDate' => new \DateTime('-1 month'), 'publishedDate' => new \DateTime('-1 month'), 'published' => false, 'md5' => 'revision2MD5', 'instances' => [0 => ['pluginWrapperId' => 47, 'layoutContainer' => 'layoutThree', 'renderOrder' => 2, 'height' => 33, 'width' => 102, 'divFloat' => 'right', 'instance' => ['pluginInstanceId' => 89, 'plugin' => 'MockPlugin3', 'siteWide' => false, 'displayName' => null, 'instanceConfig' => ['var1' => 1, 'var2' => 2], 'md5' => 'firstMd5']], 1 => ['pluginWrapperId' => 49, 'layoutContainer' => 'layoutFour', 'renderOrder' => 3, 'height' => 34, 'width' => 103, 'divFloat' => 'left', 'instance' => ['pluginInstanceId' => 90, 'plugin' => 'MockPlugin4', 'siteWide' => true, 'displayName' => 'TestSiteWide2', 'instanceConfig' => ['var3' => 3, 'var4' => 4], 'md5' => 'secondMd5']]]]]], 1 => ['containerId' => '200', 'name' => 'containerOne', 'author' => 'Westin Shafer', 'createdDate' => new \DateTime('yesterday'), 'lastPublished' => new \DateTime('yesterday'), 'revisions' => [0 => ['revisionId' => 100, 'author' => 'Westin Shafer', 'createdDate' => new \DateTime('yesterday'), 'publishedDate' => new \DateTime('yesterday'), 'published' => true, 'md5' => 'revisionMD5', 'instances' => [0 => ['pluginWrapperId' => 43, 'layoutContainer' => 'layoutOne', 'renderOrder' => 0, 'height' => 32, 'width' => 100, 'divFloat' => 'right', 'instance' => ['pluginInstanceId' => 91, 'plugin' => 'MockPlugin', 'siteWide' => false, 'displayName' => null, 'instanceConfig' => ['var1' => 1, 'var2' => 2], 'md5' => 'firstMd5']], 1 => ['pluginWrapperId' => 45, 'layoutContainer' => 'layoutTwo', 'renderOrder' => 1, 'height' => 33, 'width' => 101, 'divFloat' => 'none', 'instance' => ['pluginInstanceId' => 92, 'plugin' => 'MockPlugin2', 'siteWide' => true, 'displayName' => 'TestSiteWide', 'instanceConfig' => ['var3' => 3, 'var4' => 4], 'md5' => 'secondMd5']]]], 1 => ['revisionId' => 101, 'author' => 'Westin Shafer', 'createdDate' => new \DateTime('-1 month'), 'publishedDate' => new \DateTime('-1 month'), 'published' => false, 'md5' => 'revision2MD5', 'instances' => [0 => ['pluginWrapperId' => 47, 'layoutContainer' => 'layoutThree', 'renderOrder' => 2, 'height' => 33, 'width' => 102, 'divFloat' => 'right', 'instance' => ['pluginInstanceId' => 93, 'plugin' => 'MockPlugin3', 'siteWide' => false, 'displayName' => null, 'instanceConfig' => ['var1' => 1, 'var2' => 2], 'md5' => 'firstMd5']], 1 => ['pluginWrapperId' => 49, 'layoutContainer' => 'layoutFour', 'renderOrder' => 3, 'height' => 34, 'width' => 103, 'divFloat' => 'left', 'instance' => ['pluginInstanceId' => 94, 'plugin' => 'MockPlugin4', 'siteWide' => true, 'displayName' => 'TestSiteWide2', 'instanceConfig' => ['var3' => 3, 'var4' => 4], 'md5' => 'secondMd5']]]]]]]]; $this->site->setSiteId($site['siteId']); $this->site->setDomain($site['domain']); $this->site->setTheme($site['theme']); $this->site->setSiteLayout($site['siteLayout']); $this->site->setSiteTitle($site['siteTitle']); $this->site->setLanguage($site['language']); $this->site->setStatus($site['status']); $this->site->setFavIcon($site['favicon']); $this->site->setLoginPage($site['loginPage']); foreach ($site['pages'] as $page) { $pageEntity = new Page(); $pageEntity->setPageId($page['pageId']); $pageEntity->setName($page['name']); $pageEntity->setAuthor($page['author']); $pageEntity->setCreatedDate($page['createdDate']); $pageEntity->setLastPublished($page['lastPublished']); $pageEntity->setSite($this->site); foreach ($page['revisions'] as $index => $revisionData) { $revision = $this->getRevision($revisionData); if ($index === 0) { $pageEntity->setPublishedRevision($revision); } elseif ($index === 1) { $pageEntity->setStagedRevision($revision); } $pageEntity->addRevision($revision); } $this->site->addPage($pageEntity); } foreach ($site['containers'] as $container) { $containerEntity = new Container(); $containerEntity->setContainerId($container['containerId']); $containerEntity->setName($container['name']); $containerEntity->setAuthor($container['author']); $containerEntity->setCreatedDate($container['createdDate']); $containerEntity->setLastPublished($container['lastPublished']); $containerEntity->setSite($this->site); foreach ($container['revisions'] as $index => $revisionData) { $revision = $this->getRevision($revisionData); if ($index === 0) { $containerEntity->setPublishedRevision($revision); } elseif ($index === 1) { $containerEntity->setStagedRevision($revision); } $containerEntity->addRevision($revision); } $this->site->addContainer($containerEntity); } /** Test site entity is setup correctly */ $this->assertCount(1, $this->site->getPages()); $this->assertCount(1, $this->site->getContainers()); $original = $this->site; $cloned = clone $this->site; $this->assertNotEquals($original->getSiteId(), $cloned->getSiteId()); $this->assertNull($cloned->getSiteId()); $this->assertNull($cloned->getDomain()); $this->assertEquals($original->getTheme(), $cloned->getTheme()); $this->assertEquals($original->getSiteLayout(), $cloned->getSiteLayout()); $this->assertEquals($original->getSiteTitle(), $cloned->getSiteTitle()); $this->assertEquals($original->getLanguage(), $cloned->getLanguage()); $this->assertEquals($original->getStatus(), $cloned->getStatus()); $this->assertEquals($original->getFavIcon(), $cloned->getFavIcon()); $this->assertEquals($original->getLoginPage(), $cloned->getLoginPage()); $clonedPages = $cloned->getPages(); /** @var \Rcm\Entity\Page $page */ foreach ($clonedPages as $page) { $this->assertNull($page->getPageId()); $clonedRevision = $page->getPublishedRevision(); if (empty($clonedRevision)) { continue; } $this->assertNull($clonedRevision->getRevisionId()); $clonedWrappers = $clonedRevision->getPluginWrappers(); /** @var \Rcm\Entity\PluginWrapper $wrapper */ foreach ($clonedWrappers as $wrapper) { $this->assertNull($wrapper->getPluginWrapperId()); $this->assertNull($wrapper->getInstance()->getInstanceId()); } } $clonedContainers = $cloned->getContainers(); /** @var \Rcm\Entity\Container $container */ foreach ($clonedContainers as $container) { $this->assertNull($container->getContainerId()); $clonedRevision = $container->getPublishedRevision(); if (empty($clonedRevision)) { continue; } $this->assertNull($clonedRevision->getRevisionId()); $clonedWrappers = $clonedRevision->getPluginWrappers(); /** @var \Rcm\Entity\PluginWrapper $wrapper */ foreach ($clonedWrappers as $wrapper) { $this->assertNull($wrapper->getPluginWrapperId()); $this->assertNull($wrapper->getInstance()->getInstanceId()); } } }
/** * Get Test Page Data for Page Repo Mocks * * @param integer $pageId PageID * @param integer $pageName PageName * @param integer $revisionId RevisionId * @param string $pageType PageType * @param boolean $useStaged Use staged revision instead of published * @param string $siteLayoutOverride Layout Override * * @return array */ protected function getPageData($pageId, $pageName, $revisionId, $pageType = 'n', $useStaged = false, $siteLayoutOverride = null) { $country = new Country(); $country->setCountryName('United States'); $country->setIso2('US'); $country->setIso3('USA'); $language = new Language(); $language->setLanguageId(1); $language->setIso6391('en'); $language->setIso6392b('eng'); $language->setIso6392t('eng'); $domain = new Domain(); $domain->setDomainId(1); $domain->setDomainName('reliv.com'); $site = new Site(); $site->setSiteId(1); $site->setCountry($country); $site->setLanguage($language); $site->setLoginPage('login'); $site->setNotFoundPage('not-found'); $site->setDomain($domain); $revision = new Revision(); $revision->setRevisionId($revisionId); $revision->setAuthor('Westin Shafer'); $revision->setCreatedDate(new \DateTime()); $revision->setPublishedDate(new \DateTime()); $page = new Page(); $page->setSite($site); $page->setName($pageName); $page->setPageId($pageId); $page->setPageType($pageType); $page->addRevision($revision); $page->setPublishedRevision($revision); if ($useStaged) { $page->setStagedRevision($revision); } $page->setPageId(22); $page->setSiteLayoutOverride($siteLayoutOverride); return $page; }
/** * getPageContainerHtmlByName * * @param Page $page * @param string $name * * @return string */ protected function getPageContainerHtmlByName(Page $page, $name) { $revision = $page->getCurrentRevision(); if (empty($revision)) { throw new PageNotFoundException('No revision found for this page.'); } $pluginWrapperRows = $revision->getPluginWrappersByPageContainerName($name); $pluginHtml = ''; if (!empty($pluginWrapperRows) && is_array($pluginWrapperRows)) { $pluginHtml = $this->getPluginRowsHtml($pluginWrapperRows); } return $this->getContainerWrapperHtml($revision->getRevisionId(), $name, $pluginHtml, true); }
/** * 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 */ 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['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 = clone $pageToCopy; $clonedPage->populate($pageData); $revisionToUse = $clonedPage->getStagedRevision(); if (!empty($pageRevisionId)) { $sourceRevision = $pageToCopy->getRevisionById($pageRevisionId); if (empty($sourceRevision)) { throw new PageNotFoundException('Page revision not found.'); } $revisionToUse = clone $sourceRevision; $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; }