diff options
author | Dries Buytaert <dries@buytaert.net> | 2007-09-26 18:19:22 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2007-09-26 18:19:22 +0000 |
commit | fbde117dd6dd4a8830c1b17b6d10c338cd39e3bd (patch) | |
tree | c5e3b2a2eb6dfa117956b5f648881aa151de36b5 | |
parent | 0351f4ca5dbbacab18168113c6bb46f3bf8b5382 (diff) | |
download | brdo-fbde117dd6dd4a8830c1b17b6d10c338cd39e3bd.tar.gz brdo-fbde117dd6dd4a8830c1b17b6d10c338cd39e3bd.tar.bz2 |
- Patch #178650 by pwoladin: fixed db problem and added extra validation.
-rw-r--r-- | modules/trigger/trigger.module | 24 | ||||
-rw-r--r-- | modules/trigger/trigger.schema | 3 |
2 files changed, 24 insertions, 3 deletions
diff --git a/modules/trigger/trigger.module b/modules/trigger/trigger.module index 5cda17c01..dfb2b89cc 100644 --- a/modules/trigger/trigger.module +++ b/modules/trigger/trigger.module @@ -187,6 +187,10 @@ function _trigger_get_hook_aids($hook, $op = '') { * @param $description * A plain English description of what this hook operation does. * @return + * + * @ingoup forms + * @see trigger_assign_form_validate() + * @see trigger_assign_form_submit() */ function trigger_assign_form($form_state, $hook, $op, $description) { $form['hook'] = array( @@ -197,7 +201,8 @@ function trigger_assign_form($form_state, $hook, $op, $description) { '#type' => 'hidden', '#value' => $op, ); - // All of these forms use the same #submit function. + // All of these forms use the same validate and submit functions. + $form['#validate'][] = 'trigger_assign_form_validate'; $form['#submit'][] = 'trigger_assign_form_submit'; $options = array(); @@ -253,7 +258,24 @@ function trigger_assign_form($form_state, $hook, $op, $description) { } return $form; } +/** + * Validation function for trigger_assign_form(). + * + * Makes sure that the user is not re-assigning an action to an event. + */ +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))) { + form_set_error($form_values['operation'], t('The action you choose is already assigned to that trigger.')); + } + } +} +/** + * Submit function for trigger_assign_form(). + */ function trigger_assign_form_submit($form, $form_state) { $form_values = $form_state['values']; diff --git a/modules/trigger/trigger.schema b/modules/trigger/trigger.schema index d21069c1c..1b06b97d3 100644 --- a/modules/trigger/trigger.schema +++ b/modules/trigger/trigger.schema @@ -9,8 +9,7 @@ function trigger_schema() { 'aid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), ), - 'index keys' => array( - 'hook_op' => array('hook', 'op')) + 'primary key' => array('hook', 'op', 'aid'), ); return $schema; } |