? drupaldown
? modules/syndication
Index: includes/actions.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/actions.inc,v
retrieving revision 1.21
diff -u -p -r1.21 actions.inc
--- includes/actions.inc	10 Oct 2008 08:49:51 -0000	1.21
+++ includes/actions.inc	19 Oct 2008 03:19:11 -0000
@@ -251,30 +251,28 @@ function actions_synchronize($actions_in
   if (!$actions_in_code) {
     $actions_in_code = actions_list(TRUE);
   }
-  $actions_in_db = db_query("SELECT aid, callback, description FROM {actions} WHERE parameters = ''")->fetchAllAssoc('callback', PDO::FETCH_ASSOC);
+  $actions_in_db = db_query("SELECT aid, callback, description FROM {actions}")->fetchAllAssoc('callback', PDO::FETCH_ASSOC);
 
   // Go through all the actions provided by modules.
   foreach ($actions_in_code as $callback => $array) {
-    // Ignore configurable actions since their instances get put in
-    // when the user adds the action.
-    if (!$array['configurable']) {
-      // If we already have an action ID for this action, no need to assign aid.
-      if (array_key_exists($callback, $actions_in_db)) {
-        unset($actions_in_db[$callback]);
-      }
-      else {
-        // This is a new singleton that we don't have an aid for; assign one.
-        db_insert('actions')
-          ->fields(array(
-            'aid' => $callback,
-            'type' => $array['type'],
-            'callback' => $callback,
-            'parameters' => '',
-            'description' => $array['description'],
-            ))
-          ->execute();
-        watchdog('actions', "Action '%action' added.", array('%action' => filter_xss_admin($array['description'])));
-      }
+    // If we already have an action ID for this action, no need to assign aid.
+    if (array_key_exists($callback, $actions_in_db)) {
+      unset($actions_in_db[$callback]);
+    }
+    elseif (!$array['configurable']) {
+      // Ignore configurable actions since their instances get put in
+      // when the user adds the action.
+      // This is a new singleton that we don't have an aid for; assign one.
+      db_insert('actions')
+        ->fields(array(
+          'aid' => $callback,
+          'type' => $array['type'],
+          'callback' => $callback,
+          'parameters' => '',
+          'description' => $array['description'],
+          ))
+        ->execute();
+      watchdog('actions', "Action '%action' added.", array('%action' => filter_xss_admin($array['description'])));
     }
   }
 
@@ -283,11 +281,11 @@ function actions_synchronize($actions_in
     $orphaned = array_keys($actions_in_db);
 
     if ($delete_orphans) {
-      $results = db_select('actions')
-        ->addField('actions', 'aid')
-        ->addField('actions', 'description')
-        ->condition('callback', $orphaned, 'IN')
-        ->execute();
+      $query = db_select('actions');
+      $query->addField('actions', 'aid', 'aid');
+      $query->addField('actions', 'description', 'description');
+      $query->condition('callback', $orphaned, 'IN');
+      $results = $query->execute();
       foreach ($results as $action) {
         actions_delete($action->aid);
         watchdog('actions', "Removed orphaned action '%action' from database.", array('%action' => filter_xss_admin($action->description)));
Index: modules/simpletest/tests/actions.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/actions.test,v
retrieving revision 1.1
diff -u -p -r1.1 actions.test
--- modules/simpletest/tests/actions.test	14 Aug 2008 09:18:28 -0000	1.1
+++ modules/simpletest/tests/actions.test	19 Oct 2008 03:20:20 -0000
@@ -63,4 +63,41 @@ class ActionsConfigurationTestCase exten
     $exists = db_result(db_query("SELECT aid FROM {actions} WHERE callback = 'drupal_goto_action'"));
     $this->assertFalse($exists, t('Make sure the action is gone from the database after being deleted.'));
   }
+
+  /**
+   * Test removal of orphaned actions.
+   */
+  function testActionOrphaned() {
+    // Insert two dummy orphaned actions.
+    db_insert('actions')
+      ->fields(array(
+        'aid' => 'system_orphaned_action',
+        'type' => 'system',
+        'callback' => 'system_orphaned_action',
+        'parameters' => '',
+      ))
+      ->execute();
+    db_insert('actions')
+      ->fields(array(
+        'type' => 'system',
+        'callback' => 'system_orphaned_action',
+        'parameters' => serialize(array('key' => 'value')),
+      ))
+      ->execute();
+
+    // Create a user with permission to view the actions administration pages.
+    $user = $this->drupalCreateUser(array('administer actions'));
+    $this->drupalLogin($user);
+    
+    // Visit actions page and check that actions are in the database.
+    // TODO: Assert watchdog entry found?
+    $this->drupalGet('admin/settings/actions');
+    $count = db_query("SELECT COUNT(aid) FROM {actions} WHERE callback = :callback", array(':callback' => 'system_orphaned_action'))->fetchField();
+    $this->assertEqual($count, 2, t("Orphaned actions found."));
+
+    // Remove orphaned actions and check that they are removed from the database.
+    $this->drupalGet('admin/settings/actions/orphan');
+    $count = db_query("SELECT COUNT(aid) FROM {actions} WHERE callback = :callback", array(':callback' => 'system_orphaned_action'))->fetchField();
+    $this->assertEqual($count, 0, t("Orphaned actions removed."));
+  }
 }
