summaryrefslogtreecommitdiff
path: root/modules/trigger
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-03-26 20:44:10 +0000
committerDries Buytaert <dries@buytaert.net>2010-03-26 20:44:10 +0000
commit16c5713bc03855361349dc913e9d3e3bf23298c3 (patch)
tree6afbea38989713785dadcf14385c6eea38798b44 /modules/trigger
parent1c6df63309bbb6327100dba50239bd9192e06d7f (diff)
downloadbrdo-16c5713bc03855361349dc913e9d3e3bf23298c3.tar.gz
brdo-16c5713bc03855361349dc913e9d3e3bf23298c3.tar.bz2
- Patch #241013 by Pedro Lozano, drewish, andypost, mr.baileys: actions only trigger one action per node page load.
Diffstat (limited to 'modules/trigger')
-rw-r--r--modules/trigger/tests/trigger_test.module2
-rw-r--r--modules/trigger/trigger.module12
-rw-r--r--modules/trigger/trigger.test30
3 files changed, 38 insertions, 6 deletions
diff --git a/modules/trigger/tests/trigger_test.module b/modules/trigger/tests/trigger_test.module
index 5f0ab6878..9f0eeadd3 100644
--- a/modules/trigger/tests/trigger_test.module
+++ b/modules/trigger/tests/trigger_test.module
@@ -131,5 +131,5 @@ function trigger_test_generic_action($context) {
*/
function trigger_test_generic_any_action($context) {
// Indicate successful execution by setting a persistent variable.
- variable_set('trigger_test_generic_any_action', TRUE);
+ variable_set('trigger_test_generic_any_action', variable_get('trigger_test_generic_any_action', 0) + 1);
}
diff --git a/modules/trigger/trigger.module b/modules/trigger/trigger.module
index db017a24a..ebbc538b5 100644
--- a/modules/trigger/trigger.module
+++ b/modules/trigger/trigger.module
@@ -260,15 +260,17 @@ function _trigger_node($node, $hook, $a3 = NULL, $a4 = NULL) {
static $objects;
// Prevent recursion by tracking which operations have already been called.
static $recursion;
- if (isset($recursion[$hook])) {
- return;
- }
- $recursion[$hook] = TRUE;
$aids = trigger_get_assigned_actions($hook);
if (!$aids) {
return;
}
+
+ if (isset($recursion[$hook])) {
+ return;
+ }
+ $recursion[$hook] = TRUE;
+
$context = array(
'group' => 'node',
'hook' => $hook,
@@ -291,6 +293,8 @@ function _trigger_node($node, $hook, $a3 = NULL, $a4 = NULL) {
actions_do($aid, $node, $context, $a3, $a4);
}
}
+
+ unset($recursion[$hook]);
}
/**
diff --git a/modules/trigger/trigger.test b/modules/trigger/trigger.test
index 2df6fe01d..ca56ad85f 100644
--- a/modules/trigger/trigger.test
+++ b/modules/trigger/trigger.test
@@ -45,7 +45,7 @@ class TriggerContentTestCase extends TriggerWebTestCase {
}
function setUp() {
- parent::setUp('trigger');
+ parent::setUp('trigger', 'trigger_test');
}
/**
@@ -100,6 +100,34 @@ class TriggerContentTestCase extends TriggerWebTestCase {
}
/**
+ * Test that node actions are fired for each node individually if acting on
+ * multiple nodes.
+ */
+ function testActionContentMultiple() {
+ // Assign an action to the node save/update trigger.
+ $test_user = $this->drupalCreateUser(array('administer actions', 'administer nodes', 'create page content', 'access administration pages', 'access content overview'));
+ $this->drupalLogin($test_user);
+
+ for ($index = 0; $index < 3; $index++) {
+ $edit = array('title' => $this->randomName());
+ $this->drupalPost('node/add/page', $edit, t('Save'));
+ }
+
+ $action_id = 'trigger_test_generic_any_action';
+ $hash = md5($action_id);
+ $edit = array('aid' => $hash);
+ $this->drupalPost('admin/structure/trigger/node', $edit, t('Assign'));
+
+ $edit = array(
+ 'operation' => 'unpublish',
+ 'nodes[1]' => TRUE,
+ 'nodes[2]' => TRUE,
+ );
+ $this->drupalPost('admin/content', $edit, t('Update'));
+ $this->assertTrue(variable_get('trigger_test_generic_any_action', 0) == 2, 'Action was triggered 2 times.');
+ }
+
+ /**
* Helper function for testActionsContent(): returns some info about each of the content actions.
*
* @param $action