? patches
Index: pathauto.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.inc,v
retrieving revision 1.77
diff -u -p -r1.77 pathauto.inc
--- pathauto.inc	5 Jul 2010 14:29:51 -0000	1.77
+++ pathauto.inc	22 Jul 2010 01:11:53 -0000
@@ -94,26 +94,28 @@ function _pathauto_alias_exists($alias, 
  *
  * @param $source
  *   A string that is the internal path.
+ * @param $language
+ *   A string containing the language code to check against.
  * @return
  *   An array with the keys "pid" and "old_alias" containing
  *   the "pid" and old "alias", respectively, of the old alias.
  */
-function _pathauto_existing_alias_data($source) {
+function _pathauto_existing_alias_data($source, $language = LANGUAGE_NONE) {
   $output = array(
     'pid' => '',
     'old_alias' => ''
   );
-  $result = db_query("SELECT pid, alias FROM {url_alias} WHERE source = :source", array(':source' => $source));
-  if ($data = $result->fetchObject()) {
+  $existing = db_query_range("SELECT pid, alias FROM {url_alias} WHERE source = :source AND language IN(:language, :language-none) ORDER BY language DESC, pid DESC", 0, 1, array(':source' => $source, ':language' => $language, ':language-none' => LANGUAGE_NONE))->fetch();
+  if ($existing) {
     // The item is already aliased, check what to do...
     switch (variable_get('pathauto_update_action', PATHAUTO_UPDATE_ACTION_DELETE)) {
       // Replace old alias - remember the pid to update
       case PATHAUTO_UPDATE_ACTION_DELETE:
       case PATHAUTO_UPDATE_ACTION_REDIRECT:
-        $output['pid'] = $data->pid;
+        $output['pid'] = $existing->pid;
       // Add new alias in addition to old one
       case PATHAUTO_UPDATE_ACTION_LEAVE:
-        $output['old_alias'] = $data->alias;
+        $output['old_alias'] = $existing->alias;
         break;
       // Do nothing
       case PATHAUTO_UPDATE_ACTION_NO_NEW:
@@ -319,7 +321,7 @@ function pathauto_create_alias($module, 
     $term_path = 'taxonomy/term/' . $data['term']->tid;
     if ($term_path != $source) {
       // Quietly alias 'taxonomy/term/[tid]' with proper path for term.
-      $update_data = _pathauto_existing_alias_data($source);
+      $update_data = _pathauto_existing_alias_data($source, $language);
       _pathauto_set_alias($source, $term_path, $update_data['pid'], FALSE, $update_data['old_alias'], $language);
       // Set $source as proper path.
       $source = $term_path;
@@ -334,7 +336,7 @@ function pathauto_create_alias($module, 
       // Do nothing
       return '';
     }
-    $update_data = _pathauto_existing_alias_data($source);
+    $update_data = _pathauto_existing_alias_data($source, $language);
     $pid = $update_data['pid'];
     $old_alias = $update_data['old_alias'];
   }
@@ -390,11 +392,11 @@ function pathauto_create_alias($module, 
     // For forums and taxonomies, the source doesn't always form the base of the rss feed (ie. image galleries)
     if (($module == 'taxonomy' || $module == 'forum') && isset($data['term'])) {
       $tid = $data['term']->tid;
-      $update_data = _pathauto_existing_alias_data("taxonomy/term/$tid/$feedappend");
+      $update_data = _pathauto_existing_alias_data("taxonomy/term/$tid/$feedappend", $language);
       _pathauto_set_alias("taxonomy/term/$tid/$feedappend", "$alias/feed", $update_data['pid'], $verbose, $update_data['old_alias'], $language);
     }
     else {
-      $update_data = _pathauto_existing_alias_data("$source/$feedappend");
+      $update_data = _pathauto_existing_alias_data("$source/$feedappend", $language);
       _pathauto_set_alias("$source/$feedappend", "$alias/feed", $update_data['pid'], $verbose, $update_data['old_alias'], $language);
     }
   }
