diff --git a/core/lib/Drupal/Core/Path/AliasStorage.php b/core/lib/Drupal/Core/Path/AliasStorage.php index 0ef4a12..4385923 100644 --- a/core/lib/Drupal/Core/Path/AliasStorage.php +++ b/core/lib/Drupal/Core/Path/AliasStorage.php @@ -60,7 +60,7 @@ public function save($source, $alias, $langcode = LanguageInterface::LANGCODE_NO $fields = array( 'source' => $source, - 'alias' => Unicode::strtolower($alias), + 'alias' => $alias, 'langcode' => $langcode, ); @@ -132,7 +132,6 @@ public function delete($conditions) { */ public function preloadPathAlias($preloaded, $langcode) { $args = array( - ':system[]' => $preloaded, ':langcode' => $langcode, ':langcode_undetermined' => LanguageInterface::LANGCODE_NOT_SPECIFIED, ); @@ -143,19 +142,22 @@ public function preloadPathAlias($preloaded, $langcode) { // created alias for each source. Subsequent queries using fetchField() must // use pid DESC to have the same effect. For performance reasons, the query // builder is not used here. + $select = $this->connection->select('url_alias'); + $select->fields('url_alias', ['source', 'alias']); + $select->condition('source', $preloaded, 'IN'); if ($langcode == LanguageInterface::LANGCODE_NOT_SPECIFIED) { - // Prevent PDO from complaining about a token the query doesn't use. + // Don't put the same value in the IN query twice. unset($args[':langcode']); - $result = $this->connection->query('SELECT source, alias FROM {url_alias} WHERE source IN ( :system[] ) AND langcode = :langcode_undetermined ORDER BY pid ASC', $args); } elseif ($langcode < LanguageInterface::LANGCODE_NOT_SPECIFIED) { - $result = $this->connection->query('SELECT source, alias FROM {url_alias} WHERE source IN ( :system[] ) AND langcode IN (:langcode, :langcode_undetermined) ORDER BY langcode ASC, pid ASC', $args); + $select->orderBy('langcode', 'ASC'); } else { - $result = $this->connection->query('SELECT source, alias FROM {url_alias} WHERE source IN ( :system[] ) AND langcode IN (:langcode, :langcode_undetermined) ORDER BY langcode DESC, pid ASC', $args); + $select->orderBy('langcode', 'DESC'); } - - return $result->fetchAllKeyed(); + $select->condition('langcode', $args, 'IN'); + $select->orderBy('pid', 'ASC'); + return $select->execute()->fetchAllKeyed(); } /** @@ -163,23 +165,26 @@ public function preloadPathAlias($preloaded, $langcode) { */ public function lookupPathAlias($path, $langcode) { $args = array( - ':source' => $path, ':langcode' => $langcode, ':langcode_undetermined' => LanguageInterface::LANGCODE_NOT_SPECIFIED, ); // See the queries above. + $select = $this->connection->select('url_alias'); + $select->fields('url_alias', ['alias']); if ($langcode == LanguageInterface::LANGCODE_NOT_SPECIFIED) { unset($args[':langcode']); - $alias = $this->connection->query("SELECT alias FROM {url_alias} WHERE source = :source AND langcode = :langcode_undetermined ORDER BY pid DESC", $args)->fetchField(); } elseif ($langcode > LanguageInterface::LANGCODE_NOT_SPECIFIED) { - $alias = $this->connection->query("SELECT alias FROM {url_alias} WHERE source = :source AND langcode IN (:langcode, :langcode_undetermined) ORDER BY langcode DESC, pid DESC", $args)->fetchField(); + $select->orderBy('langcode', 'DESC'); } else { - $alias = $this->connection->query("SELECT alias FROM {url_alias} WHERE source = :source AND langcode IN (:langcode, :langcode_undetermined) ORDER BY langcode ASC, pid DESC", $args)->fetchField(); + $select->orderBy('langcode', 'ASC'); } - - return $alias; + // Use LIKE for case-insensitive matching. + $select->condition('source', $path, 'LIKE'); + $select->condition('langcode', $args, 'IN'); + $select->orderBy('pid', 'DESC'); + return $select->execute()->fetchField(); } /** @@ -187,23 +192,26 @@ public function lookupPathAlias($path, $langcode) { */ public function lookupPathSource($path, $langcode) { $args = array( - ':alias' => Unicode::strtolower($path), ':langcode' => $langcode, ':langcode_undetermined' => LanguageInterface::LANGCODE_NOT_SPECIFIED, ); // See the queries above. + $select = $this->connection->select('url_alias'); + $select->fields('url_alias', ['source']); if ($langcode == LanguageInterface::LANGCODE_NOT_SPECIFIED) { unset($args[':langcode']); - $result = $this->connection->query("SELECT source FROM {url_alias} WHERE alias = :alias AND langcode = :langcode_undetermined ORDER BY pid DESC", $args); } elseif ($langcode > LanguageInterface::LANGCODE_NOT_SPECIFIED) { - $result = $this->connection->query("SELECT source FROM {url_alias} WHERE alias = :alias AND langcode IN (:langcode, :langcode_undetermined) ORDER BY langcode DESC, pid DESC", $args); + $select->orderBy('langcode', 'DESC'); } else { - $result = $this->connection->query("SELECT source FROM {url_alias} WHERE alias = :alias AND langcode IN (:langcode, :langcode_undetermined) ORDER BY langcode ASC, pid DESC", $args); + $select->orderBy('langcode', 'ASC'); } - - return $result->fetchField(); + // Use LIKE for case-insensitive matching. + $select->condition('alias', $path, 'LIKE'); + $select->condition('langcode', $args, 'IN'); + $select->orderBy('pid', 'DESC'); + return $select->execute()->fetchField(); } /** diff --git a/core/lib/Drupal/Core/Path/AliasStorageInterface.php b/core/lib/Drupal/Core/Path/AliasStorageInterface.php index 3f55413..7717aef 100644 --- a/core/lib/Drupal/Core/Path/AliasStorageInterface.php +++ b/core/lib/Drupal/Core/Path/AliasStorageInterface.php @@ -20,7 +20,7 @@ * @param string $source * The internal system path. * @param string $alias - * The URL alias. This will be converted to lowercase. + * The URL alias. * @param string $langcode * (optional) The language code of the alias. * @param int|null $pid diff --git a/core/modules/system/system.post_update.php b/core/modules/system/system.post_update.php index b8d089d..b75625c 100644 --- a/core/modules/system/system.post_update.php +++ b/core/modules/system/system.post_update.php @@ -39,37 +39,5 @@ function system_post_update_recalculate_configuration_entity_dependencies(&$sand } /** - * Load and save all path aliases to make sure they are lower case. - */ -function system_post_update_path_alias_lowercase(&$sandbox = NULL) { - // The path alias storage interface has no way to count or iterate over all - // aliases, so we have to fall back to SQL for this function. - /** @var \Drupal\Core\Path\AliasStorageInterface $alias_storage */ - $alias_storage = \Drupal::service('path.alias_storage'); - $connection = \Drupal::database(); - $schema = $connection->schema(); - if ($schema->tableExists('url_alias')) { - if (!isset($sandbox['current'])) { - $sandbox['current'] = 0; - $sandbox['max'] = $connection->query('SELECT COUNT(pid) FROM {url_alias}') - ->fetchField(); - } - $aliases = $connection->queryRange('SELECT pid, source, alias, langcode FROM {url_alias} ORDER BY pid ASC', $sandbox['current'], $sandbox['current'] + 50) - ->fetchAllAssoc('pid', PDO::FETCH_ASSOC); - - foreach ($aliases as $alias) { - $alias_storage->save($alias['source'], $alias['alias'], $alias['langcode'], $alias['pid']); - $sandbox['current']++; - } - - $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['current'] / $sandbox['max']); - return t('Path aliases converted'); - } - else { - return t('Path alias conversion skipped, because the {url_alias} table did not exist.'); - } -} - -/** * @} End of "addtogroup updates-8.0.0-beta". */