/** * 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; }
/** * Test Clone * * @return void * * @covers \Rcm\Entity\Revision */ public function testClone() { $revision = ['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' => 44, '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' => 46, 'plugin' => 'MockPlugin2', 'siteWide' => true, 'displayName' => 'TestSiteWide', 'instanceConfig' => ['var3' => 3, 'var4' => 4], 'md5' => 'secondMd5']]]]; $this->revision->setRevisionId($revision['revisionId']); $this->revision->setAuthor($revision['author']); $this->revision->setCreatedDate($revision['createdDate']); $this->revision->publishRevision(); $this->revision->setPublishedDate($revision['publishedDate']); $this->revision->setMd5($revision['md5']); foreach ($revision['instances'] as $instance) { $plugin = new PluginInstance(); $plugin->setInstanceId($instance['instance']['pluginInstanceId']); $plugin->setPlugin($instance['instance']['plugin']); if ($instance['instance']['siteWide']) { $plugin->setSiteWide(); } $plugin->setDisplayName($instance['instance']['displayName']); $plugin->setInstanceConfig($instance['instance']['instanceConfig']); $plugin->setMd5($instance['instance']['md5']); $wrapper = new PluginWrapper(); $wrapper->setPluginWrapperId($instance['pluginWrapperId']); $wrapper->setLayoutContainer($instance['layoutContainer']); $wrapper->setRenderOrderNumber($instance['renderOrder']); $wrapper->setHeight($instance['height']); $wrapper->setWidth($instance['width']); $wrapper->setDivFloat($instance['divFloat']); $wrapper->setInstance($plugin); $this->revision->addPluginWrapper($wrapper); } $clonedRevision = clone $this->revision; /* Test Revision */ $this->assertNotEquals($this->revision->getRevisionId(), $clonedRevision->getRevisionId()); $this->assertNull($clonedRevision->getRevisionId()); $this->assertEquals($this->revision->getAuthor(), $clonedRevision->getAuthor()); $this->assertNotEquals($this->revision->getCreatedDate(), $clonedRevision->getCreatedDate()); $this->assertNotEquals($this->revision->getPublishedDate(), $clonedRevision->getPublishedDate()); $this->assertTrue($this->revision->wasPublished()); $this->assertEquals($this->revision->getMd5(), $clonedRevision->getMd5()); $clonedWrappers = $clonedRevision->getPluginWrappers(); $revisionWrappers = $this->revision->getPluginWrappers(); $this->assertNotEquals($revisionWrappers, $clonedWrappers); /** @var \Rcm\Entity\PluginWrapper $clonedWrapper */ foreach ($clonedWrappers as $clonedWrapper) { if (!$clonedWrapper->getInstance()->isSiteWide()) { $this->assertNull($clonedWrapper->getInstance()->getInstanceId()); } else { $this->assertNotNull($clonedWrapper->getInstance()->getInstanceId()); } } }
/** * @param array $data * * @return \Rcm\Entity\Revision */ protected function getNewRevision($data) { $em = $this->entityManager; $revision = new Revision(); $revision->setAuthor('Create Script'); $revision->setCreatedDate(new \DateTime()); $revision->setPublishedDate(new \DateTime()); foreach ($data as $pluginName => $pluginData) { $pluginWrapper = $this->getNewPluginWrapper($pluginName, $pluginData); $revision->addPluginWrapper($pluginWrapper); } $em->persist($revision); return $revision; }
/** * Sets the staged revision * * @param Revision $revision Revision object to add * * @return null */ public function setStagedRevision(Revision $revision) { if (!empty($this->publishedRevision) && $this->publishedRevision->getRevisionId() == $revision->getRevisionId()) { $this->removePublishedRevision(); } $this->stagedRevision = $revision; $this->stagedRevisionId = $revision->getRevisionId(); }
/** * saveContainer * * @param ContainerEntityInterface $container * @param array $containerData * @param string $author * @param null $revisionNumber * * @return int|null */ public function saveContainer(ContainerEntityInterface $container, $containerData, $author, $revisionNumber = null) { $revision = null; $publishRevision = false; if (empty($revisionNumber)) { $revision = $container->getPublishedRevision(); $publishRevision = true; } else { $revision = $container->getRevisionById($revisionNumber); } $md5 = md5(serialize($containerData)); if (!empty($revision)) { if ($revision->getMd5() == $md5) { return null; } } $site = $container->getSite(); $newRevision = new Revision(); $newRevision->setAuthor($author); $newRevision->setMd5($md5); $isDirty = false; /** @var \Rcm\Repository\PluginWrapper $pluginWrapperRepo */ $pluginWrapperRepo = $this->_em->getRepository('\\Rcm\\Entity\\PluginWrapper'); //Make a list of original wrappers so we can see if one was removed $deletedWrapperIds = []; if ($revision) { foreach ($revision->getPluginWrappers() as $wrapper) { $deletedWrapperIds[$wrapper->getPluginWrapperId()] = true; } } if (empty($containerData)) { $isDirty = true; } else { foreach ($containerData as $pluginData) { $pluginWrapper = null; if (!empty($revision)) { /** @var \Rcm\Entity\PluginWrapper $pluginWrapper */ $pluginWrapper = $revision->getPluginWrapper($pluginData['instanceId']); if ($pluginWrapper && isset($deletedWrapperIds[$pluginWrapper->getPluginWrapperId()])) { unset($deletedWrapperIds[$pluginWrapper->getPluginWrapperId()]); } } $newPluginWrapper = $pluginWrapperRepo->savePluginWrapper($pluginData, $site, $pluginWrapper); $newRevision->addPluginWrapper($newPluginWrapper); if (!empty($pluginWrapper) && $pluginWrapper->getPluginWrapperId() == $newPluginWrapper->getPluginWrapperId() && ($pluginWrapper->getInstance()->getInstanceId() == $newPluginWrapper->getInstance()->getInstanceId() || $pluginWrapper->getInstance()->isSiteWide())) { continue; } $isDirty = true; } } if (count($deletedWrapperIds)) { $isDirty = true; } if ($isDirty) { $this->_em->persist($newRevision); $this->_em->flush($newRevision); $container->addRevision($newRevision); if ($publishRevision) { $newRevision->publishRevision(); $container->setPublishedRevision($newRevision); } $stagedRevision = $container->getStagedRevision(); if (!empty($stagedRevision) && $revision->getRevisionId() == $stagedRevision->getRevisionId()) { $container->setStagedRevision($newRevision); } $this->_em->flush($container); return $newRevision->getRevisionId(); } return null; }
/** * Test Clone * * @return void * * @covers \Rcm\Entity\Page */ public function testClone() { $site = new Site(); $site->setSiteId(55); $container = ['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' => 44, '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' => 46, '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' => 48, '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' => 50, 'plugin' => 'MockPlugin4', 'siteWide' => true, 'displayName' => 'TestSiteWide2', 'instanceConfig' => ['var3' => 3, 'var4' => 4], 'md5' => 'secondMd5']]]]]]; $this->page->setPageId($container['pageId']); $this->page->setName($container['name']); $this->page->setAuthor($container['author']); $this->page->setCreatedDate($container['createdDate']); $this->page->setLastPublished($container['lastPublished']); $this->page->setSite($site); foreach ($container['revisions'] as $index => $revisionData) { $revision = new Revision(); $revision->setRevisionId($revisionData['revisionId']); $revision->setAuthor($revisionData['author']); $revision->setCreatedDate($revisionData['createdDate']); $revision->publishRevision(); $revision->setPublishedDate($revisionData['publishedDate']); $revision->setMd5($revisionData['md5']); foreach ($revisionData['instances'] as $instance) { $plugin = new PluginInstance(); $plugin->setInstanceId($instance['instance']['pluginInstanceId']); $plugin->setPlugin($instance['instance']['plugin']); if ($instance['instance']['siteWide']) { $plugin->setSiteWide(); } $plugin->setDisplayName($instance['instance']['displayName']); $plugin->setInstanceConfig($instance['instance']['instanceConfig']); $plugin->setMd5($instance['instance']['md5']); $wrapper = new PluginWrapper(); $wrapper->setPluginWrapperId($instance['pluginWrapperId']); $wrapper->setLayoutContainer($instance['layoutContainer']); $wrapper->setRenderOrderNumber($instance['renderOrder']); $wrapper->setHeight($instance['height']); $wrapper->setWidth($instance['width']); $wrapper->setDivFloat($instance['divFloat']); $wrapper->setInstance($plugin); $revision->addPluginWrapper($wrapper); } if ($index === 0) { $this->page->setPublishedRevision($revision); } elseif ($index === 1) { $this->page->setStagedRevision($revision); } $this->page->addRevision($revision); } $this->assertCount(2, $this->page->getRevisions()); $clonedContainer = clone $this->page; /* Test Container */ $this->assertNotEquals($this->page->getPageId(), $clonedContainer->getPageId()); $this->assertNull($clonedContainer->getPageId()); $this->assertNull($clonedContainer->getPublishedRevision()); $this->assertCount(1, $clonedContainer->getRevisions()); $containerName = $clonedContainer->getName(); $containerIsempty = empty($containerName); $this->assertTrue($containerIsempty); $this->assertNull($clonedContainer->getParent()); $currentRevision = $this->page->getPublishedRevision(); $clonedCurrentRev = $clonedContainer->getStagedRevision(); /* Test Revision */ $this->assertNotEquals($currentRevision->getRevisionId(), $clonedCurrentRev->getRevisionId()); $this->assertNull($clonedCurrentRev->getRevisionId()); $this->assertEquals($currentRevision->getAuthor(), $clonedCurrentRev->getAuthor()); $this->assertNotEquals($currentRevision->getCreatedDate(), $clonedCurrentRev->getCreatedDate()); $this->assertFalse($clonedCurrentRev->wasPublished()); $this->assertEquals($currentRevision->getMd5(), $clonedCurrentRev->getMd5()); $revisionWrappers = $currentRevision->getPluginWrappers(); $clonedWrappers = $clonedCurrentRev->getPluginWrappers(); $this->assertNotEquals($revisionWrappers, $clonedWrappers); /** @var \Rcm\Entity\PluginWrapper $clonedWrapper */ foreach ($clonedWrappers as $clonedWrapper) { if (!$clonedWrapper->getInstance()->isSiteWide()) { $this->assertNull($clonedWrapper->getInstance()->getInstanceId()); } else { $this->assertNotNull($clonedWrapper->getInstance()->getInstanceId()); } } $page = new Page(); $clone = clone $page; $this->assertInstanceOf('\\Rcm\\Entity\\Page', $clone); }
/** * Get a container revision * * @param $revisionData * * @return Revision */ private function getRevision($revisionData) { $revision = new Revision(); $revision->setRevisionId($revisionData['revisionId']); $revision->setAuthor($revisionData['author']); $revision->setCreatedDate($revisionData['createdDate']); $revision->publishRevision(); $revision->setPublishedDate($revisionData['publishedDate']); $revision->setMd5($revisionData['md5']); foreach ($revisionData['instances'] as $instance) { $plugin = new PluginInstance(); $plugin->setInstanceId($instance['instance']['pluginInstanceId']); $plugin->setPlugin($instance['instance']['plugin']); $plugin->setDisplayName($instance['instance']['displayName']); $plugin->setInstanceConfig($instance['instance']['instanceConfig']); $plugin->setMd5($instance['instance']['md5']); if ($instance['instance']['siteWide']) { $plugin->setSiteWide(); $this->site->addSiteWidePlugin($plugin); } $wrapper = new PluginWrapper(); $wrapper->setPluginWrapperId($instance['pluginWrapperId']); $wrapper->setLayoutContainer($instance['layoutContainer']); $wrapper->setRenderOrderNumber($instance['renderOrder']); $wrapper->setHeight($instance['height']); $wrapper->setWidth($instance['width']); $wrapper->setDivFloat($instance['divFloat']); $wrapper->setInstance($plugin); $revision->addPluginWrapper($wrapper); } return $revision; }
/** * 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; }
/** * fixRevisionSiteWides * * @param Revision $revision * @param array $siteWideIdsToChange * * @return void */ protected function fixRevisionSiteWides(Revision $revision, $siteWideIdsToChange) { $pluginWrappers = $revision->getPluginWrappers(); /** @var \Rcm\Entity\PluginWrapper $pluginWrapper */ foreach ($pluginWrappers as $pluginWrapper) { $instanceId = $pluginWrapper->getInstance()->getInstanceId(); if (isset($siteWideIdsToChange[$instanceId]) && $siteWideIdsToChange[$instanceId] instanceof PluginInstance) { $pluginWrapper->setInstance($siteWideIdsToChange[$instanceId]); } } }
/** * createPage * * @param SiteEntity $site * @param array $pageData * @param bool $publishPage * @param bool $doFlush * * @return PageEntity * @throws \Exception */ public function createPage(SiteEntity $site, $pageData, $publishPage = false, $doFlush = true) { if (empty($pageData['author'])) { throw new \Exception('Author is required to create a page.'); } $revision = new Revision(); $revision->setAuthor($pageData['author']); $revision->setCreatedDate(new \DateTime()); // we should not have an Id on page create unset($pageData['pageId']); $page = new PageEntity(); $page->populate($pageData); $page->setCreatedDate(new \DateTime()); $page->setSite($site); if (!$publishPage) { $page->setStagedRevision($revision); } else { $page->setPublishedRevision($revision); } $page->addRevision($revision); $this->_em->persist($revision); $this->_em->persist($page); if ($doFlush) { $this->_em->flush([$revision, $page]); } return $page; }