/** * {@inheritdoc} */ protected function doPersist(PersistEvent $event) { if (!$event->getDocument()->isShadowLocaleEnabled()) { $this->copyToShadows($event->getDocument(), $event->getNode()); } else { $this->copyFromShadow($event->getDocument(), $event->getNode()); } }
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); }
/** * {@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); }
/** * 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); } }
/** * 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()); }
/** * @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); }
/** * 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); }
/** * @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); }
/** * 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); }
/** * @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); }
/** * {@inheritdoc} */ public function handlePersist(PersistEvent $event) { // Set the structure type $document = $event->getDocument(); if (!$document instanceof StructureBehavior) { return; } if (!$document->getStructureType()) { return; } if (!$event->getLocale()) { return; } $node = $event->getNode(); $locale = $event->getLocale(); $this->mapContentToNode($document, $node, $locale); $node->setProperty($this->getStructureTypePropertyName($document, $locale), $document->getStructureType()); }
/** * @param PersistEvent $event */ public function doPersist(PersistEvent $event) { $node = $event->getNode(); $node->setProperty($this->encoder->localizedSystemName(self::FIELD, $event->getLocale()), $event->getDocument()->getNavigationContexts() ?: null); }
/** * @param PersistEvent $event * * @throws DocumentManagerException */ public function handlePersist(PersistEvent $event) { $document = $event->getDocument(); if (!$document instanceof AutoNameBehavior) { return; } $title = $document->getTitle(); if (!$title) { throw new DocumentManagerException(sprintf('Document has no title (title is required for auto name behavior): %s)', DocumentHelper::getDebugTitle($document))); } $name = $this->slugifier->slugify($title); $parentNode = $event->getParentNode(); $node = $event->hasNode() ? $event->getNode() : null; $name = $this->resolver->resolveName($parentNode, $name, $node); if (null === $node) { $node = $this->documentStrategy->createNodeForDocument($document, $parentNode, $name); $event->setNode($node); return; } if ($name === $node->getName()) { return; } $node = $event->getNode(); $defaultLocale = $this->registry->getDefaultLocale(); if ($defaultLocale != $event->getLocale()) { return; } $this->rename($node, $name); }