Commit 1cb11b5b authored by Dries's avatar Dries
Browse files

- Patch #394586 by andypost, bubbasan, Berdir: convert to the new database abstraction layer.

parent 5199f1bb
......@@ -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;
}
......@@ -88,7 +88,9 @@ function hook_action_info() {
* The action ID.
*/
function hook_actions_delete($aid) {
db_query("DELETE FROM {actions_assignments} WHERE aid = '%s'", $aid);
db_delete('actions_assignments')
->condition('aid', $aid)
->execute();
}
/**
......
......@@ -92,7 +92,10 @@ function trigger_menu() {
if (in_array($module, array('node', 'comment', 'user', 'system', 'taxonomy'))) {
continue;
}
$info = db_result(db_query("SELECT info FROM {system} WHERE name = '%s'", $module));
$info = db_select('system')
->condition('name', $module)
->execute()
->fetchField();
$info = unserialize($info);
$nice_name = $info['name'];
$items["admin/build/trigger/$module"] = array(
......@@ -135,8 +138,11 @@ function trigger_access_check($module) {
*/
function _trigger_get_hook_aids($hook, $op = '') {
$aids = array();
$result = db_query("SELECT aa.aid, a.type FROM {trigger_assignments} aa LEFT JOIN {actions} a ON aa.aid = a.aid WHERE aa.hook = '%s' AND aa.op = '%s' ORDER BY weight", $hook, $op);
while ($action = db_fetch_object($result)) {
$result = db_query("SELECT aa.aid, a.type FROM {trigger_assignments} aa LEFT JOIN {actions} a ON aa.aid = a.aid WHERE aa.hook = :hook AND aa.op = :op ORDER BY weight", array(
':hook' => $hook,
':op' => $op,
));
foreach ($result as $action) {
$aids[$action->aid]['type'] = $action->type;
}
return $aids;
......@@ -534,5 +540,7 @@ function trigger_options($type = 'all') {
* Remove all trigger entries for the given action, when deleted.
*/
function trigger_actions_delete($aid) {
db_query("DELETE FROM {trigger_assignments} WHERE aid = '%s'", $aid);
db_delete('trigger_assignments')
->condition('aid', $aid)
->execute();
}
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