Commit 34c996e2 authored by Dries's avatar Dries
Browse files

- Patch #358315 by neochief et al: drupal_lookup_path() not respects alias' order.

parent 4f2e13f5
......@@ -87,7 +87,7 @@ function drupal_lookup_path($action, $path = '', $path_language = '') {
// Now fetch the aliases corresponding to these system paths.
// We order by ASC and overwrite array keys to ensure the correct
// alias is used when there are multiple aliases per path.
$map[$path_language] = db_query("SELECT src, dst FROM {url_alias} WHERE src IN(:system) AND language IN(:language, '') ORDER BY language ASC", array(
$map[$path_language] = db_query("SELECT src, dst FROM {url_alias} WHERE src IN(:system) AND language IN(:language, '') ORDER BY language ASC, pid ASC", array(
':system' => $system_paths,
':language' => $path_language
))->fetchAllKeyed();
......@@ -108,7 +108,7 @@ function drupal_lookup_path($action, $path = '', $path_language = '') {
// For system paths which were not cached, query aliases individually.
else if (!isset($no_aliases[$path_language][$path])) {
// Get the most fitting result falling back with alias without language
$alias = db_query("SELECT dst FROM {url_alias} WHERE src = :src AND language IN(:language, '') ORDER BY language DESC", array(
$alias = db_query("SELECT dst FROM {url_alias} WHERE src = :src AND language IN(:language, '') ORDER BY language DESC, pid DESC", array(
':src' => $path,
':language' => $path_language
))->fetchField();
......@@ -123,7 +123,7 @@ function drupal_lookup_path($action, $path = '', $path_language = '') {
$src = '';
if (!isset($map[$path_language]) || !($src = array_search($path, $map[$path_language]))) {
// Get the most fitting result falling back with alias without language
if ($src = db_query("SELECT src FROM {url_alias} WHERE dst = :dst AND language IN(:language, '') ORDER BY language DESC", array(
if ($src = db_query("SELECT src FROM {url_alias} WHERE dst = :dst AND language IN(:language, '') ORDER BY language DESC, pid DESC", array(
':dst' => $path,
':language' => $path_language))
->fetchField()) {
......
......@@ -1340,11 +1340,11 @@ function system_schema() {
),
),
'unique keys' => array(
'dst_language' => array('dst', 'language'),
'dst_language_pid' => array('dst', 'language', 'pid'),
),
'primary key' => array('pid'),
'indexes' => array(
'src_language' => array('src', 'language'),
'src_language_pid' => array('src', 'language', 'pid'),
),
);
......@@ -3525,6 +3525,18 @@ function system_update_7024() {
return $ret;
}
/**
* Improve indexes on the {url_alias} table.
*/
function system_update_7025() {
$ret = array();
db_drop_index($ret, 'url_alias', 'src_language');
db_drop_index($ret, 'url_alias', 'dst_language');
db_add_index($ret, 'url_alias', 'dst_language_pid', array('dst', 'language', 'pid'));
db_add_index($ret, 'url_alias', 'src_language_pid', array('src', 'language', 'pid'));
return $ret;
}
/**
* @} End of "defgroup updates-6.x-to-7.x"
* The next series of updates should start at 8000.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment