Networking\InitCmsBundle\Helper\PageHelper::makePageSnapshot PHP Method

makePageSnapshot() public method

Create a snapshot of a given page.
public makePageSnapshot ( Networking\InitCmsBundle\Model\PageInterface $page )
$page Networking\InitCmsBundle\Model\PageInterface
    public function makePageSnapshot(PageInterface $page)
    {
        /** @var \JMS\Serializer\SerializerInterface $serializer */
        $serializer = $this->getService('serializer');
        if ($this->getParameter('networking_init_cms.db_driver') == 'orm') {
            /** @var \Doctrine\Common\Persistence\ObjectManager $em */
            $em = $this->getService('doctrine')->getManager();
        } else {
            /** @var \Doctrine\Common\Persistence\ObjectManager $manager */
            $em = $this->getService('doctrine_mongodb')->getManager();
        }
        foreach ($page->getLayoutBlock() as $layoutBlock) {
            /** @var \Networking\InitCmsBundle\Model\layoutBlockInterface $layoutBlock */
            $layoutBlockContent = $em->getRepository($layoutBlock->getClassType())->find($layoutBlock->getObjectId());
            $layoutBlock->takeSnapshot($serializer->serialize($layoutBlockContent, 'json'));
        }
        /**  @var  \Networking\InitCmsBundle\Model\PageSnapshotManagerInterface $pageSnapshotManager */
        $pageSnapshotManager = $this->getService('networking_init_cms.page_snapshot_manager');
        $pageSnapshotClass = $pageSnapshotManager->getClassName();
        /** @var  \Networking\InitCmsBundle\Model\PageSnapshotInterface $pageSnapshot */
        $pageSnapshot = new $pageSnapshotClass($page);
        $pageSnapshot->setVersionedData($serializer->serialize($page, 'json'))->setPage($page);
        if ($oldPageSnapshot = $page->getSnapshot()) {
            $snapshotContentRoute = $oldPageSnapshot->getContentRoute();
        } else {
            $contentRouteManager = $this->getService('networking_init_cms.content_route_manager');
            $contentRouteClass = $contentRouteManager->getClass();
            /** @var  \Networking\InitCmsBundle\Model\ContentRouteInterface $snapshotContentRoute */
            $snapshotContentRoute = new $contentRouteClass();
        }
        $pageSnapshot->setContentRoute($snapshotContentRoute);
        $pageSnapshot->setPath(self::getPageRoutePath($page->getPath()));
        $em->persist($pageSnapshot);
        $em->flush();
        $snapshotContentRoute->setPath(self::getPageRoutePath($page->getPath()));
        $snapshotContentRoute->setObjectId($pageSnapshot->getId());
        if ($oldPageSnapshot && $oldPageSnapshot->getPath() != self::getPageRoutePath($page->getPath())) {
            /** @var \Networking\InitCmsBundle\Lib\PhpCacheInterface $phpCache */
            $phpCache = $this->getService('networking_init_cms.lib.php_cache');
            $phpCache->clean();
        }
        $em->persist($snapshotContentRoute);
        $em->flush();
    }