/** * List of url aliases pointing to $location, sorted by language priority. * * @param \eZ\Publish\API\Repository\Values\Content\Location $location * @param bool $custom if true the user generated aliases are listed otherwise the autogenerated * @param string $languageCode filters those which are valid for the given language * @param null|bool $showAllTranslations * @param null|string[] $prioritizedLanguageList * * @return \eZ\Publish\API\Repository\Values\Content\URLAlias[] */ public function listLocationAliases(Location $location, $custom = true, $languageCode = null, $showAllTranslations = null, array $prioritizedLanguageList = null) { $spiUrlAliasList = $this->urlAliasHandler->listURLAliasesForLocation($location->id, $custom); if ($showAllTranslations === null) { $showAllTranslations = $this->settings['showAllTranslations']; } if ($prioritizedLanguageList === null) { $prioritizedLanguageList = $this->settings['prioritizedLanguageList']; } $urlAliasList = array(); foreach ($spiUrlAliasList as $spiUrlAlias) { if (!$this->isUrlAliasLoadable($spiUrlAlias, $languageCode, $showAllTranslations, $prioritizedLanguageList)) { continue; } $path = $this->extractPath($spiUrlAlias, $languageCode, $showAllTranslations, $prioritizedLanguageList); if ($path === false) { continue; } $urlAliasList[$spiUrlAlias->id] = $this->buildUrlAliasDomainObject($spiUrlAlias, $path); } $prioritizedAliasList = array(); foreach ($prioritizedLanguageList as $languageCode) { foreach ($urlAliasList as $urlAlias) { foreach ($urlAlias->languageCodes as $aliasLanguageCode) { if ($aliasLanguageCode === $languageCode) { $prioritizedAliasList[$urlAlias->id] = $urlAlias; break; } } } } // Add aliases not matched by prioritized language to the end of the list return array_values($prioritizedAliasList + $urlAliasList); }
/** * Internal method for backing up custom Location URL aliases. * * @see \eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand::backupCustomLocationAliases() */ protected function doBackupCustomLocationAliases() { $totalCount = $this->getTotalLocationCount(); $passCount = ceil($totalCount / $this->bulkCount); $customAliasCount = 0; $customAliasPathCount = 0; if ($totalCount === 0) { $this->output->writeln('Could not find any Locations, nothing to backup.'); $this->output->writeln(''); return; } $queryBuilder = $this->connection->createQueryBuilder(); $queryBuilder->select('node_id', 'parent_node_id', 'contentobject_id')->from('ezcontentobject_tree')->where($queryBuilder->expr()->neq('node_id', 1))->orderBy('depth', 'ASC')->orderBy('node_id', 'ASC'); $this->output->writeln("Backing up custom URL alias(es) for {$totalCount} Location(s)."); $progressBar = $this->getProgressBar($totalCount); $progressBar->start(); for ($pass = 0; $pass <= $passCount; ++$pass) { $rows = $this->loadLocationData($queryBuilder, $pass); foreach ($rows as $row) { $customAliases = $this->urlAliasHandler->listURLAliasesForLocation($row['node_id'], true); $customAliasCount += count($customAliases); $customAliasPathCount += $this->storeCustomAliases($customAliases); } $progressBar->advance(count($rows)); } $progressBar->finish(); $this->output->writeln(''); $this->output->writeln("Done. Backed up {$customAliasCount} custom URL alias(es) " . "with {$customAliasPathCount} path(s)."); $this->output->writeln(''); }