/** * {@inheritdoc} */ protected function doPersist(PersistEvent $event) { if (!$event->getDocument()->isShadowLocaleEnabled()) { $this->copyToShadows($event->getDocument(), $event->getNode()); } else { $this->copyFromShadow($event->getDocument(), $event->getNode()); } }
/** * 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); } }
/** * {@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); }
/** * @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); }
/** * 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); }
/** * @param PersistEvent $event */ public function handlePersist(PersistEvent $event) { $document = $event->getDocument(); if (!$this->supports($document)) { return; } $this->doPersist($event); }
/** * @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()); }
/** * 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); } }
/** * 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()); }
/** * {@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); }
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!'); } }
/** * @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); }
/** * 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); }
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); }
/** * @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); }
/** * 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()); }
/** * 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); } }
/** * 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 } }
/** * @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()); }
/** * 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); }
/** * @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); }
/** * 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); }
/** * 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); }
/** * @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); }
/** * @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); }
/** * 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); } }
/** * 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); }
/** * 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); }
/** * 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; }
/** * Sets the ResourceSegment on the Structure. * * @param PersistEvent $event */ public function handlePersistDocument(PersistEvent $event) { /** @var ResourceSegmentBehavior $document */ $document = $event->getDocument(); if (!$this->supports($document)) { return; } $property = $this->getResourceSegmentProperty($document); // check if a property for the resource segment is available, this prevents the code from failing in case there // is no such property for some reason (e.g. the document doesn't have a structure) if ($property) { $this->persistDocument($document, $property); } }