? database.mysql ? path_alias_backport.patch ? path_alias_backport2.patch ? sites/localhost Index: database/updates.inc =================================================================== RCS file: /cvs/drupal/drupal/database/updates.inc,v retrieving revision 1.100.2.9 diff -u -p -r1.100.2.9 updates.inc --- database/updates.inc 2 Dec 2005 21:32:31 -0000 1.100.2.9 +++ database/updates.inc 25 Apr 2006 08:46:43 -0000 @@ -107,7 +107,8 @@ $sql_updates = array( "2005-03-21" => "update_128", "2005-04-14" => "update_129", "2005-05-06" => "update_130", - "2005-05-07" => "update_131" + "2005-05-07" => "update_131", + "2005-05-08" => "update_132" ); function update_32() { @@ -2394,6 +2395,19 @@ function update_131() { return $ret; } +function update_132() { + $ret = array(); + + if ($GLOBALS['db_type'] == 'mysql') { + $ret[] = update_sql("ALTER TABLE {url_alias} ADD INDEX (src)"); + } + elseif ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql("CREATE INDEX url_alias_src_idx ON {url_alias}(src)"); + } + + return $ret; +} + function update_sql($sql) { $edit = $_POST["edit"]; $result = db_query($sql); Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.44.2.2 diff -u -p -r1.44.2.2 bootstrap.inc --- includes/bootstrap.inc 30 Nov 2005 10:05:16 -0000 1.44.2.2 +++ includes/bootstrap.inc 25 Apr 2006 08:46:44 -0000 @@ -370,19 +370,70 @@ function drupal_get_path_map($action = ' } /** + * Given an alias, return its Drupal system URL if one exists. Given a Drupal + * system URL return its alias if one exists. + * + * @param $action + * One of the following values: + * - wipe: delete the alias cache. + * - alias: return an alias for a given Drupal system path (if one exists). + * - source: return the Drupal system URL for a path alias (if one exists). + * @param $path + * The path to investigate for corresponding aliases or system URLs. + */ +function drupal_lookup_path($action, $path = '') { + static $map = array(); + static $count = NULL; + + + if ($count === NULL) { + $count = db_result(db_query('SELECT COUNT(pid) FROM {url_alias}')); + } + + if ($action == 'wipe') { + $map = array(); + } + elseif ($count > 0 && $path != '') { + if ($action == 'alias') { + if (isset($map[$path])) { + return $map[$path]; + } + if ($alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path))) { + $map[$path] = $alias; + return $alias; + } + else { + $map[$path] = $path; + } + } + elseif ($action == 'source') { + if ($alias = array_search($path, $map)) { + return $alias; + } + if (!isset($map[$path])) { + if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path))) { + $map[$src] = $path; + return $src; + } + } + } + } + + return FALSE; +} + +/** * Given an internal Drupal path, return the alias set by the administrator. */ function drupal_get_path_alias($path) { - if (($map = drupal_get_path_map()) && ($newpath = array_search($path, $map))) { - return $newpath; + $result = $path; + if ($alias = drupal_lookup_path('alias', $path)) { + $result = $alias; } - elseif (function_exists('conf_url_rewrite')) { - return conf_url_rewrite($path, 'outgoing'); - } - else { - // No alias found. Return the normal path. - return $path; + if (function_exists('conf_url_rewrite') && $result == $path && ($return = conf_url_rewrite($path, 'outgoing'))) { + $result = $return; } + return $result; } /** Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.434.2.20 diff -u -p -r1.434.2.20 common.inc --- includes/common.inc 13 Mar 2006 21:29:57 -0000 1.434.2.20 +++ includes/common.inc 25 Apr 2006 08:46:45 -0000 @@ -68,22 +68,21 @@ function drupal_get_html_head() { * Regenerate the path map from the information in the database. */ function drupal_rebuild_path_map() { - drupal_get_path_map('rebuild'); + drupal_lookup_path('wipe'); } /** * Given a path alias, return the internal path it represents. */ function drupal_get_normal_path($path) { - if (($map = drupal_get_path_map()) && isset($map[$path])) { - return $map[$path]; + $result = $path; + if ($src = drupal_lookup_path('source', $path)) { + $result = $src; } - elseif (function_exists('conf_url_rewrite')) { - return conf_url_rewrite($path, 'incoming'); - } - else { - return $path; + if (function_exists('conf_url_rewrite') && $result == $path && ($return = conf_url_rewrite($path, 'incoming'))) { + $result = $return; } + return $result; } /**