예제 #1
0
 /**
  * @param PageInterface $draftPage
  * @param \JMS\Serializer\Serializer $serializer
  * @return PageInterface
  */
 public function revertToPublished(PageInterface $draftPage, \JMS\Serializer\SerializerInterface $serializer)
 {
     $pageSnapshot = $draftPage->getSnapshot();
     $contentRoute = $draftPage->getContentRoute();
     /** @var $publishedPage PageInterface */
     $publishedPage = $serializer->deserialize($pageSnapshot->getVersionedData(), $this->getClassName(), 'json');
     // Save the layout blocks in a temp variable so that we can
     // assure the correct layout blocks will be saved and not
     // merged with the layout blocks from the draft page
     $tmpLayoutBlocks = $publishedPage->getLayoutBlock();
     // tell the entity manager to handle our published page
     // as if it came from the DB and not a serialized object
     $publishedPage = $this->_em->merge($publishedPage);
     $contentRoute->setTemplate($pageSnapshot->getContentRoute()->getTemplate());
     $contentRoute->setTemplateName($pageSnapshot->getContentRoute()->getTemplateName());
     $contentRoute->setController($pageSnapshot->getContentRoute()->getController());
     $contentRoute->setPath($pageSnapshot->getContentRoute()->getPath());
     $this->_em->merge($contentRoute);
     $publishedPage->setContentRoute($contentRoute);
     // Set the layout blocks of the NOW managed entity to
     // exactly that of the published version
     $publishedPage->resetLayoutBlock($tmpLayoutBlocks);
     $this->_em->flush();
     return $publishedPage;
 }