? .DS_Store ? 595972_ajax_settings.patch ? attached-links-on-everything-473268-152.patch ? head.db ? path_api.patch ? path_api_4.patch ? rdf.module.patch ? rdf.module31.patch ? test.txt ? misc/attached_links.css ? misc/attached_links.js ? misc/configure.png ? misc/delete.png ? misc/edit.png ? modules/.DS_Store ? modules/rdf ? sites/default/files ? sites/default/private ? sites/default/settings.php Index: includes/path.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/path.inc,v retrieving revision 1.44 diff -u -p -r1.44 path.inc --- includes/path.inc 2 Aug 2009 06:48:24 -0000 1.44 +++ includes/path.inc 15 Oct 2009 06:21:02 -0000 @@ -47,7 +47,7 @@ function drupal_lookup_path($action, $pa global $language; $cache = &drupal_static(__FUNCTION__, array( 'map' => array(), - 'no_src' => array(), + 'no_source' => array(), 'whitelist' => NULL, 'system_paths' => array(), 'no_aliases' => array(), @@ -83,7 +83,7 @@ function drupal_lookup_path($action, $pa // 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. - $cache['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( + $cache['map'][$path_language] = db_query("SELECT source, alias FROM {url_alias} WHERE source IN (:system) AND language IN (:language, '') ORDER BY language ASC, pid ASC", array( ':system' => $cache['system_paths'], ':language' => $path_language ))->fetchAllKeyed(); @@ -104,35 +104,35 @@ function drupal_lookup_path($action, $pa // For system paths which were not cached, query aliases individually. else if (!isset($cache['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, pid DESC", array( - ':src' => $path, + $alias = db_query("SELECT alias FROM {url_alias} WHERE source = :source AND language IN (:language, '') ORDER BY language DESC, pid DESC", array( + ':source' => $path, ':language' => $path_language ))->fetchField(); $cache['map'][$path_language][$path] = $alias; return $alias; } } - // Check $no_src for this $path in case we've already determined that there + // Check $no_source for this $path in case we've already determined that there // isn't a path that has this alias - elseif ($action == 'source' && !isset($cache['no_src'][$path_language][$path])) { + elseif ($action == 'source' && !isset($cache['no_source'][$path_language][$path])) { // Look for the value $path within the cached $map - $src = ''; - if (!isset($cache['map'][$path_language]) || !($src = array_search($path, $cache['map'][$path_language]))) { + $source = ''; + if (!isset($cache['map'][$path_language]) || !($source = array_search($path, $cache['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, pid DESC", array( - ':dst' => $path, + if ($source = db_query("SELECT source FROM {url_alias} WHERE alias = :alias AND language IN (:language, '') ORDER BY language DESC, pid DESC", array( + ':alias' => $path, ':language' => $path_language)) ->fetchField()) { - $cache['map'][$path_language][$src] = $path; + $cache['map'][$path_language][$source] = $path; } else { // We can't record anything into $map because we do not have a valid // index and there is no need because we have not learned anything - // about any Drupal path. Thus cache to $no_src. - $cache['no_src'][$path_language][$path] = TRUE; + // about any Drupal path. Thus cache to $no_source. + $cache['no_source'][$path_language][$path] = TRUE; } } - return $src; + return $source; } } @@ -205,8 +205,8 @@ function drupal_get_path_alias($path = N */ function drupal_get_normal_path($path, $path_language = '') { $result = $path; - if ($src = drupal_lookup_path('source', $path, $path_language)) { - $result = $src; + if ($source = drupal_lookup_path('source', $path, $path_language)) { + $result = $source; } if (function_exists('custom_url_rewrite_inbound')) { // Modules may alter the inbound request path by reference. @@ -367,7 +367,7 @@ function drupal_path_alias_whitelist_reb // path it corresponds to. This is the portion of the path before the first / // if present, otherwise the whole path itself. $whitelist = array(); - $result = db_query("SELECT SUBSTRING_INDEX(src, '/', 1) AS path FROM {url_alias} GROUP BY path"); + $result = db_query("SELECT SUBSTRING_INDEX(source, '/', 1) AS path FROM {url_alias} GROUP BY path"); foreach ($result as $row) { $whitelist[$row->path] = TRUE; } Index: modules/locale/locale.test =================================================================== RCS file: /cvs/drupal/drupal/modules/locale/locale.test,v retrieving revision 1.44 diff -u -p -r1.44 locale.test --- modules/locale/locale.test 13 Oct 2009 21:34:14 -0000 1.44 +++ modules/locale/locale.test 15 Oct 2009 06:21:02 -0000 @@ -1268,8 +1268,8 @@ class LocalePathFunctionalTest extends D $path = 'admin/config/search/path/add'; $english_path = $this->randomName(8); $edit = array( - 'src' => 'node/' . $node->nid, - 'dst' => $english_path, + 'source' => 'node/' . $node->nid, + 'alias' => $english_path, 'language' => 'en', ); $this->drupalPost($path, $edit, t('Create new alias')); @@ -1277,8 +1277,8 @@ class LocalePathFunctionalTest extends D // Create a path alias in new custom language. $custom_language_path = $this->randomName(8); $edit = array( - 'src' => 'node/' . $node->nid, - 'dst' => $custom_language_path, + 'source' => 'node/' . $node->nid, + 'alias' => $custom_language_path, 'language' => $langcode, ); $this->drupalPost($path, $edit, t('Create new alias')); Index: modules/path/path.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/path/path.admin.inc,v retrieving revision 1.33 diff -u -p -r1.33 path.admin.inc --- modules/path/path.admin.inc 14 Oct 2009 20:42:47 -0000 1.33 +++ modules/path/path.admin.inc 15 Oct 2009 06:21:02 -0000 @@ -19,8 +19,8 @@ function path_admin_overview($keys = NUL $multilanguage = (module_exists('locale') || $alias_exists); $header = array( - array('data' => t('Alias'), 'field' => 'dst', 'sort' => 'asc'), - array('data' => t('System'), 'field' => 'src'), + array('data' => t('Alias'), 'field' => 'alias', 'sort' => 'asc'), + array('data' => t('System'), 'field' => 'source'), array('data' => t('Operations'), 'colspan' => '2') ); if ($multilanguage) { @@ -30,7 +30,7 @@ function path_admin_overview($keys = NUL $query = db_select('url_alias')->extend('PagerDefault')->extend('TableSort'); if ($keys) { // Replace wildcards with PDO wildcards. - $query->condition('dst', '%' . preg_replace('!\*+!', '%', $keys) . '%', 'LIKE'); + $query->condition('alias', '%' . preg_replace('!\*+!', '%', $keys) . '%', 'LIKE'); } $result = $query ->fields('url_alias') @@ -43,15 +43,15 @@ function path_admin_overview($keys = NUL foreach ($result as $data) { $row = array( 'data' => array( - l($data->dst, $data->src), - l($data->src, $data->src, array('alias' => TRUE)), + l($data->alias, $data->source), + l($data->source, $data->source, array('alias' => TRUE)), l(t('edit'), "admin/config/search/path/edit/$data->pid", array('query' => $destination)), l(t('delete'), "admin/config/search/path/delete/$data->pid", array('query' => $destination)), ), ); // If the system path maps to a different URL alias, highlight this table // row to let the user know of old aliases. - if ($data->dst != drupal_get_path_alias($data->src, $data->language)) { + if ($data->alias != drupal_get_path_alias($data->source, $data->language)) { $row['class'] = array('warning'); } if ($multilanguage) { @@ -78,11 +78,10 @@ function path_admin_overview($keys = NUL /** * Menu callback; handles pages for creating and editing URL aliases. */ -function path_admin_edit($pid = 0) { - if ($pid) { - $alias = path_load($pid); - drupal_set_title($alias['dst']); - $output = drupal_get_form('path_admin_form', $alias); +function path_admin_edit($path = array()) { + if ($path) { + drupal_set_title($path['alias']); + $output = drupal_get_form('path_admin_form', $path); } else { $output = drupal_get_form('path_admin_form'); @@ -98,41 +97,48 @@ function path_admin_edit($pid = 0) { * @see path_admin_form_validate() * @see path_admin_form_submit() */ -function path_admin_form($form, &$form_state, $edit = array('src' => '', 'dst' => '', 'language' => '', 'pid' => NULL)) { - - $form['#alias'] = $edit; - - $form['src'] = array( +function path_admin_form($form, &$form_state, $path = array('source' => '', 'alias' => '', 'language' => '', 'pid' => NULL)) { + $form['source'] = array( '#type' => 'textfield', '#title' => t('Existing system path'), - '#default_value' => $edit['src'], + '#default_value' => $path['source'], '#maxlength' => 255, '#size' => 45, '#description' => t('Specify the existing path you wish to alias. For example: node/28, forum/1, taxonomy/term/1+2.'), '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='), '#required' => TRUE, ); - $form['dst'] = array( + $form['alias'] = array( '#type' => 'textfield', '#title' => t('Path alias'), - '#default_value' => $edit['dst'], + '#default_value' => $path['alias'], '#maxlength' => 255, '#size' => 45, '#description' => t('Specify an alternative path by which this data can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'), '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='), '#required' => TRUE, ); - // This will be a hidden value unless locale module is enabled + + // This will be a hidden value unless locale module is enabled. $form['language'] = array( '#type' => 'value', - '#value' => $edit['language'] + '#value' => $path['language'] ); - if ($edit['pid']) { - $form['pid'] = array('#type' => 'hidden', '#value' => $edit['pid']); - $form['submit'] = array('#type' => 'submit', '#value' => t('Update alias')); + if ($path['pid']) { + $form['pid'] = array( + '#type' => 'hidden', + '#value' => $path['pid'], + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Update alias'), + ); } else { - $form['submit'] = array('#type' => 'submit', '#value' => t('Create new alias')); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Create new alias'), + ); } return $form; @@ -140,37 +146,42 @@ function path_admin_form($form, &$form_s /** - * Verify that a new URL alias is valid + * Verify that a URL alias is valid */ function path_admin_form_validate($form, &$form_state) { - $src = $form_state['values']['src']; - $dst = $form_state['values']['dst']; + $source = $form_state['values']['source']; + $alias = $form_state['values']['alias']; $pid = isset($form_state['values']['pid']) ? $form_state['values']['pid'] : 0; // Language is only set if locale module is enabled, otherwise save for all languages. $language = isset($form_state['values']['language']) ? $form_state['values']['language'] : ''; - $has_alias = db_query("SELECT COUNT(dst) FROM {url_alias} WHERE pid <> :pid AND dst = :dst AND language = :language", array( - ':pid' => $pid, - ':dst' => $dst, + $has_alias = db_query("SELECT COUNT(alias) FROM {url_alias} WHERE pid <> :pid AND alias = :alias AND language = :language", array( + ':pid' => $pid, + ':alias' => $alias, ':language' => $language, )) ->fetchField(); if ($has_alias) { - form_set_error('dst', t('The alias %alias is already in use in this language.', array('%alias' => $dst))); + form_set_error('alias', t('The alias %alias is already in use in this language.', array('%alias' => $alias))); } - $item = menu_get_item($src); + $item = menu_get_item($source); if (!$item || !$item['access']) { - form_set_error('src', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $src))); + form_set_error('source', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $source))); } } /** - * Save a new URL alias to the database. + * Save a URL alias to the database. */ function path_admin_form_submit($form, &$form_state) { - // Language is only set if locale module is enabled - path_set_alias($form_state['values']['src'], $form_state['values']['dst'], isset($form_state['values']['pid']) ? $form_state['values']['pid'] : 0, isset($form_state['values']['language']) ? $form_state['values']['language'] : ''); + $path = array(); + foreach (array('source', 'alias', 'pid', 'language') as $key) { + if (isset($form_state['values'][$key])) { + $path[$key] = $form_state['values'][$key]; + } + } + path_save($path); drupal_set_message(t('The alias has been saved.')); $form_state['redirect'] = 'admin/config/search/path'; @@ -180,15 +191,17 @@ function path_admin_form_submit($form, & /** * Menu callback; confirms deleting an URL alias */ -function path_admin_delete_confirm($form, $form_state, $pid) { - $path = path_load($pid); +function path_admin_delete_confirm($form, &$form_state, $path) { if (user_access('administer url aliases')) { - $form['pid'] = array('#type' => 'value', '#value' => $pid); - $output = confirm_form($form, - t('Are you sure you want to delete path alias %title?', array('%title' => $path['dst'])), - 'admin/config/search/path'); + $form_state['path'] = $path; + return confirm_form( + $form, + t('Are you sure you want to delete path alias %title?', + array('%title' => $path['alias'])), + 'admin/config/search/path' + ); } - return $output; + return array(); } /** @@ -196,7 +209,7 @@ function path_admin_delete_confirm($form */ function path_admin_delete_confirm_submit($form, &$form_state) { if ($form_state['values']['confirm']) { - path_admin_delete($form_state['values']['pid']); + path_delete($form_state['path']['pid']); $form_state['redirect'] = 'admin/config/search/path'; return; } Index: modules/path/path.api.php =================================================================== RCS file: modules/path/path.api.php diff -N modules/path/path.api.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/path/path.api.php 15 Oct 2009 06:21:02 -0000 @@ -0,0 +1,44 @@ + array('administer url aliases'), 'file' => 'path.admin.inc', ); - $items['admin/config/search/path/edit'] = array( + $items['admin/config/search/path/edit/%path'] = array( 'title' => 'Edit alias', 'page callback' => 'path_admin_edit', + 'page arguments' => array(5), 'access arguments' => array('administer url aliases'), 'type' => MENU_CALLBACK, 'file' => 'path.admin.inc', ); - $items['admin/config/search/path/delete'] = array( + $items['admin/config/search/path/delete/%path'] = array( 'title' => 'Delete alias', 'page callback' => 'drupal_get_form', - 'page arguments' => array('path_admin_delete_confirm'), + 'page arguments' => array('path_admin_delete_confirm', 5), 'access arguments' => array('administer url aliases'), 'type' => MENU_CALLBACK, 'file' => 'path.admin.inc', @@ -72,79 +73,87 @@ function path_menu() { } /** - * Post-confirmation; delete an URL alias. - */ -function path_admin_delete($pid = 0) { - db_delete('url_alias') - ->condition('pid', $pid) - ->execute(); - drupal_set_message(t('The alias has been deleted.')); + * Fetch a specific URL alias from the database. + * + * @param $criteria + * A string representing the source, a number representing the pid, or an + * array of criteria. + */ +function path_load($criteria) { + if (is_numeric($criteria)) { + $criteria = array('pid' => $criteria); + } + else if (is_string($criteria)) { + $criteria = array('source' => $criteria); + } + else if (!is_array($criteria)) { + return FALSE; + } + $select = db_select('url_alias'); + foreach ($criteria as $field => $value) { + $select->condition($field, $value); + } + return $select + ->fields('url_alias', array('source', 'alias', 'language', 'pid')) + ->execute() + ->fetchAssoc(); } /** - * Set an aliased path for a given Drupal path, preventing duplicates. - */ -function path_set_alias($path = NULL, $alias = NULL, $pid = NULL, $language = '') { - $path = urldecode($path); - $alias = urldecode($alias); - // First we check if we deal with an existing alias and delete or modify it based on pid. + * Save a path alias to the database. + * + * @param $path + * A path array containing the following keys: + * - source: the initial path. + * - alias: the aliased path. + * - language: the language of the alias. + * - pid: unique path alias identifier (optional). + */ +function path_save($path) { + $path += array('language' => '', 'pid' => 0); + $pid = empty($path['pid']) ? 0 : $path['pid']; + $new = (bool) $pid; + unset($path['pid']); + // Make sure that this combination of source, alias, language wasn't save before. + $loaded_path = path_load($path); + if ($loaded_path) { + return $loaded_path; + } if ($pid) { - // An existing alias. - if (!$path || !$alias) { - // Delete the alias based on pid. - db_delete('url_alias') - ->condition('pid', $pid) - ->execute(); - } - else { - // Update the existing alias. - db_update('url_alias') - ->fields(array( - 'src' => $path, - 'dst' => $alias, - 'language' => $language)) - ->condition('pid', $pid) - ->execute(); - } - } - elseif ($path && $alias) { - // Check for existing aliases. - if ($alias == drupal_get_path_alias($path, $language)) { - // There is already such an alias, neutral or in this language. - // Update the alias based on alias; setting the language if not yet done. - db_update('url_alias') - ->fields(array( - 'src' => $path, - 'dst' => $alias, - 'language' => $language - )) - ->condition('dst', $alias) - ->execute(); - } - else { - // A new alias. Add it to the database. - db_insert('url_alias') - ->fields(array( - 'src' => $path, - 'dst' => $alias, - 'language' => $language, - )) - ->execute(); - } + db_update('url_alias') + ->fields($path) + ->condition('pid', $pid) + ->execute(); } else { - // Delete the alias. - if ($alias) { - db_delete('url_alias') - ->condition('dst', $alias) - ->execute(); - } - else { - db_delete('url_alias') - ->condition('src', $path) - ->execute(); - } + $pid = db_insert('url_alias') + ->fields($path) + ->execute(); } + $path['pid'] = $pid; + module_invoke_all('path_' . ($new ? 'insert' : 'update'), $path); + + drupal_clear_path_cache(); + return $path; +} + +/** + * Delete a URL alias. + * + * @param $criteria + * A number representing the pid or an array of criteria. + */ +function path_delete($criteria) { + if (!is_array($criteria)) { + $criteria = array('pid' => $criteria); + } + $path = path_load($criteria); + $delete = db_delete('url_alias'); + foreach ($criteria as $field => $value) { + $delete->condition($field, $value); + } + $delete->execute(); + module_invoke_all('path_delete', $path); drupal_clear_path_cache(); } @@ -154,16 +163,18 @@ function path_set_alias($path = NULL, $a function path_node_validate($node, $form) { if (user_access('create url aliases') || user_access('administer url aliases')) { if (isset($node->path)) { - $language = isset($node->language) ? $node->language : ''; - $node->path = trim($node->path); - $has_alias = db_query("SELECT COUNT(dst) FROM {url_alias} WHERE src <> :src AND dst = :dst AND language = :language", array( - ':src' => "node/$node->nid", - ':dst' => $node->path, - ':language' => $language, - )) - ->fetchField(); - - if ($has_alias) { + if (!is_array($node->path)) { + $node->path = array('alias' => $node->path); + } + $select = db_select('url_alias')->condition('alias', trim($node->path['alias'])); + $select->addExpression('COUNT(alias)'); + if ($node->nid) { + $select->condition('source', 'node/' . $node->nid, '<>'); + } + if (isset($node->language)) { + $select->condition('language', $node->language); + } + if ($select->execute()->fetchField()) { form_set_error('path', t('The path is already in use.')); } } @@ -175,10 +186,12 @@ function path_node_validate($node, $form */ function path_node_load($nodes, $types) { foreach ($nodes as $node) { - $language = isset($node->language) ? $node->language : ''; - $path = 'node/' . $node->nid; - $alias = drupal_get_path_alias($path, $language); - if ($path != $alias) { + $criteria = array('source' => 'node/' . $node->nid); + if (isset($node->language)) { + $criteria['language'] = $node->language; + } + $alias = path_load($criteria); + if ($alias) { $node->path = $alias; } } @@ -188,13 +201,16 @@ function path_node_load($nodes, $types) * Implement hook_node_insert(). */ function path_node_insert($node) { - if (user_access('create url aliases') || user_access('administer url aliases')) { - $language = isset($node->language) ? $node->language : ''; - // Don't try to insert if path is NULL. We may have already set - // the alias ahead of time. - if (isset($node->path)) { - path_set_alias('node/' . $node->nid, $node->path, NULL, $language); - } + if ((user_access('create url aliases') || user_access('administer url aliases')) && isset($node->path)) { + if (!is_array($node->path)) { + $node->path = array('alias' => $node->path); + } + + $node->path += array( + 'source' => 'node/' . $node->nid, + 'language' => isset($node->language) ? $node->language : '', + ); + $node->path = path_save($node->path); } } @@ -202,9 +218,18 @@ function path_node_insert($node) { * Implement hook_node_update(). */ function path_node_update($node) { - if (user_access('create url aliases') || user_access('administer url aliases')) { - $language = isset($node->language) ? $node->language : ''; - path_set_alias('node/' . $node->nid, isset($node->path) ? $node->path : NULL, isset($node->pid) ? $node->pid : NULL, $language); + if ((user_access('create url aliases') || user_access('administer url aliases')) && isset($node->path)) { + if (!is_array($node->path)) { + $node->path = array('alias' => $node->path); + } + if (isset($node->pid)) { + $node->path['pid'] = $node->pid; + } + $node->path += array( + 'source' => 'node/' . $node->nid, + 'language' => isset($node->language) ? $node->language : '', + ); + path_save($node->path); } } @@ -212,14 +237,20 @@ function path_node_update($node) { * Implement hook_node_delete(). */ function path_node_delete($node) { - path_set_alias('node/' . $node->nid); + if (isset($node->path)) { + if (!is_array($node->path)) { + $node->path = path_load(array('alias' => $node->path)); + } + path_delete($node->path['pid']); + unset($node->path); + } } /** * Implement hook_taxonomy_term_delete(). */ function path_taxonomy_term_delete($term) { - path_set_alias('taxonomy/term/' . $term->tid); + path_delete(path_load('taxonomy/term/' . $term->tid)); } /** @@ -227,7 +258,15 @@ function path_taxonomy_term_delete($term */ function path_form_alter(&$form, $form_state, $form_id) { if (!empty($form['#node_edit_form'])) { - $path = isset($form['#node']->path) ? $form['#node']->path : NULL; + $path = NULL; + if (isset($form['#node']->path)) { + if (is_array($form['#node']->path)) { + $path = $form['#node']->path['alias']; + } + else { + $path = $form['#node']->path; + } + } $form['path'] = array( '#type' => 'fieldset', '#title' => t('URL path settings'), @@ -252,11 +291,7 @@ function path_form_alter(&$form, $form_s if ($path) { $form['path']['pid'] = array( '#type' => 'value', - '#value' => db_query("SELECT pid FROM {url_alias} WHERE dst = :dst AND language = :language", array( - ':dst' => $path, - ':language' => $form['#node']->language - )) - ->fetchField(), + '#value' => $form['#node']->path['pid'], ); } } @@ -271,13 +306,14 @@ function path_form_taxonomy_form_term_al // After a new term is added, populate the path field if it was set. if (!empty($form['#term']['path'])) { $path = $form['#term']['path']; + if (!is_array($path)) { + $path = path_load(array('alias' => $path)); + } } else { - $url = 'taxonomy/term/' . $form['#term']['tid']; - $alias = drupal_get_path_alias($url); - + $alias = path_load('taxonomy/term/' . $form['#term']['tid']); // Since drupal_get_path_alias() can return the default path, check if we really have an alias. - if ($alias != $url) { + if ($alias['alias'] != 'taxonomy/term/' . $form['#term']['tid']) { $path = $alias; } else { @@ -289,7 +325,7 @@ function path_form_taxonomy_form_term_al $form['identification']['path'] = array( '#type' => 'textfield', '#title' => t('URL alias'), - '#default_value' => $path, + '#default_value' => $path['alias'], '#maxlength' => 255, '#weight' => 0, '#access' => (user_access('create url aliases') || user_access('administer url aliases')), @@ -300,7 +336,7 @@ function path_form_taxonomy_form_term_al $form['identification']['path']['pid'] = array( '#type' => 'value', '#access' => (user_access('create url aliases') || user_access('administer url aliases')), - '#value' => db_query("SELECT pid FROM {url_alias} WHERE dst = :dst", array(':dst' => $path))->fetchField(), + '#value' => db_query("SELECT pid FROM {url_alias} WHERE alias = :alias", array(':alias' => $path['alias']))->fetchField(), ); } } @@ -310,13 +346,13 @@ function path_form_taxonomy_form_term_al * Path validation callback for taxonomy_form_term. */ function path_taxonomy_term_validate($form, &$form_state) { - $pid = db_query("SELECT pid FROM {url_alias} WHERE dst = :dst", array(':dst' => $form_state['values']['path']))->fetchField(); - if ($pid) { + $path = path_load(array('alias' => $form_state['values']['path'])); + if ($path) { // If the pid matches the one in use for this term then we are fine. - if (isset($form_state['values']['pid']) && $pid == $form_state['values']['pid']) { + if (isset($form_state['values']['pid']) && $path['pid'] == $form_state['values']['pid']) { return; } - form_set_error('path', 'The URL alias is already in use.'); + form_set_error('path', t('The URL alias is already in use.')); } } @@ -326,10 +362,12 @@ function path_taxonomy_term_validate($fo function path_taxonomy_term_submit($form, &$form_state) { // Make sure this is not triggered on the delete confirmation form. if (empty($form_state['confirm_delete'])) { - $url = 'taxonomy/term/' . $form_state['tid']; - $alias = isset($form_state['values']['path']) ? $form_state['values']['path'] : NULL; - $pid = isset($form_state['values']['pid']) ? $form_state['values']['pid'] : NULL; - path_set_alias($url, $alias, $pid); + $path = array( + 'source' => 'taxonomy/term/' . $form_state['tid'], + 'alias' => isset($form_state['values']['path']) ? $form_state['values']['path'] : NULL, + 'pid' => isset($form_state['values']['pid']) ? $form_state['values']['pid'] : NULL, + ); + path_save($path); } } @@ -348,10 +386,3 @@ function path_permission() { ), ); } - -/** - * Fetch a specific URL alias from the database. - */ -function path_load($pid) { - return db_query('SELECT * FROM {url_alias} WHERE pid = :pid', array(':pid' => $pid))->fetchAssoc(); -} Index: modules/path/path.test =================================================================== RCS file: /cvs/drupal/drupal/modules/path/path.test,v retrieving revision 1.22 diff -u -p -r1.22 path.test --- modules/path/path.test 11 Oct 2009 03:07:19 -0000 1.22 +++ modules/path/path.test 15 Oct 2009 06:21:02 -0000 @@ -35,20 +35,20 @@ class PathTestCase extends DrupalWebTest // Create alias. $edit = array(); - $edit['src'] = 'node/' . $node1->nid; - $edit['dst'] = $this->randomName(8); + $edit['source'] = 'node/' . $node1->nid; + $edit['alias'] = $this->randomName(8); $this->drupalPost('admin/config/search/path/add', $edit, t('Create new alias')); // Visit the system path for the node and confirm a cache entry is // created. cache_clear_all('*', 'cache_path', TRUE); - $this->drupalGet($edit['src']); - $this->assertTrue(cache_get($edit['src'], 'cache_path'), t('Cache entry was created.')); + $this->drupalGet($edit['source']); + $this->assertTrue(cache_get($edit['source'], 'cache_path'), t('Cache entry was created.')); // Visit the alias for the node and confirm a cache entry is created. cache_clear_all('*', 'cache_path', TRUE); - $this->drupalGet($edit['dst']); - $this->assertTrue(cache_get($edit['src'], 'cache_path'), t('Cache entry was created.')); + $this->drupalGet($edit['alias']); + $this->assertTrue(cache_get($edit['source'], 'cache_path'), t('Cache entry was created.')); } /** @@ -60,25 +60,26 @@ class PathTestCase extends DrupalWebTest // Create alias. $edit = array(); - $edit['src'] = 'node/' . $node1->nid; - $edit['dst'] = $this->randomName(8); + $edit['source'] = 'node/' . $node1->nid; + $edit['alias'] = $this->randomName(8); $this->drupalPost('admin/config/search/path/add', $edit, t('Create new alias')); // Confirm that the alias works. - $this->drupalGet($edit['dst']); + $this->drupalGet($edit['alias']); $this->assertText($node1->title[FIELD_LANGUAGE_NONE][0]['value'], 'Alias works.'); // Change alias. - $pid = $this->getPID($edit['dst']); + $pid = $this->getPID($edit['alias']); - $previous = $edit['dst']; - $edit['dst'] = $this->randomName(8); + $previous = $edit['alias']; + $edit['alias'] = $this->randomName(8); $this->drupalPost('admin/config/search/path/edit/' . $pid, $edit, t('Update alias')); // Confirm that the alias works. - $this->drupalGet($edit['dst']); + $this->drupalGet($edit['alias']); $this->assertText($node1->title[FIELD_LANGUAGE_NONE][0]['value'], 'Changed alias works.'); + drupal_static_reset('drupal_lookup_path'); // Confirm that previous alias no longer works. $this->drupalGet($previous); $this->assertNoText($node1->title, 'Previous alias no longer works.'); @@ -88,18 +89,18 @@ class PathTestCase extends DrupalWebTest $node2 = $this->drupalCreateNode(); // Set alias to second test node. - $edit['src'] = 'node/' . $node2->nid; - // leave $edit['dst'] the same + $edit['source'] = 'node/' . $node2->nid; + // leave $edit['alias'] the same $this->drupalPost('admin/config/search/path/add', $edit, t('Create new alias')); // Confirm no duplicate was created. - $this->assertRaw(t('The alias %alias is already in use in this language.', array('%alias' => $edit['dst'])), 'Attempt to move alias was rejected.'); + $this->assertRaw(t('The alias %alias is already in use in this language.', array('%alias' => $edit['alias'])), 'Attempt to move alias was rejected.'); // Delete alias. $this->drupalPost('admin/config/search/path/delete/' . $pid, array(), t('Confirm')); // Confirm that the alias no longer works. - $this->drupalGet($edit['dst']); + $this->drupalGet($edit['alias']); $this->assertNoText($node1->title, 'Alias was successfully deleted.'); } @@ -151,8 +152,8 @@ class PathTestCase extends DrupalWebTest $this->assertNoText($node1->title, 'Alias was successfully deleted.'); } - function getPID($dst) { - return db_query("SELECT pid FROM {url_alias} WHERE dst = :dst", array(':dst' => $dst))->fetchField(); + function getPID($alias) { + return db_query("SELECT pid FROM {url_alias} WHERE alias = :alias", array(':alias' => $alias))->fetchField(); } } Index: modules/system/system.install =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.install,v retrieving revision 1.399 diff -u -p -r1.399 system.install --- modules/system/system.install 14 Oct 2009 10:56:35 -0000 1.399 +++ modules/system/system.install 15 Oct 2009 06:21:03 -0000 @@ -1576,14 +1576,14 @@ function system_schema() { 'unsigned' => TRUE, 'not null' => TRUE, ), - 'src' => array( + 'source' => array( 'description' => 'The Drupal path this alias is for; e.g. node/12.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', ), - 'dst' => array( + 'alias' => array( 'description' => 'The alias for this path; e.g. title-of-the-story.', 'type' => 'varchar', 'length' => 255, @@ -1599,11 +1599,11 @@ function system_schema() { ), ), 'unique keys' => array( - 'dst_language_pid' => array('dst', 'language', 'pid'), + 'alias_language_pid' => array('alias', 'language', 'pid'), ), 'primary key' => array('pid'), 'indexes' => array( - 'src_language_pid' => array('src', 'language', 'pid'), + 'source_language_pid' => array('source', 'language', 'pid'), ), ); @@ -1937,7 +1937,6 @@ function system_update_7007() { return implode(', ', $messages); } - /** * Use the poll_choice primary key to record votes in poll_votes rather than * the choice order. Rename chorder to weight. @@ -2726,6 +2725,21 @@ function system_update_7040() { } /** + * Rename dst and src to source and alias. + */ +function system_update_7041() { + // Drop indexes. + db_drop_index('url_alias', 'src_language_pid'); + db_drop_unique_key('url_alias', 'dst_language_pid'); + // Rename fields. + db_change_field('url_alias', 'src', 'source', array('varchar' => 'int', 'length' => 255, 'not null' => TRUE, 'default' => 0)); + db_change_field('url_alias', 'dst', 'alias', array('varchar' => 'int', 'length' => 255, 'not null' => TRUE, 'default' => 0)); + // Add indexes back. + db_add_index('url_alias', 'source_language_pid', array('source', 'language', 'pid')); + db_add_unique_key('url_alias', 'alias_language_pid', array('alias', 'language', 'pid')); +} + +/** * @} End of "defgroup updates-6.x-to-7.x" * The next series of updates should start at 8000. */