Index: taxonomy_manager.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/taxonomy_manager/Attic/taxonomy_manager.admin.inc,v
retrieving revision 1.1.2.17.2.25
diff -u -p -r1.1.2.17.2.25 taxonomy_manager.admin.inc
--- taxonomy_manager.admin.inc	5 Sep 2009 10:09:41 -0000	1.1.2.17.2.25
+++ taxonomy_manager.admin.inc	4 Oct 2009 10:46:23 -0000
@@ -572,6 +572,12 @@ function taxonomy_manager_merge_form($vo
   $options['collect_children'] = t('Collect all children of selected terms an add it to the merged term');
   $options['collect_relations'] = t('Collect all relations of selected terms an add it to the merged term');
   
+  // If path_redirect is installed, also give an option to allow merged terms
+  // to have their old URLs merged to the new one.
+  if (module_exists('path_redirect')) {
+    $options['merge_redirect'] = t('Use path_redirect to redirect all old URLs to the new term.'); 
+  }
+  
   if (count($options) > 0) {
     $form['merge']['options'] = array( 
       '#type' => 'checkboxes', 
@@ -2118,6 +2124,41 @@ function taxonomy_manager_merge($main_te
   //TODO: add hook, so that other modules can consider changes
   foreach ($merging_terms as $merge_term) {
     if ($merge_term != $main_term) {
+      // If path_redirect is installed and 'merge_redirect' option is set,
+      // create redirects for the old URL.
+      if (module_exists('path_redirect') && $options['merge_redirect']) {
+        // Redirect the old base URL.
+        $redirect = array(
+          'path' => 'taxonomy/term/' . $merge_term,
+          'redirect' => 'taxonomy/term/' . $main_term,
+        );
+        path_redirect_save($redirect);
+        // Redirect any optional URL aliases.
+        $aliases = db_query("SELECT dst FROM {url_alias} WHERE src='%s'", $redirect['path']);
+        while ($alias = db_fetch_object($aliases)) {
+          // Want to make sure we're inserting a new record.
+          unset($redirect['rid']);
+          // The old destination is the new source path.
+          $redirect['path'] = $alias->dst;
+          // Save the new redirect.
+          path_redirect_save($redirect);
+        }
+        // Cleanup any old path_redirect recordss
+        $aliases = db_query("SELECT rid, path FROM {path_redirect} WHERE redirect='%s'", $redirect['path']);
+        while ($alias = db_fetch_object($aliases)) {
+          // Make sure we're updating the correct record.
+          $redirect['rid'] = $alias->rid;
+          // The old path is the new source path.
+          $redirect['path'] = $alias->path;
+          // Save the new redirect.
+          path_redirect_save($redirect);
+        }
+        // Cleanup.
+        unset($alias);
+        unset($aliases);
+        unset($redirect);
+      }
+
       //update node-relations
       $sql = db_query("SELECT * FROM {term_node} WHERE tid = %d", $merge_term);
       while ($obj = db_fetch_object($sql)) {
