コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function handlePersist(PersistEvent $event)
 {
     $locale = $event->getLocale();
     if (!$locale) {
         return;
     }
     $document = $event->getDocument();
     if (!$document instanceof ExtensionBehavior) {
         return;
     }
     $structureType = $document->getStructureType();
     $node = $event->getNode();
     $extensionsData = $document->getExtensionsData();
     $webspaceName = $this->inspector->getWebspace($document);
     $prefix = $this->namespaceRegistry->getPrefix('extension_localized');
     $extensions = $this->extensionManager->getExtensions($structureType);
     foreach ($extensions as $extension) {
         $extensionData = null;
         if (!isset($extensionsData[$extension->getName()])) {
             continue;
         }
         $extensionData = $extensionsData[$extension->getName()];
         $extension->setLanguageCode($locale, $prefix, $this->internalPrefix);
         $extension->save($node, $extensionData, $webspaceName, $locale);
     }
     $this->hydrate($event);
 }
コード例 #2
0
 /**
  * @param PersistEvent $event
  *
  * @throws DocumentManagerException
  */
 public function handlePersist(PersistEvent $event)
 {
     $options = $event->getOptions();
     $this->validateOptions($options);
     $document = $event->getDocument();
     $parentPath = null;
     $nodeName = null;
     if ($options['path']) {
         $parentPath = PathHelper::getParentPath($options['path']);
         $nodeName = PathHelper::getNodeName($options['path']);
     }
     if ($options['parent_path']) {
         $parentPath = $options['parent_path'];
     }
     if ($parentPath) {
         $event->setParentNode($this->resolveParent($parentPath, $options));
     }
     if ($options['node_name']) {
         if (!$event->hasParentNode()) {
             throw new DocumentManagerException(sprintf('The "node_name" option can only be used either with the "parent_path" option ' . 'or when a parent node has been established by a previous subscriber. ' . 'When persisting document: %s', DocumentHelper::getDebugTitle($document)));
         }
         $nodeName = $options['node_name'];
     }
     if (!$nodeName) {
         return;
     }
     if ($event->hasNode()) {
         $this->renameNode($event->getNode(), $nodeName);
         return;
     }
     $node = $this->strategy->createNodeForDocument($document, $event->getParentNode(), $nodeName);
     $event->setNode($node);
 }
コード例 #3
0
ファイル: RouteSubscriber.php プロジェクト: sulu/sulu
 /**
  * Updates the route for the given document and creates history routes if necessary.
  *
  * @param PersistEvent $event
  */
 public function handlePersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof RouteBehavior) {
         return;
     }
     $node = $event->getNode();
     $node->setProperty(self::NODE_HISTORY_FIELD, $document->isHistory());
     $targetDocument = $document->getTargetDocument();
     if ($targetDocument instanceof HomeDocument || !$targetDocument instanceof WebspaceBehavior || !$targetDocument instanceof ResourceSegmentBehavior) {
         return;
     }
     // copy new route to old position
     $webspaceKey = $targetDocument->getWebspaceName();
     $locale = $this->documentInspector->getLocale($document);
     $routePath = $this->sessionManager->getRoutePath($webspaceKey, $locale, null) . $targetDocument->getResourceSegment();
     // create a route node if it is not a new document and the path changed
     $documentPath = $this->documentInspector->getPath($document);
     if ($documentPath && $documentPath != $routePath) {
         /** @var RouteDocument $newRouteDocument */
         $newRouteDocument = $this->documentManager->create('route');
         $newRouteDocument->setTargetDocument($targetDocument);
         $this->documentManager->persist($newRouteDocument, $locale, ['path' => $routePath, 'auto_create' => true]);
         $this->documentManager->publish($newRouteDocument, $locale);
         // change routes in old position to history
         $this->changeOldPathToHistoryRoutes($document, $newRouteDocument);
     }
 }
コード例 #4
0
 /**
  * @param PersistEvent $event
  */
 public function handlePersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     if (!$this->supports($document)) {
         return;
     }
     $this->doPersist($event);
 }
コード例 #5
0
 /**
  * Deindex/index document in search implementation depending
  * on the publish state.
  *
  * @param ContentNodeEvent $event
  */
 public function handlePersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof StructureBehavior) {
         return;
     }
     $this->searchManager->index($document);
 }
コード例 #6
0
 /**
  * @param PersistEvent $event
  */
 public function doPersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     if ($document instanceof RedirectTypeBehavior && $document->getRedirectType() !== RedirectType::NONE) {
         return;
     }
     $property = $this->getResourceSegmentProperty($document);
     $document->getStructure()->getProperty($property->getName())->setValue($document->getResourceSegment());
 }
コード例 #7
0
ファイル: InvalidateSubscriber.php プロジェクト: sulu/sulu
 /**
  * Invalidate custom-urls for persisted pages.
  *
  * @param PersistEvent $event
  */
 public function handlePersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof BasePageDocument) {
         return;
     }
     foreach ($this->manager->findByPage($document) as $customUrlDocument) {
         $this->manager->invalidate($customUrlDocument);
     }
 }
コード例 #8
0
 /**
  * {@inheritdoc}
  */
 protected function generatePath(PersistEvent $event)
 {
     $document = $event->getDocument();
     $currentPath = '';
     if ($event->hasParentNode()) {
         $currentPath = $event->getParentNode()->getPath();
     }
     $parentName = $this->getParentName($document);
     return sprintf('%s/%s', $currentPath, $parentName);
 }
コード例 #9
0
 public function handlePersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof RedirectTypeBehavior) {
         return;
     }
     if ($document->getRedirectTarget() === $document) {
         throw new \InvalidArgumentException('You are not allowed to link a page to itself!');
     }
 }
コード例 #10
0
ファイル: RouteSubscriber.php プロジェクト: kriswillis/sulu
 /**
  * @param PersistEvent $event
  */
 public function doPersist(PersistEvent $event)
 {
     $node = $event->getNode();
     $document = $event->getDocument();
     $targetDocument = $document->getTargetDocument();
     $targetNode = null;
     if ($targetDocument) {
         $targetNode = $this->documentRegistry->getNodeForDocument($targetDocument);
     }
     $node->setProperty($this->encoder->systemName(self::DOCUMENT_TARGET_FIELD), $targetNode);
 }
コード例 #11
0
 /**
  * Deindex/index document in search implementation depending
  * on the publish state.
  *
  * @param PersistEvent $event
  */
 public function handlePersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof StructureBehavior) {
         return;
     }
     if ($document instanceof SecurityBehavior && !empty($document->getPermissions())) {
         return;
     }
     $this->searchManager->index($document);
 }
コード例 #12
0
 public function handlePersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     if (!$this->supports($document)) {
         return;
     }
     $parentName = $this->getParentName($document);
     $path = sprintf('%s/%s', $this->basePath, $parentName);
     $parentNode = $this->nodeManager->createPath($path);
     $event->setParentNode($parentNode);
 }
コード例 #13
0
ファイル: TitleSubscriber.php プロジェクト: kriswillis/sulu
 /**
  * @param PersistEvent $event
  */
 public function doPersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     $title = $document->getTitle();
     $structure = $this->inspector->getStructureMetadata($document);
     if (!$structure->hasProperty('title')) {
         return;
     }
     $document->getStructure()->getProperty('title')->setValue($title);
     $this->doHydrate($event);
 }
コード例 #14
0
 public function setUp()
 {
     $this->persistEvent = $this->prophesize(PersistEvent::class);
     $this->hydrateEvent = $this->prophesize(HydrateEvent::class);
     $this->notImplementing = new \stdClass();
     $this->encoder = $this->prophesize(PropertyEncoder::class);
     $this->node = $this->prophesize(NodeInterface::class);
     $this->accessor = $this->prophesize(DocumentAccessor::class);
     $this->persistEvent->getNode()->willReturn($this->node);
     $this->persistEvent->getAccessor()->willReturn($this->accessor);
     $this->hydrateEvent->getAccessor()->willReturn($this->accessor);
 }
コード例 #15
0
ファイル: PublishSubscriber.php プロジェクト: sulu/sulu
 /**
  * Creates the node with the same UUID in the public workspace if it does not exist yet. In case it does it will
  * be renamed if necessary.
  *
  * @param PersistEvent $event
  */
 public function createNodeInPublicWorkspace(PersistEvent $event)
 {
     $node = $event->getNode();
     if ($node->isNew()) {
         $this->createNodesWithUuid($node);
         return;
     }
     $liveNode = $this->getLiveNode($event->getDocument());
     $nodeName = $node->getName();
     if ($liveNode->getName() !== $nodeName) {
         $liveNode->rename($nodeName);
     }
 }
コード例 #16
0
ファイル: SecuritySubscriber.php プロジェクト: ollietb/sulu
 /**
  * Adds the security information to the node.
  *
  * @param PersistEvent $event
  */
 public function handlePersist(PersistEvent $event)
 {
     /** @var SecurityBehavior $document */
     $document = $event->getDocument();
     if (!$this->supports($document) || !$document->getPermissions()) {
         return;
     }
     $node = $event->getNode();
     foreach ($document->getPermissions() as $roleId => $permission) {
         $node->setProperty('sec:role-' . $roleId, $permission);
         // TODO use PropertyEncoder, once it is refactored
     }
 }
コード例 #17
0
 /**
  * @param PersistEvent $event
  */
 public function handlePersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof TimestampBehavior) {
         return;
     }
     $node = $event->getNode();
     if (!$document->getCreated()) {
         $name = $this->encoder->localizedSystemName(self::CREATED, $event->getLocale());
         $node->setProperty($name, new \DateTime());
     }
     $name = $this->encoder->localizedSystemName(self::CHANGED, $event->getLocale());
     $node->setProperty($name, new \DateTime());
 }
コード例 #18
0
ファイル: OrderSubscriber.php プロジェクト: sulu/sulu
 /**
  * Adjusts the order of the document and its siblings.
  *
  * @param PersistEvent $event
  */
 public function handlePersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     if (false == $document instanceof OrderBehavior) {
         return;
     }
     if ($document->getSuluOrder()) {
         return;
     }
     $node = $event->getNode();
     $parent = $node->getParent();
     $nodeCount = count($parent->getNodes());
     $order = ($nodeCount + 1) * 10;
     $document->setSuluOrder($order);
 }
コード例 #19
0
ファイル: OrderSubscriber.php プロジェクト: kriswillis/sulu
 /**
  * Adjusts the order of the document and its siblings.
  *
  * @param PersistEvent $event
  */
 public function handlePersist(PersistEvent $event)
 {
     $node = $event->getNode();
     $document = $event->getDocument();
     if (false == $this->supports($document)) {
         return;
     }
     $propertyName = $this->encoder->systemName(self::FIELD);
     if ($node->hasProperty($propertyName)) {
         return;
     }
     $parent = $node->getParent();
     $nodeCount = count($parent->getNodes());
     $order = ($nodeCount + 1) * 10;
     $node->setProperty($propertyName, $order, PropertyType::LONG);
     $this->handleHydrate($event);
 }
コード例 #20
0
ファイル: BlameSubscriber.php プロジェクト: sulu/sulu
 /**
  * Persists the data of creator and changer to the Node.
  *
  * @param PersistEvent $event
  */
 public function handlePersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof LocalizedBlameBehavior) {
         return;
     }
     $userId = $this->getUserId($event->getOptions());
     if (null === $userId) {
         return;
     }
     if (!$event->getLocale()) {
         return;
     }
     if (!$document->getCreator()) {
         $event->getAccessor()->set(self::CREATOR, $userId);
     }
     $event->getAccessor()->set(self::CHANGER, $userId);
 }
コード例 #21
0
 /**
  * It should not register on PERSIST when there is already a document.
  */
 public function testHandleRegisterPersistAlreadyExists()
 {
     $this->persistEvent->getDocument()->willReturn($this->document);
     $this->persistEvent->getNode()->willReturn($this->node->reveal());
     $this->persistEvent->getLocale()->willReturn('fr');
     $this->registry->registerDocument($this->document, $this->node->reveal(), 'fr')->shouldNotBeCalled();
     $this->registry->updateLocale($this->document, 'fr')->shouldBeCalled();
     $this->registry->hasDocument($this->document)->willReturn(true);
     $this->subscriber->handlePersist($this->persistEvent->reveal());
 }
コード例 #22
0
 /**
  * It should set the parent document.
  */
 public function testSetParentDocument()
 {
     $this->persistEvent->getDocument()->willReturn($this->document->reveal());
     $this->persistEvent->getLocale()->willReturn('fr');
     $this->metadataFactory->getMetadataForClass(get_class($this->document->reveal()))->willReturn($this->metadata->reveal());
     $this->metadata->getAlias()->willReturn('test');
     $this->nodeManager->createPath('/')->willReturn($this->parentNode->reveal());
     $this->persistEvent->hasParentNode()->shouldBeCalled();
     $this->persistEvent->setParentNode($this->parentNode->reveal())->shouldBeCalled();
     $this->documentManager->find('/test', 'fr')->willReturn($this->parentDocument);
     $this->subscriber->handlePersist($this->persistEvent->reveal());
 }
コード例 #23
0
 /**
  * {@inheritdoc}
  */
 protected function doPersist(PersistEvent $event)
 {
     if (!$event->getDocument()->isShadowLocaleEnabled()) {
         $this->copyToShadows($event->getDocument(), $event->getNode());
     } else {
         $this->copyFromShadow($event->getDocument(), $event->getNode());
     }
 }
コード例 #24
0
ファイル: CustomUrlSubscriber.php プロジェクト: sulu/sulu
 /**
  * Creates routes for persisted custom-url.
  *
  * @param PersistEvent $event
  */
 public function handlePersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof CustomUrlBehavior) {
         return;
     }
     $oldRoutes = $document->getRoutes();
     $webspaceKey = $this->inspector->getWebspace($document);
     $domain = $this->generator->generate($document->getBaseDomain(), $document->getDomainParts());
     $locale = $this->webspaceManager->findWebspaceByKey($webspaceKey)->getLocalization($document->getTargetLocale());
     $route = $this->createRoute($domain, $document, $locale, $event->getLocale(), $this->getRoutesPath($webspaceKey));
     if (!array_key_exists($domain, $oldRoutes)) {
         $document->addRoute($domain, $route);
     }
     foreach ($oldRoutes as $oldRoute) {
         if ($oldRoute->getPath() === $route->getPath()) {
             continue;
         }
         $oldRoute->setTargetDocument($route);
         $oldRoute->setHistory(true);
         $this->documentManager->persist($oldRoute, $event->getLocale(), ['path' => $oldRoute->getPath(), 'auto_create' => true]);
         $this->documentManager->publish($oldRoute, $locale);
     }
 }
コード例 #25
0
 /**
  * @param PersistEvent $event
  *
  * @throws MandatoryPropertyException
  */
 public function doPersist(PersistEvent $event)
 {
     $node = $event->getNode();
     $document = $event->getDocument();
     $node->setProperty($this->encoder->localizedSystemName(self::REDIRECT_TYPE_FIELD, $event->getLocale()), $document->getRedirectType() ?: RedirectType::NONE, PropertyType::LONG);
     $node->setProperty($this->encoder->localizedSystemName(self::EXTERNAL_FIELD, $event->getLocale()), $document->getRedirectExternal());
     $internalDocument = $document->getRedirectTarget();
     if (!$internalDocument) {
         if ($document->getRedirectType() == RedirectType::INTERNAL) {
             throw new MandatoryPropertyException('Internal link property is mandatory.');
         }
         return;
     }
     $internalNode = $this->documentRegistry->getNodeForDocument($internalDocument);
     $node->setProperty($this->encoder->localizedSystemName(self::INTERNAL_FIELD, $event->getLocale()), $internalNode);
     $this->doHydrate($event);
 }
コード例 #26
0
 /**
  * @param PersistEvent $event
  */
 public function handlePersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof BlameBehavior) {
         return;
     }
     $userId = $this->getUserId($event->getOptions());
     if (null === $userId) {
         return;
     }
     $node = $event->getNode();
     $locale = $event->getLocale();
     if (!$this->getCreator($node, $locale)) {
         $name = $this->encoder->localizedSystemName(self::CREATOR, $locale);
         $node->setProperty($name, $userId, PropertyType::LONG);
     }
     $name = $this->encoder->localizedSystemName(self::CHANGER, $locale);
     $node->setProperty($name, $userId, PropertyType::LONG);
     $this->handleHydrate($event);
 }
コード例 #27
0
 /**
  * @param PersistEvent $event
  */
 public function handlePersist(PersistEvent $event)
 {
     $locale = $event->getLocale();
     if (!$locale) {
         return;
     }
     $document = $event->getDocument();
     if (!$document instanceof WorkflowStageBehavior) {
         return;
     }
     $stage = $document->getWorkflowStage();
     $node = $event->getNode();
     $persistedStage = $this->getWorkflowStage($node, $locale);
     if ($stage == WorkflowStage::PUBLISHED && $stage !== $persistedStage) {
         $event->getAccessor()->set(self::PUBLISHED_FIELD, new \DateTime());
     }
     if ($stage == WorkflowStage::TEST && $stage !== $persistedStage) {
         $event->getAccessor()->set(self::PUBLISHED_FIELD, null);
     }
     $document->setWorkflowStage($stage);
 }
コード例 #28
0
 /**
  * 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);
 }
コード例 #29
0
 /**
  * If this is a shadow document, update the URL to that of the shadowed document.
  *
  * TODO: This is about caching and should be handled somewhere else.
  *
  * @param PersistEvent $event
  */
 public function handlePersistUpdateUrl(PersistEvent $event)
 {
     $document = $event->getDocument();
     if (!$this->supports($document)) {
         return;
     }
     if (!$document->isShadowLocaleEnabled()) {
         return;
     }
     $node = $event->getNode();
     $structure = $this->inspector->getStructureMetadata($document);
     if (false === $structure->hasPropertyWithTagName('sulu.rlp')) {
         return;
     }
     $locatorProperty = $structure->getPropertyByTagName('sulu.rlp');
     if ($node->getPropertyValueWithDefault($this->encoder->localizedSystemName($locatorProperty->getName(), $document->getLocale()), null)) {
         return;
     }
     $shadowLocator = $node->getPropertyValueWithDefault($this->encoder->localizedSystemName($locatorProperty->getName(), $document->getShadowLocale()), null);
     if (!$shadowLocator) {
         return;
     }
     $event->getAccessor()->set('resourceSegment', $shadowLocator);
 }
コード例 #30
0
ファイル: WorkflowStageSubscriber.php プロジェクト: sulu/sulu
 /**
  * Determines if the given document is supported by this subscriber.
  *
  * @param HydrateEvent|PublishEvent|PersistEvent $event
  *
  * @return bool
  */
 private function supports($event)
 {
     return $event->getLocale() && $event->getDocument() instanceof WorkflowStageBehavior;
 }