/** * {@inheritDoc} */ public function doPersist(PersistEvent $event) { $document = $event->getDocument(); if ($document->isShadowLocaleEnabled()) { $this->validateShadow($document); } $event->getNode()->setProperty($this->encoder->localizedSystemName(self::SHADOW_ENABLED_FIELD, $event->getLocale()), $document->isShadowLocaleEnabled() ?: null); $event->getNode()->setProperty($this->encoder->localizedSystemName(self::SHADOW_LOCALE_FIELD, $event->getLocale()), $document->getShadowLocale()); }
/** * @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()); }
/** * {@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 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); }
/** * 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()); }
/** * 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()); }
/** * @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); } }
/** * 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); }
/** * 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; }
/** * {@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 * * @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); }
/** * @param PersistEvent $event */ public function doPersist(PersistEvent $event) { $node = $event->getNode(); $node->setProperty($this->encoder->localizedSystemName(self::FIELD, $event->getLocale()), $event->getDocument()->getNavigationContexts() ?: null); }