Commit 16c5713b authored by Dries's avatar Dries
Browse files

- Patch #241013 by Pedro Lozano, drewish, andypost, mr.baileys: actions only...

- Patch #241013 by Pedro Lozano, drewish, andypost, mr.baileys: actions only trigger one action per node page load.
parent 1c6df633
......@@ -2097,6 +2097,10 @@ function system_get_files_database(&$files, $type) {
*/
function system_update_files_database(&$files, $type) {
$result = db_query("SELECT * FROM {system} WHERE type = :type", array(':type' => $type));
// Remember if any module or theme is moved to a new filename so we can
// clear the system_list cache (in particular, the 'filepaths' subarray).
$filename_changed = FALSE;
// Add all files that need to be deleted to a DatabaseCondition.
$delete = db_or();
......@@ -2127,6 +2131,10 @@ function system_update_files_database(&$files, $type) {
->fields($updated_fields)
->condition('filename', $old_filename)
->execute();
if (isset($updated_fields['filename'])) {
$filename_changed = TRUE;
}
}
// Indicate that the file exists already.
......@@ -2135,6 +2143,7 @@ function system_update_files_database(&$files, $type) {
else {
// File is not found in file system, so delete record from the system table.
$delete->condition('filename', $file->filename);
$filename_changed = TRUE;
}
}
......@@ -2165,6 +2174,13 @@ function system_update_files_database(&$files, $type) {
}
}
$query->execute();
// If any module or theme was moved to a new location, we need to reset the
// system_list cache or we will continue to load the old copy, look for DB
// schema updates in the wrong place, etc.
if ($filename_changed) {
system_list_reset();
}
}
/**
......
......@@ -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);
}
......@@ -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]);
}
/**
......
......@@ -45,7 +45,7 @@ class TriggerContentTestCase extends TriggerWebTestCase {
}
function setUp() {
parent::setUp('trigger');
parent::setUp('trigger', 'trigger_test');
}
/**
......@@ -99,6 +99,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.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment