From 37f518612102a1f91ea6179f4e53ce5db85b7c69 Mon Sep 17 00:00:00 2001 From: webchick Date: Mon, 26 Mar 2012 22:40:00 -0700 Subject: Issue #960056 by catch, mikeytown2, pmitchell, cedarm: Fixed trigger_get_assigned_actions() has no static cache. --- modules/trigger/trigger.admin.inc | 2 ++ modules/trigger/trigger.module | 11 ++++++++--- modules/trigger/trigger.test | 2 ++ 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'modules/trigger') diff --git a/modules/trigger/trigger.admin.inc b/modules/trigger/trigger.admin.inc index c91fd12c4..447d0dc07 100644 --- a/modules/trigger/trigger.admin.inc +++ b/modules/trigger/trigger.admin.inc @@ -93,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']))); @@ -280,6 +281,7 @@ function trigger_assign_form_submit($form, &$form_state) { } } } + drupal_static_reset('trigger_get_assigned_actions'); } /** diff --git a/modules/trigger/trigger.module b/modules/trigger/trigger.module index 3fa25e800..82d117272 100644 --- a/modules/trigger/trigger.module +++ b/modules/trigger/trigger.module @@ -164,9 +164,13 @@ function trigger_trigger_info() { * 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]; } /** @@ -602,6 +606,7 @@ function trigger_actions_delete($aid) { db_delete('trigger_assignments') ->condition('aid', $aid) ->execute(); + drupal_static_reset('trigger_get_assigned_actions'); } /** diff --git a/modules/trigger/trigger.test b/modules/trigger/trigger.test index 4a3016a7a..138de6281 100644 --- a/modules/trigger/trigger.test +++ b/modules/trigger/trigger.test @@ -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'); } /** -- cgit v1.2.3