/** * Finds the next available parent-localization in which the node has a translation. * * @param string[] $availableLocales * @param Localization $localization The localization to start the search for * * @return null|Localization */ private function findAvailableParentLocalization(array $availableLocales, Localization $localization) { do { if (in_array($localization->getLocale(), $availableLocales)) { return $localization; } // try to load parent and stop if there is no parent $localization = $localization->getParent(); } while ($localization != null); return; }
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; } }