summaryrefslogtreecommitdiff
path: root/modules/trigger
diff options
context:
space:
mode:
Diffstat (limited to 'modules/trigger')
-rw-r--r--modules/trigger/tests/trigger_test.module5
-rw-r--r--modules/trigger/trigger.admin.inc30
-rw-r--r--modules/trigger/trigger.install41
-rw-r--r--modules/trigger/trigger.module38
-rw-r--r--modules/trigger/trigger.test4
5 files changed, 94 insertions, 24 deletions
diff --git a/modules/trigger/tests/trigger_test.module b/modules/trigger/tests/trigger_test.module
index 0e3f3f877..72fe35284 100644
--- a/modules/trigger/tests/trigger_test.module
+++ b/modules/trigger/tests/trigger_test.module
@@ -57,7 +57,7 @@ function trigger_test_action_info() {
function trigger_test_trigger_info() {
// Register triggers that this module provides. The first is an additional
// node trigger and the second is our own, which should create a new tab
- // on the trigger assignment page.
+ // on the trigger assignment page. The last tests long trigger names.
return array(
'node' => array(
'node_triggertest' => array(
@@ -68,6 +68,9 @@ function trigger_test_trigger_info() {
'trigger_test_triggertest' => array(
'label' => t('Another test trigger is fired'),
),
+ 'trigger_test_we_sweat_it_out_in_the_streets_of_a_runaway_american_dream' => array(
+ 'label' => t('A test trigger with a name over 64 characters'),
+ ),
),
);
}
diff --git a/modules/trigger/trigger.admin.inc b/modules/trigger/trigger.admin.inc
index 7509eb35a..447d0dc07 100644
--- a/modules/trigger/trigger.admin.inc
+++ b/modules/trigger/trigger.admin.inc
@@ -6,13 +6,16 @@
*/
/**
- * Builds the form that allows users to assign actions to triggers.
+ * Builds a form that allows users to assign actions to triggers.
*
* @param $module_to_display
- * Which tab of triggers to display. E.g., 'node' for all
- * node-related triggers.
+ * Which tab of triggers to display. E.g., 'node' for all node-related
+ * triggers.
+ *
* @return
* HTML form.
+ *
+ * @see trigger_menu()
*/
function trigger_assign($module_to_display = NULL) {
// If no type is specified we default to node actions, since they
@@ -36,16 +39,18 @@ function trigger_assign($module_to_display = NULL) {
}
/**
- * Confirm removal of an assigned action.
+ * Form constructor for confirmation page for removal of an assigned action.
*
* @param $module
* The tab of triggers the user will be directed to after successful
* removal of the action, or if the confirmation form is cancelled.
* @param $hook
+ * The name of the trigger hook, e.g., 'node_insert'.
* @param $aid
* The action ID.
- * @ingroup forms
+ *
* @see trigger_unassign_submit()
+ * @ingroup forms
*/
function trigger_unassign($form, $form_state, $module, $hook = NULL, $aid = NULL) {
if (!($hook && $aid)) {
@@ -79,7 +84,7 @@ function trigger_unassign($form, $form_state, $module, $hook = NULL, $aid = NULL
}
/**
- * Submit callback for trigger_unassign() form.
+ * Form submission handler for trigger_unassign().
*/
function trigger_unassign_submit($form, &$form_state) {
if ($form_state['values']['confirm'] == 1) {
@@ -88,6 +93,7 @@ function trigger_unassign_submit($form, &$form_state) {
->condition('hook', $form_state['values']['hook'])
->condition('aid', $aid)
->execute();
+ drupal_static_reset('trigger_get_assigned_actions');
$actions = actions_get_all_actions();
watchdog('actions', 'Action %action has been unassigned.', array('%action' => $actions[$aid]['label']));
drupal_set_message(t('Action %action has been unassigned.', array('%action' => $actions[$aid]['label'])));
@@ -108,9 +114,9 @@ function trigger_unassign_submit($form, &$form_state) {
* @param $label
* A plain English description of what this trigger does.
*
- * @ingoup forms
* @see trigger_assign_form_validate()
* @see trigger_assign_form_submit()
+ * @ingroup forms
*/
function trigger_assign_form($form, $form_state, $module, $hook, $label) {
$form['module'] = array(
@@ -197,9 +203,11 @@ function trigger_assign_form($form, $form_state, $module, $hook, $label) {
}
/**
- * Validation function for trigger_assign_form().
+ * Form validation handler for trigger_assign_form().
*
* Makes sure that the user is not re-assigning an action to an event.
+ *
+ * @see trigger_assign_form_submit()
*/
function trigger_assign_form_validate($form, $form_state) {
$form_values = $form_state['values'];
@@ -216,7 +224,9 @@ function trigger_assign_form_validate($form, $form_state) {
}
/**
- * Submit function for trigger_assign_form().
+ * Form submission handler for trigger_assign_form().
+ *
+ * @see trigger_assign_form_validate()
*/
function trigger_assign_form_submit($form, &$form_state) {
if (!empty($form_state['values']['aid'])) {
@@ -271,6 +281,7 @@ function trigger_assign_form_submit($form, &$form_state) {
}
}
}
+ drupal_static_reset('trigger_get_assigned_actions');
}
/**
@@ -306,4 +317,3 @@ function theme_trigger_display($variables) {
}
return $output;
}
-
diff --git a/modules/trigger/trigger.install b/modules/trigger/trigger.install
index 9a172a2a0..20d5c3a3d 100644
--- a/modules/trigger/trigger.install
+++ b/modules/trigger/trigger.install
@@ -9,12 +9,14 @@
* Implements hook_schema().
*/
function trigger_schema() {
+ // The total index length (hook and aid) must be less than 333. Since the aid
+ // field is 255 characters, the hook field can have a maximum length of 78.
$schema['trigger_assignments'] = array(
'description' => 'Maps trigger to hook and operation assignments from trigger.module.',
'fields' => array(
'hook' => array(
'type' => 'varchar',
- 'length' => 32,
+ 'length' => 78,
'not null' => TRUE,
'default' => '',
'description' => 'Primary Key: The name of the internal Drupal hook; for example, node_insert.',
@@ -53,9 +55,15 @@ function trigger_install() {
}
/**
- * Adds operation names to the hook names and drops the "op" field.
+ * Alter the "hook" field and drop the "op field" of {trigger_assignments}.
+ *
+ * Increase the length of the "hook" field to 78 characters and adds operation
+ * names to the hook names, and drops the "op" field.
*/
function trigger_update_7000() {
+ db_drop_primary_key('trigger_assignments');
+ db_change_field('trigger_assignments', 'hook', 'hook', array('type' => 'varchar', 'length' => 78, 'not null' => TRUE, 'default' => '', 'description' => 'Primary Key: The name of the internal Drupal hook; for example, node_insert.'));
+
$result = db_query("SELECT hook, op, aid FROM {trigger_assignments} WHERE op <> ''");
foreach ($result as $record) {
@@ -67,4 +75,33 @@ function trigger_update_7000() {
->execute();
}
db_drop_field('trigger_assignments', 'op');
+
+ db_add_primary_key('trigger_assignments', array('hook', 'aid'));
+}
+
+/**
+ * Increase the length of the "hook" field to 78 characters.
+ *
+ * This is a separate function for those who ran an older version of
+ * trigger_update_7000() that did not do this.
+ */
+function trigger_update_7001() {
+ db_drop_primary_key('trigger_assignments');
+ db_change_field('trigger_assignments', 'hook', 'hook', array('type' => 'varchar', 'length' => 78, 'not null' => TRUE, 'default' => '', 'description' => 'Primary Key: The name of the internal Drupal hook; for example, node_insert.', ), array('primary key' => array('hook', 'aid')));
+}
+
+/**
+ * Renames nodeapi to node.
+ */
+function trigger_update_7002() {
+ $result = db_query("SELECT hook, aid FROM {trigger_assignments}");
+
+ foreach($result as $record) {
+ $new_hook = str_replace('nodeapi', 'node', $record->hook);
+ db_update('trigger_assignments')
+ ->fields(array('hook' => $new_hook))
+ ->condition('hook', $record->hook)
+ ->condition('aid', $record->aid)
+ ->execute();
+ }
}
diff --git a/modules/trigger/trigger.module b/modules/trigger/trigger.module
index 6c1f58ffa..82d117272 100644
--- a/modules/trigger/trigger.module
+++ b/modules/trigger/trigger.module
@@ -2,8 +2,7 @@
/**
* @file
- * Enables functions to be stored and executed at a later time when
- * triggered by other modules or by one of Drupal's core API hooks.
+ * Enables functions to be stored and executed at a later time.
*/
/**
@@ -27,7 +26,7 @@ function trigger_help($path, $arg) {
if ($path == 'admin/help#trigger') {
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
- $output .= '<p>' . t('The Trigger module provides the ability to cause <em>actions</em> to run when certain <em>triggers</em> take place on your site. Triggers are events, such as new content being added to your site or a user logging in, and actions are tasks, such as unpublishing content or e-mailing an administrator. For more information, see the online handbook entry for <a href="@trigger">Trigger module</a>.', array('@trigger' => 'http://drupal.org/handbook/modules/trigger/')) . '</p>';
+ $output .= '<p>' . t('The Trigger module provides the ability to cause <em>actions</em> to run when certain <em>triggers</em> take place on your site. Triggers are events, such as new content being added to your site or a user logging in, and actions are tasks, such as unpublishing content or e-mailing an administrator. For more information, see the online handbook entry for <a href="@trigger">Trigger module</a>.', array('@trigger' => 'http://drupal.org/documentation/modules/trigger/')) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Configuring triggers and actions') . '</dt>';
@@ -158,15 +157,20 @@ function trigger_trigger_info() {
*
* @param $hook
* The name of the hook being fired.
+ *
* @return
* An array whose keys are action IDs that the user has associated with
* this trigger, and whose values are arrays containing the action type and
* label.
*/
function trigger_get_assigned_actions($hook) {
- return db_query("SELECT ta.aid, a.type, a.label FROM {trigger_assignments} ta LEFT JOIN {actions} a ON ta.aid = a.aid WHERE ta.hook = :hook ORDER BY ta.weight", array(
- ':hook' => $hook,
- ))->fetchAllAssoc( 'aid', PDO::FETCH_ASSOC);
+ $actions = &drupal_static(__FUNCTION__, array());
+ if (!isset($actions[$hook])) {
+ $actions[$hook] = db_query("SELECT ta.aid, a.type, a.label FROM {trigger_assignments} ta LEFT JOIN {actions} a ON ta.aid = a.aid WHERE ta.hook = :hook ORDER BY ta.weight", array(
+ ':hook' => $hook,
+ ))->fetchAllAssoc('aid', PDO::FETCH_ASSOC);
+ }
+ return $actions[$hook];
}
/**
@@ -231,8 +235,8 @@ function _trigger_normalize_node_context($type, $node) {
*
* @param $node
* Node object.
- * @param $op
- * Operation to trigger.
+ * @param $hook
+ * Hook to trigger.
* @param $a3
* Additional argument to action function.
* @param $a4
@@ -384,8 +388,8 @@ function trigger_comment_view($comment) {
*
* @param $a1
* Comment object or array of form values.
- * @param $op
- * Operation to trigger.
+ * @param $hook
+ * Hook to trigger.
*/
function _trigger_comment($a1, $hook) {
// Keep objects for reuse so that changes actions make to objects can persist.
@@ -442,6 +446,7 @@ function trigger_cron() {
* The type of action that is about to be called.
* @param $account
* The account object that was passed via the user hook.
+ *
* @return
* The object expected by the action that is about to be called.
*/
@@ -518,6 +523,15 @@ function trigger_user_view($account) {
/**
* Calls action functions for user triggers.
+ *
+ * @param $hook
+ * The hook that called this function.
+ * @param $edit
+ * Edit variable passed in to the hook or empty array if not needed.
+ * @param $account
+ * Account variable passed in to the hook.
+ * @param $method
+ * Method variable passed in to the hook or NULL if not needed.
*/
function _trigger_user($hook, &$edit, $account, $category = NULL) {
// Keep objects for reuse so that changes actions make to objects can persist.
@@ -592,10 +606,14 @@ function trigger_actions_delete($aid) {
db_delete('trigger_assignments')
->condition('aid', $aid)
->execute();
+ drupal_static_reset('trigger_get_assigned_actions');
}
/**
* Retrieves and caches information from hook_trigger_info() implementations.
+ *
+ * @return
+ * Array of all triggers.
*/
function _trigger_get_all_info() {
$triggers = &drupal_static(__FUNCTION__);
diff --git a/modules/trigger/trigger.test b/modules/trigger/trigger.test
index 9a9a4ba28..138de6281 100644
--- a/modules/trigger/trigger.test
+++ b/modules/trigger/trigger.test
@@ -11,7 +11,7 @@
class TriggerWebTestCase extends DrupalWebTestCase {
/**
- * Configure an advanced action.
+ * Configures an advanced action.
*
* @param $action
* The name of the action callback. For example: 'user_block_user_action'
@@ -344,6 +344,7 @@ class TriggerActionTestCase extends TriggerWebTestCase {
$edit = array('aid' => drupal_hash_base64($aid));
$this->drupalPost('admin/structure/trigger/user', $edit, t('Assign'), array(), array(), $form_html_id);
+ drupal_static_reset('trigger_get_asssigned_actions');
}
@@ -372,6 +373,7 @@ class TriggerActionTestCase extends TriggerWebTestCase {
$edit = array('aid' => drupal_hash_base64($aid));
$this->drupalPost('admin/structure/trigger/user', $edit, t('Assign'), array(), array(), $form_html_id);
+ drupal_static_reset('trigger_get_assigned_actions');
}
/**