/**
  * @param RefreshEvent $event
  */
 public function handleRefresh(RefreshEvent $event)
 {
     $document = $event->getDocument();
     $node = $this->documentRegistry->getNodeForDocument($document);
     $locale = $this->documentRegistry->getLocaleForDocument($document);
     // revert/reload the node to the persisted state
     $node->revert();
     // rehydrate the document
     $hydrateEvent = new HydrateEvent($node, $locale);
     $hydrateEvent->setDocument($document);
     $this->eventDispatcher->dispatch(Events::HYDRATE, $hydrateEvent);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function save($webspaceKey, $type, $uuid, $locale)
 {
     /** @var SnippetDocument $document */
     $document = $this->documentManager->find($uuid, $locale);
     if (!$document) {
         throw new SnippetNotFoundException($uuid);
     }
     if ($document->getStructureType() !== $type) {
         throw new WrongSnippetTypeException($document->getStructureType(), $type, $document);
     }
     $this->settingsManager->save($webspaceKey, 'snippets-' . $type, $this->registry->getNodeForDocument($document));
     return $document;
 }
 /**
  * Handle the reorder operation.
  *
  * @param ReorderEvent $event
  *
  * @throws DocumentManagerException
  */
 public function handleReorder(ReorderEvent $event)
 {
     $document = $event->getDocument();
     $siblingId = $event->getDestId();
     $after = $event->getAfter();
     $node = $this->documentRegistry->getNodeForDocument($document);
     $parentNode = $node->getParent();
     $nodeName = $node->getName();
     $siblingName = $this->resolveSiblingName($siblingId, $parentNode, $node);
     if (true === $after) {
         $siblingName = $this->resolveAfterSiblingName($parentNode, $siblingName);
     }
     $parentNode->orderBefore($nodeName, $siblingName);
 }
 /**
  * The node should be available from the event.
  */
 public function testReorderNodeFomRegistry()
 {
     $reorderEvent = $this->prophesize(ReorderEvent::class);
     $reorderEvent->hasNode()->willReturn(false);
     $reorderEvent->getDocument()->willReturn($this->document);
     $this->registry->hasDocument($this->document)->willReturn(true);
     $this->registry->getNodeForDocument($this->document)->willReturn($this->node->reveal());
     $reorderEvent->setNode($this->node->reveal())->shouldBeCalled();
     $this->subscriber->handleNodeFromRegistry($reorderEvent->reveal());
 }
 /**
  * If the node for the persisted document is in the registry.
  *
  * @param PersistEvent|ReorderEvent $event
  */
 public function handleNodeFromRegistry($event)
 {
     if ($event->hasNode()) {
         return;
     }
     $document = $event->getDocument();
     if (!$this->documentRegistry->hasDocument($document)) {
         return;
     }
     $node = $this->documentRegistry->getNodeForDocument($document);
     $event->setNode($node);
 }
 /**
  * Resolve the destination name on move and copy events.
  *
  * @param MoveEvent $event
  */
 private function handleMoveCopy(MoveEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof AutoNameBehavior) {
         return;
     }
     $destId = $event->getDestId();
     $node = $this->registry->getNodeForDocument($document);
     $destNode = $this->nodeManager->find($destId);
     $nodeName = $this->resolver->resolveName($destNode, $node->getName());
     $event->setDestName($nodeName);
 }
Ejemplo n.º 7
0
 /**
  * Loops all documents and imports all properties of the documents.
  *
  * @param BasePageDocument $document
  * @param string $structureType
  * @param string $webspaceKey
  * @param string $locale
  * @param string $format
  * @param array $data
  */
 protected function setDocumentData(BasePageDocument $document, $structureType, $webspaceKey, $locale, $format, $data)
 {
     $structure = $this->structureManager->getStructure($structureType);
     $properties = $structure->getProperties(true);
     $node = $this->documentRegistry->getNodeForDocument($document);
     $node->setProperty(sprintf('i18n:%s-template', $locale), $structureType);
     $state = $this->getParser($format)->getPropertyData('state', $data, null, null, 2);
     $node->setProperty(sprintf('i18n:%s-state', $locale), $state);
     if ($this->getParser($format)->getPropertyData('title', $data) === '') {
         $this->addException(sprintf('Document(%s) has not set any title', $document->getUuid()), 'ignore');
         return false;
     }
     // import all content data
     foreach ($properties as $property) {
         $value = $this->getParser($format)->getPropertyData($property->getName(), $data, $property->getContentTypeName());
         // don't generate a new url when one exists
         $doImport = true;
         if ($property->getContentTypeName() == 'resource_locator') {
             $doImport = false;
             if (!$document->getResourceSegment()) {
                 $doImport = true;
                 $parent = $document->getParent();
                 if ($parent instanceof BasePageDocument) {
                     $parentUuid = $parent->getUuid();
                     $value = $this->generateUrl($structure->getPropertiesByTagName('sulu.rlp.part'), $parentUuid, $webspaceKey, $locale, $format, $data);
                 }
             }
         }
         // import property data
         if ($doImport) {
             $this->importProperty($property, $node, $structure, $value, $webspaceKey, $locale, $format);
         }
     }
     // import extensions
     $extensions = $this->extensionManager->getExtensions($structureType);
     foreach ($extensions as $key => $extension) {
         $this->importExtension($extension, $key, $node, $data, $webspaceKey, $locale, $format);
     }
     // set required data
     $document->setTitle($this->getParser($format)->getPropertyData('title', $data));
     return true;
 }
 /**
  * Remove the given documents node from PHPCR session and optionally
  * remove any references to the node.
  *
  * @param RemoveEvent $event
  */
 public function handleRemove(RemoveEvent $event)
 {
     $document = $event->getDocument();
     $node = $this->documentRegistry->getNodeForDocument($document);
     $node->remove();
 }
Ejemplo n.º 9
0
 /**
  * Create a new collection of referrers from a list of referencing items.
  *
  * @param $document
  *
  * @return ReferrerCollection
  */
 public function createReferrerCollection($document)
 {
     $node = $this->registry->getNodeForDocument($document);
     $locale = $this->registry->getOriginalLocaleForDocument($document);
     return new ReferrerCollection($node, $this->dispatcher, $locale);
 }
 /**
  * Return the UUID of the given document.
  *
  * @param object $document
  *
  * @return string
  */
 public function getUuid($document)
 {
     return $this->documentRegistry->getNodeForDocument($document)->getIdentifier();
 }