summaryrefslogtreecommitdiff
path: root/modules/trigger/trigger.admin.inc
diff options
context:
space:
mode:
Diffstat (limited to 'modules/trigger/trigger.admin.inc')
-rw-r--r--modules/trigger/trigger.admin.inc66
1 files changed, 52 insertions, 14 deletions
diff --git a/modules/trigger/trigger.admin.inc b/modules/trigger/trigger.admin.inc
index 02f9cff9d..129270a69 100644
--- a/modules/trigger/trigger.admin.inc
+++ b/modules/trigger/trigger.admin.inc
@@ -79,7 +79,11 @@ function trigger_unassign_submit($form, &$form_state) {
$form_values = $form_state['values'];
if ($form_values['confirm'] == 1) {
$aid = actions_function_lookup($form_values['aid']);
- db_query("DELETE FROM {trigger_assignments} WHERE hook = '%s' AND op = '%s' AND aid = '%s'", $form_values['hook'], $form_values['operation'], $aid);
+ db_delete('trigger_assignments')
+ ->condition('hook', $form_values['hook'])
+ ->condition('op', $form_values['operation'])
+ ->condition('aid', $aid)
+ ->execute();
$actions = actions_get_all_actions();
watchdog('actions', 'Action %action has been unassigned.', array('%action' => check_plain($actions[$aid]['description'])));
drupal_set_message(t('Action %action has been unassigned.', array('%action' => $actions[$aid]['description'])));
@@ -185,7 +189,12 @@ function trigger_assign_form_validate($form, $form_state) {
$form_values = $form_state['values'];
if (!empty($form_values['aid'])) {
$aid = actions_function_lookup($form_values['aid']);
- if (db_result(db_query("SELECT aid FROM {trigger_assignments} WHERE hook = '%s' AND op = '%s' AND aid = '%s'", $form_values['hook'], $form_values['operation'], $aid))) {
+ $aid_exists = db_query("SELECT aid FROM {trigger_assignments} WHERE hook = :hook AND op = :op AND aid = :aid", array(
+ ':hook' => $form_values['hook'],
+ ':op' => $form_values['operation'],
+ ':aid' => $aid,
+ ))->fetchField();
+ if ($aid_exists) {
form_set_error($form_values['operation'], t('The action you chose is already assigned to that trigger.'));
}
}
@@ -199,18 +208,45 @@ function trigger_assign_form_submit($form, $form_state) {
if (!empty($form_values['aid'])) {
$aid = actions_function_lookup($form_values['aid']);
- $weight = db_result(db_query("SELECT MAX(weight) FROM {trigger_assignments} WHERE hook = '%s' AND op = '%s'", $form_values['hook'], $form_values['operation']));
- db_query("INSERT INTO {trigger_assignments} values ('%s', '%s', '%s', %d)", $form_values['hook'], $form_values['operation'], $aid, $weight + 1);
+ $weight = db_query("SELECT MAX(weight) FROM {trigger_assignments} WHERE hook = :hook AND op = :op", array(
+ ':hook' => $form_values['hook'],
+ ':op' => $form_values['operation'],
+ ))->fetchField();
+
+ db_insert('trigger_assignments')
+ ->fields(array(
+ 'hook' => $form_values['hook'],
+ 'op' => $form_values['operation'],
+ 'aid' => $aid,
+ 'weight' => $weight + 1,
+ ))
+ ->execute();
// If this action changes a node property, we need to save the node
// so the change will persist.
$actions = actions_list();
if (isset($actions[$aid]['behavior']) && in_array('changes_node_property', $actions[$aid]['behavior']) && ($form_values['operation'] != 'presave')) {
// Delete previous node_save_action if it exists, and re-add a new one at a higher weight.
- $save_post_action_assigned = db_result(db_query("SELECT aid FROM {trigger_assignments} WHERE hook = '%s' AND op = '%s' AND aid = 'node_save_action'", $form_values['hook'], $form_values['operation']));
+ $save_post_action_assigned = db_query("SELECT aid FROM {trigger_assignments} WHERE hook = :hook AND op = :op AND aid = :aid", array(
+ ':hook' => $form_values['hook'],
+ ':op' => $form_values['operation'],
+ ':aid' => 'node_save_action',
+ ))->fetchField();
+
if ($save_post_action_assigned) {
- db_query("DELETE FROM {trigger_assignments} WHERE hook = '%s' AND op = '%s' AND aid = 'node_save_action'", $form_values['hook'], $form_values['operation']);
+ db_delete('trigger_assignments')
+ ->condition('hook', $form_values['hook'])
+ ->condition('op', $form_values['operation'])
+ ->condition('aid', 'node_save_action')
+ ->execute();
}
- db_query("INSERT INTO {trigger_assignments} VALUES ('%s', '%s', '%s', %d)", $form_values['hook'], $form_values['operation'], 'node_save_action', $weight + 2);
+ db_insert('trigger_assignments')
+ ->fields(array(
+ 'hook' => $form_values['hook'],
+ 'op' => $form_values['operation'],
+ 'aid' => 'node_save_action',
+ 'weight' => $weight + 2,
+ ))
+ ->execute();
if (!$save_post_action_assigned) {
drupal_set_message(t('You have added an action that changes a the property of a post. A Save post action has been added so that the property change will be saved.'));
}
@@ -268,15 +304,17 @@ function theme_trigger_display($element) {
* An array of action descriptions keyed by action IDs.
*/
function _trigger_get_hook_actions($hook, $op, $type = NULL) {
- $actions = array();
if ($type) {
- $result = db_query("SELECT h.aid, a.description FROM {trigger_assignments} h LEFT JOIN {actions} a on a.aid = h.aid WHERE a.type = '%s' AND h.hook = '%s' AND h.op = '%s' ORDER BY h.weight", $type, $hook, $op);
+ return db_query("SELECT h.aid, a.description FROM {trigger_assignments} h LEFT JOIN {actions} a on a.aid = h.aid WHERE a.type = :type AND h.hook = :hook AND h.op = :op ORDER BY h.weight", array(
+ ':type' => $type,
+ ':hook' => $hook,
+ ':op' => $op,
+ ))->fetchAllKeyed();
}
else {
- $result = db_query("SELECT h.aid, a.description FROM {trigger_assignments} h LEFT JOIN {actions} a on a.aid = h.aid WHERE h.hook = '%s' AND h.op = '%s' ORDER BY h.weight", $hook, $op);
- }
- while ($action = db_fetch_object($result)) {
- $actions[$action->aid] = $action->description;
+ return db_query("SELECT h.aid, a.description FROM {trigger_assignments} h LEFT JOIN {actions} a on a.aid = h.aid WHERE h.hook = :hook AND h.op = :op ORDER BY h.weight", array(
+ ':hook' => $hook,
+ ':op' => $op,
+ ))->fetchAllKeyed();
}
- return $actions;
}