Index: comment_alter_taxonomy.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/comment_alter_taxonomy/comment_alter_taxonomy.module,v
retrieving revision 1.17
diff -u -p -r1.17 comment_alter_taxonomy.module
--- comment_alter_taxonomy.module	24 Mar 2009 00:39:32 -0000	1.17
+++ comment_alter_taxonomy.module	13 Nov 2010 16:34:37 -0000
@@ -773,3 +773,23 @@ function _comment_alter_taxonomy_callbac
   include_once drupal_get_path('module', 'comment_alter_taxonomy') .'/'. $file;
   return call_user_func_array($function, $args);
 }
+
+/**
+ * Implements hook_cron().
+ */
+function comment_alter_taxonomy_cron() {
+  // Find all orphan (no longer assigned) terms in configured vocabularies to
+  // delete them.
+  if ($vids = array_keys(variable_get('comment_alter_taxonomy_vocabularies', array()))) {
+    $placeholders = db_placeholders($vids);
+    $result = db_query("SELECT t.tid
+      FROM {term_data} t
+      LEFT JOIN {term_node} tn ON tn.tid = t.tid
+      WHERE t.vid IN ($placeholders) AND tn.tid IS NULL
+    ", $vids);
+
+    while ($tid = db_result($result)) {
+      taxonomy_del_term($tid);
+    }
+  }
+}
