? .DS_Store
? path_module_needs_a_real_api.patch
? sites/default/files
? sites/default/settings.php
Index: modules/path/path.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/path/path.admin.inc,v
retrieving revision 1.14
diff -u -p -r1.14 path.admin.inc
--- modules/path/path.admin.inc	13 Oct 2008 00:33:03 -0000	1.14
+++ modules/path/path.admin.inc	10 Nov 2008 06:23:49 -0000
@@ -65,8 +65,8 @@ function path_admin_overview($keys = NUL
  */
 function path_admin_edit($pid = 0) {
   if ($pid) {
-    $alias = path_load($pid);
-    drupal_set_title($alias['dst']);
+    $alias = path_load((int)$pid);
+    drupal_set_title($alias['path']);
     $output = drupal_get_form('path_admin_form', $alias);
   }
   else {
@@ -83,24 +83,23 @@ function path_admin_edit($pid = 0) {
  * @see path_admin_form_validate()
  * @see path_admin_form_submit()
  */
-function path_admin_form(&$form_state, $edit = array('src' => '', 'dst' => '', 'language' => '', 'pid' => NULL)) {
+function path_admin_form(&$form_state, $path = array('path' => '', 'alias' => '', 'language' => '', 'pid' => NULL)) {
+  $form['#alias'] = $path;
 
-  $form['#alias'] = $edit;
-
-  $form['src'] = array(
+  $form['path'] = array(
     '#type' => 'textfield',
     '#title' => t('Existing system path'),
-    '#default_value' => $edit['src'],
+    '#default_value' => $path['path'],
     '#maxlength' => 64,
     '#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' => 64,
     '#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.'),
@@ -110,14 +109,23 @@ function path_admin_form(&$form_state, $
   // 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' => 'value',
+      '#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;
@@ -128,18 +136,18 @@ function path_admin_form(&$form_state, $
  * Verify that a new URL alias is valid
  */
 function path_admin_form_validate($form, &$form_state) {
-  $src = $form_state['values']['src'];
-  $dst = $form_state['values']['dst'];
+  $path = $form_state['values']['path'];
+  $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'] : '';
 
-  if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE pid != %d AND dst = '%s' AND language = '%s'", $pid, $dst, $language))) {
-    form_set_error('dst', t('The alias %alias is already in use in this language.', array('%alias' => $dst)));
+  if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE pid != %d AND dst = '%s' AND language = '%s'", $pid, $alias, $language))) {
+    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($path);
   if (!$item) {
-    form_set_error('src', t("The path '@link_path' is invalid.", array('@link_path' => $src)));
+    form_set_error('path', t("The path '@link_path' is invalid.", array('@link_path' => $path)));
   }
 }
 
@@ -148,7 +156,7 @@ function path_admin_form_validate($form,
  */
 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_save($form_state['values']);
 
   drupal_set_message(t('The alias has been saved.'));
   $form_state['redirect'] = 'admin/build/path';
@@ -163,7 +171,7 @@ function path_admin_delete_confirm($form
   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'])),
+      t('Are you sure you want to delete path alias %title?', array('%title' => $path['path'])),
       isset($_GET['destination']) ? $_GET['destination'] : 'admin/build/path');
   }
   return $output;
@@ -174,7 +182,8 @@ 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['values']['pid']);
+    drupal_set_message(t('The alias has been deleted.'));
     $form_state['redirect'] = 'admin/build/path';
     return;
   }
Index: modules/path/path.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/path/path.module,v
retrieving revision 1.149
diff -u -p -r1.149 path.module
--- modules/path/path.module	12 Oct 2008 04:30:06 -0000	1.149
+++ modules/path/path.module	10 Nov 2008 06:23:49 -0000
@@ -68,53 +68,84 @@ function path_menu() {
 }
 
 /**
- * Post-confirmation; delete an URL alias.
+ * Fetch a specific URL alias from the database.
  */
-function path_admin_delete($pid = 0) {
-  db_query('DELETE FROM {url_alias} WHERE pid = %d', $pid);
-  drupal_set_message(t('The alias has been deleted.'));
+function path_load($criteria) {
+  if (is_string($criteria)) {
+    $criteria = array('path' => $criteria);
+  }
+  else if (is_numeric($criteria)) {
+    $criteria = array('pid' => $criteria);
+  }
+  else if (!is_array($criteria)) {
+    return FALSE;
+  }
+  $map = array(
+    'path' => 'src',
+    'alias' => 'dst',
+  );
+  $select = db_select('url_alias');
+  foreach ($criteria as $field => $value) {
+    if (isset($map[$field])) {
+      $field = $map[$field];
+    }
+    $select->condition($field, $value);
+  }
+  $select->addField('url_alias', 'src', 'path');
+  $select->addField('url_alias', 'dst', 'alias');
+  return $select->fields('url_alias', array('language', 'pid'))
+    ->execute()
+    ->fetch(PDO::FETCH_ASSOC);
 }
 
 /**
  * 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.
-  if ($pid) {
-    // An existing alias.
-    if (!$path || !$alias) {
-      // Delete the alias based on pid.
-      db_query('DELETE FROM {url_alias} WHERE pid = %d', $pid);
-    }
-    else {
-      // Update the existing alias.
-      db_query("UPDATE {url_alias} SET src = '%s', dst = '%s', language = '%s' WHERE pid = %d", $path, $alias, $language, $pid);
-    }
-  }
-  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_query("UPDATE {url_alias} SET src = '%s', dst = '%s', language = '%s' WHERE dst = '%s'", $path, $alias, $language, $alias);
-    }
-    else {
-      // A new alias. Add it to the database.
-      db_query("INSERT INTO {url_alias} (src, dst, language) VALUES ('%s', '%s', '%s')", $path, $alias, $language);
-    }
+ *
+ * @param $path
+ *   A path array containing the following keys:
+ *   - Path: the initial path.
+ *   - Alias: the aliased path.
+ *   - Language: the language of the alias.
+*    - Pid: unique path alias identifier (optional).
+ */
+function path_save($path) {
+  $save = array(
+    'src' => urldecode($path['path']),
+    'dst' => urldecode($path['alias']),
+    'language' => $path['language'],
+  );
+  if (!isset($path['pid']) || !$path['pid']) {
+    drupal_write_record('url_alias', $save);
+    $pid = $save['pid'];
   }
   else {
-    // Delete the alias.
-    if ($alias) {
-      db_query("DELETE FROM {url_alias} WHERE dst = '%s'", $alias);
-    }
-    else {
-      db_query("DELETE FROM {url_alias} WHERE src = '%s'", $path);
-    }
+    $save['pid'] = $pid = $path['pid'];
+    drupal_write_record('url_alias', $save, 'pid');
   }
+
   drupal_clear_path_cache();
+  return $pid;
+}
+
+/**
+ * Delete a URL alias
+ */
+function path_delete($criteria) {
+  if (!is_array($criteria)) {
+    $criteria = array('pid' => $criteria);
+  }
+  $map = array(
+    'path' => 'src',
+    'alias' => 'dst',
+  );
+  $delete = db_delete('url_alias');
+  foreach ($criteria as $field => $value) {
+    if (isset($map[$field])) {
+      $field = $map[$field];
+    }
+    $delete->condition($field, $value);
+  }
+  return $delete->execute();
 }
 
 /**
@@ -124,8 +155,8 @@ function path_nodeapi_validate(&$node, $
   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);
-      if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE dst = '%s' AND src != '%s' AND language = '%s'", $node->path, "node/$node->nid", $language))) {
+      $node->path['alias'] = trim($node->path['alias']);
+      if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE dst = '%s' AND src != '%s' AND language = '%s'", $node->path['alias'], "node/$node->nid", $language))) {
         form_set_error('path', t('The path is already in use.'));
       }
     }
@@ -138,8 +169,8 @@ function path_nodeapi_validate(&$node, $
 function path_nodeapi_load(&$node, $arg) {
   $language = isset($node->language) ? $node->language : '';
   $path = 'node/' . $node->nid;
-  $alias = drupal_get_path_alias($path, $language);
-  if ($path != $alias) {
+  $alias = path_load(array('path' => $path, 'language' => $language));
+  if ($alias) {
     $node->path = $alias;
   }
 }
@@ -149,11 +180,14 @@ function path_nodeapi_load(&$node, $arg)
  */
 function path_nodeapi_insert(&$node, $arg) {
   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);
+      $node->path += array(
+        'path' => 'node/' . $node->nid,
+        'language' => isset($node->language) ? $node->language : '',
+      );
+      $node->path['pid'] = path_save($node->path);
     }
   }
 }
@@ -163,8 +197,11 @@ function path_nodeapi_insert(&$node, $ar
  */
 function path_nodeapi_update(&$node, $arg) {
   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);
+    $node->path += array(
+      'path' => 'node/' . $node->nid,
+      'language' => isset($node->language) ? $node->language : '',
+    );
+    path_save($node->path);
   }
 }
 
@@ -172,12 +209,9 @@ function path_nodeapi_update(&$node, $ar
  * Implementation of hook_nodeapi_delete().
  */
 function path_nodeapi_delete(&$node, $arg) {
-  if (user_access('create url aliases') || user_access('administer url aliases')) {
-    $language = isset($node->language) ? $node->language : '';
-    $path = 'node/' . $node->nid;
-    if (drupal_get_path_alias($path) != $path) {
-      path_set_alias($path);
-    }
+  if ($node->path &&(user_access('create url aliases') || user_access('administer url aliases'))) {
+    path_delete($node->path);
+    unset($node->path);
   }
 }
 
@@ -186,7 +220,7 @@ function path_nodeapi_delete(&$node, $ar
  */
 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 = isset($form['#node']->path) ? $form['#node']->path['alias'] : NULL;
     $form['path'] = array(
       '#type' => 'fieldset',
       '#title' => t('URL path settings'),
@@ -194,8 +228,9 @@ function path_form_alter(&$form, $form_s
       '#collapsed' => empty($path),
       '#access' => user_access('create url aliases'),
       '#weight' => 30,
+      '#tree' => TRUE,
     );
-    $form['path']['path'] = array(
+    $form['path']['alias'] = array(
       '#type' => 'textfield',
       '#default_value' => $path,
       '#maxlength' => 250,
@@ -206,7 +241,7 @@ function path_form_alter(&$form, $form_s
     if ($path) {
       $form['path']['pid'] = array(
         '#type' => 'value',
-        '#value' => db_result(db_query("SELECT pid FROM {url_alias} WHERE dst = '%s' AND language = '%s'", $path, $form['#node']->language))
+        '#value' => $form['#node']->path['pid'],
       );
     }
   }
@@ -227,10 +262,3 @@ function path_perm() {
     ),
   );
 }
-
-/**
- * Fetch a specific URL alias from the database.
- */
-function path_load($pid) {
-  return db_fetch_array(db_query('SELECT * FROM {url_alias} WHERE pid = %d', $pid));
-}
Index: modules/path/path.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/path/path.test,v
retrieving revision 1.4
diff -u -p -r1.4 path.test
--- modules/path/path.test	13 Oct 2008 20:57:19 -0000	1.4
+++ modules/path/path.test	10 Nov 2008 06:23:49 -0000
@@ -29,23 +29,23 @@ class PathTestCase extends DrupalWebTest
 
     // Create alias.
     $edit = array();
-    $edit['src'] = 'node/' . $node1->nid;
-    $edit['dst'] = $this->randomName(8);
+    $edit['path'] = 'node/' . $node1->nid;
+    $edit['alias'] = $this->randomName(8);
     $this->drupalPost('admin/build/path/add', $edit, t('Create new alias'));
 
     // Confirm that the alias works.
-    $this->drupalGet($edit['dst']);
+    $this->drupalGet($edit['alias']);
     $this->assertText($node1->title, '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/build/path/edit/' . $pid, $edit, t('Update alias'));
 
     // Confirm that the alias works.
-    $this->drupalGet($edit['dst']);
+    $this->drupalGet($edit['alias']);
     $this->assertText($node1->title, 'Changed alias works.');
 
     // Confirm that previous alias no longer works.
@@ -57,18 +57,18 @@ class PathTestCase extends DrupalWebTest
     $node2 = $this->createNode();
 
     // Set alias to second test node.
-    $edit['src'] = 'node/' . $node2->nid;
-    // leave $edit['dst'] the same
+    $edit['path'] = 'node/' . $node2->nid;
+    // leave $edit['alias'] the same
     $this->drupalPost('admin/build/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/build/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.');
   }
 
@@ -81,20 +81,20 @@ class PathTestCase extends DrupalWebTest
 
     // Create alias.
     $edit = array();
-    $edit['path'] = $this->randomName(8);
+    $edit['path_alias'] = $this->randomName(8);
     $this->drupalPost('node/' . $node1->nid . '/edit', $edit, t('Save'));
 
     // Confirm that the alias works.
-    $this->drupalGet($edit['path']);
+    $this->drupalGet($edit['path_alias']);
     $this->assertText($node1->title, 'Alias works.');
 
     // Change alias.
-    $previous = $edit['path'];
-    $edit['path'] = $this->randomName(8);
+    $previous = $edit['path_alias'];
+    $edit['path_alias'] = $this->randomName(8);
     $this->drupalPost('node/' . $node1->nid . '/edit', $edit, t('Save'));
 
     // Confirm that the alias works.
-    $this->drupalGet($edit['path']);
+    $this->drupalGet($edit['path_alias']);
     $this->assertText($node1->title, 'Changed alias works.');
 
     // Make sure that previous alias no longer works.
@@ -116,7 +116,7 @@ class PathTestCase extends DrupalWebTest
     $this->drupalPost('node/' . $node1->nid . '/edit', array('path' => ''), t('Save'));
 
     // Confirm that the alias no longer works.
-    $this->drupalGet($edit['path']);
+    $this->drupalGet($edit['path_alias']);
     $this->assertNoText($node1->title, 'Alias was successfully deleted.');
   }
 
@@ -133,7 +133,7 @@ class PathTestCase extends DrupalWebTest
     // Check to make sure the node was created.
     $node = node_load(array('title' => $edit['title']));
 
-    $this->assertNotNull(($node === FALSE ? NULL : $node), 'Node found in database. %s');
+    $this->assertTrue($node, 'Node found in database.');
 
     return $node;
   }
