상속: extends Sulu\Component\DocumentManager\PropertyEncoder
예제 #1
0
 public function __construct(SessionManagerInterface $sessionManager, SessionInterface $defaultSession, SessionInterface $liveSession, WebspaceManagerInterface $webspaceManager, PropertyEncoder $propertyEncoder)
 {
     $this->sessionManager = $sessionManager;
     $this->defaultSession = $defaultSession;
     $this->liveSession = $liveSession;
     $this->webspaceManager = $webspaceManager;
     $this->propertyName = $propertyEncoder->systemName(OrderSubscriber::FIELD);
 }
예제 #2
0
 /**
  * Iterates over all nodes of the given type, and upgrades them.
  *
  * @param StructureMetadata $structureMetadata The structure metadata, whose pages have to be upgraded
  * @param array $properties The properties which are or contain URL fields
  * @param bool $addScheme Adds the scheme to URLs if true, removes the scheme otherwise
  */
 private function iterateStructureNodes(StructureMetadata $structureMetadata, array $properties, $addScheme)
 {
     foreach ($this->localizationManager->getLocalizations() as $localization) {
         $rows = $this->session->getWorkspace()->getQueryManager()->createQuery(sprintf('SELECT * FROM [nt:unstructured] WHERE [%s] = "%s" OR [%s] = "%s"', $this->propertyEncoder->localizedSystemName('template', $localization->getLocalization()), $structureMetadata->getName(), 'template', $structureMetadata->getName()), 'JCR-SQL2')->execute();
         foreach ($rows->getNodes() as $node) {
             $this->upgradeNode($node, $localization->getLocalization(), $properties, $addScheme);
         }
     }
 }
예제 #3
0
 /**
  * Upgrades the node to new date representation.
  *
  * @param NodeInterface $node The node to be upgraded
  * @param string $locale The locale of the node to be upgraded
  * @param array $properties The properties which are or contain date fields$up
  */
 private function upgradeNode(NodeInterface $node, $locale, $properties, $up)
 {
     foreach ($properties as $property) {
         $propertyName = $this->propertyEncoder->localizedContentName($property, $locale);
         if ($node->hasProperty($propertyName)) {
             $value = $this->upgradeProperty($node->getPropertyValue($propertyName), $up);
             $node->setProperty($propertyName, $value);
         }
     }
 }
예제 #4
0
 /**
  * Removes all localized properties in the given locale from the given node.
  *
  * @param NodeInterface $node
  * @param string $locale
  */
 private function removeLocalizedNodeProperties(NodeInterface $node, $locale)
 {
     // remove all localized system properties from the node
     foreach ($node->getProperties($this->propertyEncoder->localizedSystemName('', $locale) . '*') as $property) {
         $property->remove();
     }
     // remove all localized content properties from the node
     foreach ($node->getProperties($this->propertyEncoder->localizedContentName('', $locale) . '*') as $property) {
         $property->remove();
     }
 }
예제 #5
0
 private function upgradeNode(NodeInterface $node, Webspace $webspace, Localization $localization, OutputInterface $output, $depth = 0)
 {
     $locale = $localization->getLocale();
     $localizedTemplatePropertyName = $this->propertyEncoder->localizedSystemName('template', $locale);
     if (!$node->hasProperty($localizedTemplatePropertyName)) {
         return;
     }
     $structureMetadata = $this->structureMetadataFactory->getStructureMetadata($this->metadataFactory->getMetadataForPhpcrNode($node)->getAlias(), $node->getPropertyValue($localizedTemplatePropertyName));
     $property = $structureMetadata->getPropertyByTagName('sulu.rlp');
     if (!$property) {
         return;
     }
     $nodeType = $node->getPropertyValue($this->propertyEncoder->localizedSystemName('nodeType', $locale));
     if ($property->getContentTypeName() !== 'resource_locator' && $nodeType !== Structure::NODE_TYPE_CONTENT) {
         return;
     }
     $baseRoutePath = $this->sessionManager->getRoutePath($webspace->getKey(), $localization->getLocale());
     foreach ($node->getReferences('sulu:content') as $routeProperty) {
         if (strpos($routeProperty->getPath(), $baseRoutePath) !== 0) {
             continue;
         }
         $routeNode = $routeProperty->getParent();
         if ($routeNode->getPropertyValue('sulu:history') === true) {
             continue;
         }
         $resourceLocator = substr($routeNode->getPath(), strlen($baseRoutePath));
         if ($resourceLocator) {
             // only set if resource locator is not empty
             // if the resource locator is empty it is the homepage, whose url should not be changed
             $node->setProperty($this->propertyEncoder->localizedContentName($property->getName(), $locale), $resourceLocator);
             $prefix = '   ';
             for ($i = 0; $i < $depth; ++$i) {
                 $prefix .= '-';
             }
             $title = $node->getPropertyValue($this->propertyEncoder->localizedContentName('title', $locale));
             $output->writeln($prefix . '> "' . $title . '": ' . $resourceLocator);
         }
         break;
     }
 }
예제 #6
0
 /**
  * Adjusts the order of the document and its siblings.
  *
  * @param ReorderEvent $event
  */
 public function handleReorder(ReorderEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof OrderBehavior) {
         return;
     }
     $parentDocument = $this->documentInspector->getParent($document);
     if (null === $parentDocument) {
         return;
     }
     $count = 1;
     foreach ($this->documentInspector->getChildren($parentDocument) as $childDocument) {
         if (!$childDocument instanceof OrderBehavior) {
             continue;
         }
         $order = $count * 10;
         $childDocument->setSuluOrder($order);
         // TODO move to NodeHelper once integrated in sulu/sulu?
         $childNode = $this->documentInspector->getNode($childDocument);
         $childNode->setProperty($this->propertyEncoder->systemName(static::FIELD), $order);
         ++$count;
     }
 }
예제 #7
0
 /**
  * converts a query row to an array.
  */
 private function rowToArray(Row $row, $locale, $webspaceKey, $fields)
 {
     // reset cache
     $this->initializeExtensionCache();
     $templateName = $this->encoder->localizedSystemName('template', $locale);
     $nodeTypeName = $this->encoder->localizedSystemName('nodeType', $locale);
     // check and determine shadow-nodes
     $node = $row->getNode('page');
     $document = $this->documentManager->find($node->getIdentifier(), $locale);
     $originalDocument = $document;
     if (!$node->hasProperty($templateName) && !$node->hasProperty($nodeTypeName)) {
         return false;
     }
     $redirectType = $document->getRedirectType();
     if ($redirectType === RedirectType::INTERNAL) {
         $target = $document->getRedirectTarget();
         if ($target) {
             $url = $target->getResourceSegment();
             $document = $target;
             $node = $this->inspector->getNode($document);
         }
     }
     if ($redirectType === RedirectType::EXTERNAL) {
         $url = 'http://' . $document->getRedirectExternal();
     }
     $originLocale = $locale;
     if ($document instanceof ShadowLocaleBehavior) {
         $locale = $document->isShadowLocaleEnabled() ? $document->getShadowLocale() : $originLocale;
     }
     $nodeState = null;
     if ($document instanceof WorkflowStageBehavior) {
         $nodeState = $document->getWorkflowStage();
     }
     // if page is not piblished ignore it
     if ($nodeState !== WorkflowStage::PUBLISHED) {
         return false;
     }
     if (!isset($url)) {
         $url = $document->getResourceSegment();
     }
     if (false === $url) {
         return;
     }
     // generate field data
     $fieldsData = $this->getFieldsData($row, $node, $document, $fields[$originLocale], $document->getStructureType(), $webspaceKey, $locale);
     $structureType = $document->getStructureType();
     $shortPath = $this->inspector->getContentPath($originalDocument);
     $documentData = array('uuid' => $document->getUuid(), 'nodeType' => $redirectType, 'path' => $shortPath, 'changed' => $document->getChanged(), 'changer' => $document->getChanger(), 'created' => $document->getCreated(), 'published' => $document->getPublished(), 'creator' => $document->getCreator(), 'title' => $originalDocument->getTitle(), 'url' => $url, 'urls' => $this->inspector->getLocalizedUrlsForPage($document), 'locale' => $locale, 'webspaceKey' => $this->inspector->getWebspace($document), 'template' => $structureType, 'parent' => $this->inspector->getParent($document)->getUuid());
     if ($document instanceof OrderBehavior) {
         $documentData['order'] = $document->getSuluOrder();
     }
     return array_merge($documentData, $fieldsData);
 }
예제 #8
0
 private function getShadowLocale(NodeInterface $node, $locale)
 {
     return $node->getPropertyValueWithDefault($this->encoder->localizedSystemName(self::SHADOW_LOCALE_FIELD, $locale), null);
 }