uppdated modules
This commit is contained in:
@@ -1124,7 +1124,8 @@ abstract class RulesPlugin extends RulesExtendable {
|
||||
elseif ($this->plugin == 'reaction rule') {
|
||||
// Clear event sets cached for evaluation.
|
||||
cache_clear_all('event_', 'cache_rules', TRUE);
|
||||
variable_del('rules_event_whitelist');
|
||||
// Clear event whitelist for rebuild.
|
||||
cache_clear_all('rules_event_whitelist', 'cache_rules', TRUE);
|
||||
}
|
||||
drupal_static_reset('rules_get_cache');
|
||||
drupal_static_reset('rules_config_update_dirty_flag');
|
||||
|
||||
@@ -809,7 +809,7 @@ class RulesEventSet extends RulesRuleSet {
|
||||
}
|
||||
// Cache a whitelist of configured events so we can use it to speed up later
|
||||
// calls. See rules_invoke_event().
|
||||
variable_set('rules_event_whitelist', array_flip(array_keys($sets)));
|
||||
rules_set_cache('rules_event_whitelist', array_flip(array_keys($sets)));
|
||||
}
|
||||
|
||||
protected function stateVariables($element = NULL) {
|
||||
|
||||
@@ -22,9 +22,9 @@ files[] = ui/ui.plugins.inc
|
||||
dependencies[] = entity_token
|
||||
dependencies[] = entity
|
||||
|
||||
; Information added by Drupal.org packaging script on 2015-01-08
|
||||
version = "7.x-2.8"
|
||||
; Information added by Drupal.org packaging script on 2015-03-16
|
||||
version = "7.x-2.9"
|
||||
core = "7.x"
|
||||
project = "rules"
|
||||
datestamp = "1420734780"
|
||||
datestamp = "1426527210"
|
||||
|
||||
|
||||
@@ -508,3 +508,21 @@ function rules_update_7213() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch out the rules_event_whitelist variable for a cache equivalent.
|
||||
*/
|
||||
function rules_update_7214() {
|
||||
// Set new event_whitelist cache cid.
|
||||
rules_set_cache('rules_event_whitelist', variable_get('rules_event_whitelist', array()));
|
||||
// Delete old conf variable.
|
||||
variable_del('rules_event_whitelist');
|
||||
// Avoid any missing class errors.
|
||||
registry_rebuild();
|
||||
// Clear and rebuild Rules caches.
|
||||
// See: rules_admin_settings_cache_rebuild_submit.
|
||||
rules_clear_cache();
|
||||
rules_get_cache();
|
||||
_rules_rebuild_component_cache();
|
||||
RulesEventSet::rebuildEventCache();
|
||||
}
|
||||
|
||||
@@ -8,10 +8,44 @@
|
||||
// hook_init().
|
||||
require_once dirname(__FILE__) . '/modules/events.inc';
|
||||
|
||||
/**
|
||||
* Implements hook_module_implements_alter().
|
||||
*/
|
||||
function rules_module_implements_alter(&$implementations, $hook) {
|
||||
// Ensures the invocation of hook_menu_get_item_alter() triggers
|
||||
// rules_menu_get_item_alter() first so the rules invocation is ready for all
|
||||
// sub-sequent hook implementations.
|
||||
if ($hook == 'menu_get_item_alter' && array_key_exists('rules', $implementations)) {
|
||||
$group = $implementations['rules'];
|
||||
unset($implementations['rules']);
|
||||
$implementations = array_merge(array('rules' => $group), $implementations);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu_get_item_alter().
|
||||
*/
|
||||
function rules_menu_get_item_alter() {
|
||||
// Make sure that event invocation is enabled before menu items are loaded.
|
||||
// But make sure later calls to menu_get_item() won't automatically re-enabled
|
||||
// the rules invocation.
|
||||
// Example: modules that implement hook_entity_ENTITY_TYPE_load() might want
|
||||
// to invoke Rules events in that load hook, which is also invoked for menu
|
||||
// item loading. Since this can happen even before hook_init() we need to make
|
||||
// sure that firing Rules events is enabled at that point. A typical use case
|
||||
// for this is Drupal Commerce with commerce_cart_commerce_order_load().
|
||||
if (!drupal_static('rules_init', FALSE)) {
|
||||
rules_event_invocation_enabled(TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_init().
|
||||
*/
|
||||
function rules_init() {
|
||||
// See rules_menu_get_item_alter().
|
||||
$rules_init = &drupal_static(__FUNCTION__, FALSE);
|
||||
$rules_init = TRUE;
|
||||
// Enable event invocation once hook_init() was invoked for Rules.
|
||||
rules_event_invocation_enabled(TRUE);
|
||||
rules_invoke_event('init');
|
||||
@@ -352,7 +386,7 @@ function &rules_get_cache($cid = 'data') {
|
||||
$cache[$cid] = FALSE;
|
||||
_rules_rebuild_component_cache();
|
||||
}
|
||||
elseif (strpos($cid, 'event_') === 0) {
|
||||
elseif (strpos($cid, 'event_') === 0 || $cid == 'rules_event_whitelist') {
|
||||
$cache[$cid] = FALSE;
|
||||
RulesEventSet::rebuildEventCache();
|
||||
}
|
||||
@@ -447,7 +481,6 @@ function rules_flush_caches() {
|
||||
*/
|
||||
function rules_clear_cache() {
|
||||
cache_clear_all('*', 'cache_rules', TRUE);
|
||||
variable_del('rules_event_whitelist');
|
||||
drupal_static_reset('rules_get_cache');
|
||||
drupal_static_reset('rules_fetch_data');
|
||||
drupal_static_reset('rules_config_update_dirty_flag');
|
||||
@@ -984,17 +1017,16 @@ function rules_invoke_all() {
|
||||
* @see rules_invoke_event_by_args()
|
||||
*/
|
||||
function rules_invoke_event() {
|
||||
global $conf;
|
||||
|
||||
$args = func_get_args();
|
||||
$event_name = $args[0];
|
||||
unset($args[0]);
|
||||
// We maintain a whitelist of configured events to reduces the number of cache
|
||||
// reads. We access it directly via the global $conf as this is fast without
|
||||
// having to introduce another static cache. Then, if the whitelist is unset,
|
||||
// we ignore it so cache rebuilding is triggered.
|
||||
if (rules_event_invocation_enabled() && (!isset($conf['rules_event_whitelist']) || isset($conf['rules_event_whitelist'][$event_name])) && $event = rules_get_cache('event_' . $event_name)) {
|
||||
$event->executeByArgs($args);
|
||||
// reads. If the whitelist is empty we proceed and it is rebuilt.
|
||||
if (rules_event_invocation_enabled()) {
|
||||
$whitelist = rules_get_cache('rules_event_whitelist');
|
||||
if ((empty($whitelist) || isset($whitelist[$event_name])) && $event = rules_get_cache('event_' . $event_name)) {
|
||||
$event->executeByArgs($args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1016,14 +1048,13 @@ function rules_invoke_event() {
|
||||
* @see rules_invoke_event()
|
||||
*/
|
||||
function rules_invoke_event_by_args($event_name, $args = array()) {
|
||||
global $conf;
|
||||
|
||||
// We maintain a whitelist of configured events to reduces the number of cache
|
||||
// reads. We access it directly via the global $conf as this is fast without
|
||||
// having to introduce another static cache. Then, if the whitelist is unset,
|
||||
// we ignore it so cache rebuilding is triggered.
|
||||
if (rules_event_invocation_enabled() && (!isset($conf['rules_event_whitelist']) || isset($conf['rules_event_whitelist'][$event_name])) && $event = rules_get_cache('event_' . $event_name)) {
|
||||
$event->executeByArgs($args);
|
||||
// reads. If the whitelist is empty we proceed and it is rebuilt.
|
||||
if (rules_event_invocation_enabled()) {
|
||||
$whitelist = rules_get_cache('rules_event_whitelist');
|
||||
if ((empty($whitelist) || isset($whitelist[$event_name])) && $event = rules_get_cache('event_' . $event_name)) {
|
||||
$event->executeByArgs($args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ files[] = rules_admin.module
|
||||
files[] = rules_admin.inc
|
||||
dependencies[] = rules
|
||||
|
||||
; Information added by Drupal.org packaging script on 2015-01-08
|
||||
version = "7.x-2.8"
|
||||
; Information added by Drupal.org packaging script on 2015-03-16
|
||||
version = "7.x-2.9"
|
||||
core = "7.x"
|
||||
project = "rules"
|
||||
datestamp = "1420734780"
|
||||
datestamp = "1426527210"
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ core = 7.x
|
||||
files[] = rules_i18n.i18n.inc
|
||||
files[] = rules_i18n.rules.inc
|
||||
files[] = rules_i18n.test
|
||||
; Information added by Drupal.org packaging script on 2015-01-08
|
||||
version = "7.x-2.8"
|
||||
; Information added by Drupal.org packaging script on 2015-03-16
|
||||
version = "7.x-2.9"
|
||||
core = "7.x"
|
||||
project = "rules"
|
||||
datestamp = "1420734780"
|
||||
datestamp = "1426527210"
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ files[] = includes/rules_scheduler.views_default.inc
|
||||
files[] = includes/rules_scheduler.views.inc
|
||||
files[] = includes/rules_scheduler_views_filter.inc
|
||||
|
||||
; Information added by Drupal.org packaging script on 2015-01-08
|
||||
version = "7.x-2.8"
|
||||
; Information added by Drupal.org packaging script on 2015-03-16
|
||||
version = "7.x-2.9"
|
||||
core = "7.x"
|
||||
project = "rules"
|
||||
datestamp = "1420734780"
|
||||
datestamp = "1426527210"
|
||||
|
||||
|
||||
+3
-3
@@ -5,9 +5,9 @@ core = 7.x
|
||||
files[] = rules_scheduler_test.inc
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by Drupal.org packaging script on 2015-01-08
|
||||
version = "7.x-2.8"
|
||||
; Information added by Drupal.org packaging script on 2015-03-16
|
||||
version = "7.x-2.9"
|
||||
core = "7.x"
|
||||
project = "rules"
|
||||
datestamp = "1420734780"
|
||||
datestamp = "1426527210"
|
||||
|
||||
|
||||
@@ -2099,3 +2099,50 @@ class RulesEventDispatcherTestCase extends DrupalWebTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test early bootstrap Rules invocation.
|
||||
*/
|
||||
class RulesInvocationEnabledTestCase extends DrupalWebTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Rules invocation enabled',
|
||||
'description' => 'Tests that Rules events are enabled during menu item loads.',
|
||||
'group' => 'Rules',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp('dblog', 'rules', 'rules_test', 'rules_test_invocation');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a Rules event is triggered on node menu item loading.
|
||||
*
|
||||
* @see rules_test_invocation_node_load()
|
||||
*/
|
||||
public function testInvocationOnNodeMenuLoading() {
|
||||
// Create a test node.
|
||||
$node = $this->drupalCreateNode(array('title' => 'Test'));
|
||||
// Enable Rules logging on the INFO level so that entries are written to
|
||||
// dblog.
|
||||
variable_set('rules_log_errors', RulesLog::INFO);
|
||||
// Create an empty rule that will fire in our node load hook.
|
||||
$rule = rules_reaction_rule();
|
||||
$rule->event('rules_test_event');
|
||||
$rule->save('test_rule');
|
||||
|
||||
// Visit the node page which should trigger the load hook.
|
||||
$this->drupalGet('node/' . $node->nid);
|
||||
$result = db_query("SELECT * FROM {watchdog} WHERE type = 'rules' AND message = 'Reacting on event %label.'")->fetch();
|
||||
$this->assertFalse(empty($result), 'Rules event was triggered and logged.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ files[] = rules_test.rules.inc
|
||||
files[] = rules_test.rules_defaults.inc
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by Drupal.org packaging script on 2015-01-08
|
||||
version = "7.x-2.8"
|
||||
; Information added by Drupal.org packaging script on 2015-03-16
|
||||
version = "7.x-2.9"
|
||||
core = "7.x"
|
||||
project = "rules"
|
||||
datestamp = "1420734780"
|
||||
datestamp = "1426527210"
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
name = "Rules Test invocation"
|
||||
description = "Helper module to test Rules invocations."
|
||||
package = Testing
|
||||
core = 7.x
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by Drupal.org packaging script on 2015-03-16
|
||||
version = "7.x-2.9"
|
||||
core = "7.x"
|
||||
project = "rules"
|
||||
datestamp = "1426527210"
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Helper module for Rules invocation testing.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_node_load().
|
||||
*/
|
||||
function rules_test_invocation_node_load($nodes, $types) {
|
||||
rules_invoke_event('rules_test_event');
|
||||
}
|
||||
Reference in New Issue
Block a user