Commit a26efbeb authored by webchick's avatar webchick

#408434 by mr.baileys and andypost: Fix fatal error in actions.inc after DBTNG conversion.

parent 5b8d80b9
......@@ -47,7 +47,7 @@ function actions_do($action_ids, $object = NULL, $context = NULL, $a1 = NULL, $a
}
$actions = array();
$available_actions = actions_list();
$result = array();
$actions_result = array();
if (is_array($action_ids)) {
$conditions = array();
foreach ($action_ids as $action_id) {
......@@ -82,11 +82,11 @@ function actions_do($action_ids, $object = NULL, $context = NULL, $a1 = NULL, $a
if (is_numeric($action_id)) {
$function = $params['callback'];
$context = array_merge($context, $params);
$result[$action_id] = $function($object, $context, $a1, $a2);
$actions_result[$action_id] = $function($object, $context, $a1, $a2);
}
// Singleton action; $action_id is the function name.
else {
$result[$action_id] = $action_id($object, $context, $a1, $a2);
$actions_result[$action_id] = $action_id($object, $context, $a1, $a2);
}
}
}
......@@ -97,15 +97,15 @@ function actions_do($action_ids, $object = NULL, $context = NULL, $a1 = NULL, $a
$action = db_query("SELECT callback, parameters FROM {actions} WHERE aid = :aid", array(':aid' => $action_ids))->fetchObject();
$function = $action->callback;
$context = array_merge($context, unserialize($action->parameters));
$result[$action_ids] = $function($object, $context, $a1, $a2);
$actions_result[$action_ids] = $function($object, $context, $a1, $a2);
}
// Singleton action; $action_ids is the function name.
else {
$result[$action_ids] = $action_ids($object, $context, $a1, $a2);
$actions_result[$action_ids] = $action_ids($object, $context, $a1, $a2);
}
}
$stack--;
return $result;
return $actions_result;
}
/**
......
......@@ -20,6 +20,14 @@ function trigger_test_action_info() {
'cron' => array('run'),
),
),
'trigger_test_system_cron_conf_action' => array(
'type' => 'system',
'description' => t('Cron test configurable action'),
'configurable' => TRUE,
'hooks' => array(
'cron' => array('run'),
),
),
);
}
......@@ -30,3 +38,39 @@ function trigger_test_system_cron_action() {
// Indicate successful execution by setting a persistent variable.
variable_set('trigger_test_system_cron_action', TRUE);
}
/**
* Implement a configurable Drupal action.
*/
function trigger_test_system_cron_conf_action($object, $context) {
// Indicate successful execution by incrementing a persistent variable.
$value = variable_get('trigger_test_system_cron_conf_action', 0) + 1;
variable_set('trigger_test_system_cron_conf_action', $value);
}
/**
* Form for configurable test action.
*/
function trigger_test_system_cron_conf_action_form($context) {
if (!isset($context['subject'])) {
$context['subject'] = '';
}
$form['subject'] = array(
'#type' => 'textfield',
'#default_value' => $context['subject'],
);
return $form;
}
/**
* Form submission handler for configurable test action.
*/
function trigger_test_system_cron_conf_action_submit($form, $form_state) {
$form_values = $form_state['values'];
// Process the HTML form to store configuration. The keyed array that
// we return will be serialized to the database.
$params = array(
'subject' => $form_values['subject'],
);
return $params;
}
......@@ -127,25 +127,51 @@ class TriggerCronTestCase extends DrupalWebTestCase {
}
/**
* Assign an action to a trigger, then pull the trigger, and make sure the actions fire.
* Test assigning multiple actions to the cron trigger.
*
* This test ensures that both simple and multiple complex actions
* succeed properly. This is done in the cron trigger test because
* cron allows passing multiple actions in at once.
*/
function testActionsCron() {
$action = 'trigger_test_system_cron_action';
$hash = md5($action);
// Create administrative user.
// Create an administrative user.
$test_user = $this->drupalCreateUser(array('administer actions'));
$this->drupalLogin($test_user);
// Select our test action and assign it to a cron run trigger.
$edit = array('aid' => $hash);
// Assign a non-configurable action to the cron run trigger.
$edit = array('aid' => md5('trigger_test_system_cron_action'));
$this->drupalPost('admin/build/trigger/cron', $edit, t('Assign'));
// Assign a configurable action to the cron trigger.
$hash = md5('trigger_test_system_cron_conf_action');
$action_description = $this->randomName();
$edit = array(
'actions_description' => $action_description,
'subject' => $action_description,
);
$this->drupalPost('admin/settings/actions/configure/' . $hash, $edit, t('Save'));
$edit = array('aid' => md5('1'));
$this->drupalPost('admin/build/trigger/cron', $edit, t('Assign'));
// Add a second configurable action to the cron trigger.
$action_description = $this->randomName();
$edit = array(
'actions_description' => $action_description,
'subject' => $action_description,
);
$this->drupalPost('admin/settings/actions/configure/' . $hash, $edit, t('Save'));
$edit = array('aid' => md5('2'));
$this->drupalPost('admin/build/trigger/cron', $edit, t('Assign'));
// Force a cron run.
drupal_cron_run();
// Make sure the actions fire.
// Make sure the non-configurable action has fired.
$action_run = variable_get('trigger_test_system_cron_action', FALSE);
$this->assertTrue($action_run, t('Check that the cron run triggered the test action.'));
// Make sure that both configurable actions have fired.
$action_run = variable_get('trigger_test_system_cron_conf_action', 0) == 2;
$this->assertTrue($action_run, t('Check that the cron run triggered both complex 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