--- flag.install	2008/09/11 14:25:40	1.2.2.7
+++ flag.install	2008/09/12 13:31:32	1.2.2.11
@@ -1,5 +1,5 @@
 <?php
-// $Id: flag.install,v 1.2.2.6 2008/09/11 03:46:59 mooffie Exp $
+// $Id: flag.install,v 1.2.2.10 2008/09/12 13:20:55 mooffie Exp $
 
 /**
  * Implementation of hook_install().
@@ -251,11 +251,17 @@
  * Delete obsolete actions provided by beta3.
  *
  * Note: To ease maintenance, this code is compatible with both D5 and D6.
+ *
+ * Check out #305391 for a discussion about this code.
  */
 function flag_update_6000() {
   $ret = array();
   // This conditional ensures we have Actions 2.x, not Actions 1.x.
-  if (db_table_exists('actions_assignments') || db_table_exists('trigger_assignments')) {
+  //
+  // At the beginning we had only db_table_exists() checks here. However, it
+  // turned out that db_table_exists() fails when the $db_prefix string contains
+  // a dot. So module_exists() and function_exists() are added, as backup.
+  if (module_exists('trigger') || function_exists('_actions_get_hook_aids') || db_table_exists('actions_assignments') || db_table_exists('trigger_assignments')) {
 
     // Step 1: Find all actions we need to delete.
 
@@ -286,6 +292,10 @@
     if (function_exists('actions_delete')) {
       foreach ($aids as $aid) {
         actions_delete($aid);
+        $ret[] = array(
+          'success' => TRUE,
+          'query' => t('actions_delete("@aid") called.', array('@aid' => $aid)),
+        );
       }
     }
 
@@ -294,7 +304,7 @@
     foreach ($aids as $aid) {
       foreach (array('actions', 'actions_assignments', 'trigger_assignments') as $table) {
         if (db_table_exists($table)) {
-          $ret[]= _flag_update_sql("DELETE FROM {{$table}} WHERE aid = '%s'", $aid);
+          $ret[] = _flag_update_sql("DELETE FROM {{$table}} WHERE aid = '%s'", $aid);
         }
       }
     }
