updated rules

This commit is contained in:
2020-06-23 12:29:12 +02:00
parent 35b78db5c0
commit da7085e201
72 changed files with 2402 additions and 1060 deletions
@@ -1,5 +1,10 @@
<?php
/**
* @file
* Views integration for the rules scheduler module.
*/
/**
* Default scheduled task handler.
*/
@@ -6,8 +6,9 @@
*/
/**
* Implements hook_views_data(). Specifies the list of future scheduled
* tasks displayed on the schedule page.
* Implements hook_views_data().
*
* Specifies the list of future scheduled tasks displayed on the schedule page.
*/
function rules_scheduler_views_data() {
$table = array(
@@ -9,7 +9,7 @@
* Implements hook_views_default_views().
*/
function rules_scheduler_views_default_views() {
$view = new view;
$view = new view();
$view->name = 'rules_scheduler';
$view->description = 'Scheduled Rules components';
$view->tag = '';
@@ -4,8 +4,10 @@
* @file
* An extended subclass for component filtering.
*/
class rules_scheduler_views_filter extends views_handler_filter_in_operator {
function get_value_options() {
public function get_value_options() {
if (!isset($this->value_options)) {
$this->value_title = t('Component');
$result = db_select('rules_scheduler', 'r')
@@ -19,4 +21,5 @@ class rules_scheduler_views_filter extends views_handler_filter_in_operator {
$this->value_options = $config_names;
}
}
}
}
@@ -9,7 +9,7 @@
* Schedule page with a view for the scheduled tasks.
*/
function rules_scheduler_schedule_page() {
// Display view for all scheduled tasks
// Display view for all scheduled tasks.
if (module_exists('views')) {
// We cannot use views_embed_view() here as we need to set the path for the
// component filter form.
@@ -18,7 +18,7 @@ function rules_scheduler_schedule_page() {
$task_list = $view->preview();
}
else {
$task_list = t('To display scheduled tasks you have to install the <a href="http://drupal.org/project/views">Views</a> module.');
$task_list = t('To display scheduled tasks you have to install the <a href="https://www.drupal.org/project/views">Views</a> module.');
}
$page['task_view'] = array(
'#markup' => $task_list,
@@ -44,7 +44,7 @@ function rules_scheduler_form($form, &$form_state) {
$form['delete_by_config'] = array(
'#type' => 'fieldset',
'#title' => t('Delete tasks by component name'),
'#disabled' => empty($config_options)
'#disabled' => empty($config_options),
);
$form['delete_by_config']['config'] = array(
'#title' => t('Component'),
@@ -57,7 +57,7 @@ function rules_scheduler_form($form, &$form_state) {
'#type' => 'submit',
'#value' => t('Delete tasks'),
'#submit' => array('rules_scheduler_form_delete_by_config_submit'),
);
);
return $form;
}
@@ -90,7 +90,6 @@ function rules_scheduler_delete_task($form, &$form_state, $task) {
else {
$msg = t('This task executes component %label and will be executed on %date. The action cannot be undone.', array(
'%label' => $config->label(),
'%id' => $task['identifier'],
'%date' => format_date($task['date']),
));
}
@@ -116,7 +115,7 @@ function rules_scheduler_schedule_form($form, &$form_state, $rules_config, $base
$form_state['component'] = $rules_config->name;
$action = rules_action('schedule', array('component' => $rules_config->name));
$action->form($form, $form_state);
// The component should be fixed, so hide the paramter for it.
// The component should be fixed, so hide the parameter for it.
$form['parameter']['component']['#access'] = FALSE;
$form['submit'] = array(
'#type' => 'submit',
@@ -12,7 +12,7 @@ function rules_scheduler_drush_command() {
$items = array();
$items['rules-scheduler-tasks'] = array(
'description' => 'Checks for scheduled tasks to be added to the queue.',
'description' => 'Check for scheduled tasks to be added to the queue.',
'options' => array(
'claim' => 'Optionally claim tasks from the queue to work on. Any value set will override the default time spent on this queue.',
),
@@ -21,7 +21,7 @@ function rules_scheduler_drush_command() {
'examples' => array(
'drush rusch' => 'Add scheduled tasks to the queue.',
'drush rusch --claim' => 'Add scheduled tasks to the queue and claim items for the default amount of time.',
'drush rusch --claim=30' => 'Add schedules tasks to the queue and claim items for 30 seconds.',
'drush rusch --claim=30' => 'Add scheduled tasks to the queue and claim items for 30 seconds.',
),
);
@@ -41,8 +41,8 @@ function rules_scheduler_drush_help($section) {
/**
* Command callback for processing the rules_scheduler_tasks queue.
*
* @see rules_scheduler_cron_queue_info().
* @see rules_scheduler_cron().
* @see rules_scheduler_cron_queue_info()
* @see rules_scheduler_cron()
*/
function drush_rules_scheduler_tasks() {
if (rules_scheduler_queue_tasks()) {
@@ -3,19 +3,17 @@ description = Schedule the execution of Rules components using actions.
dependencies[] = rules
package = Rules
core = 7.x
files[] = rules_scheduler.admin.inc
files[] = rules_scheduler.module
files[] = rules_scheduler.install
files[] = rules_scheduler.rules.inc
files[] = rules_scheduler.test
files[] = includes/rules_scheduler.handler.inc
files[] = includes/rules_scheduler.views_default.inc
files[] = includes/rules_scheduler.views.inc
; Views handlers
files[] = includes/rules_scheduler_views_filter.inc
; Information added by Drupal.org packaging script on 2015-03-16
version = "7.x-2.9"
; Test cases
files[] = tests/rules_scheduler.test
files[] = tests/rules_scheduler_test.inc
; Information added by Drupal.org packaging script on 2019-01-24
version = "7.x-2.12"
core = "7.x"
project = "rules"
datestamp = "1426527210"
datestamp = "1548305586"
@@ -31,7 +31,8 @@ function rules_scheduler_schema() {
'not null' => TRUE,
),
'data' => array(
'type' => 'text',
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'serialize' => TRUE,
'description' => 'The whole, serialized evaluation data.',
@@ -47,7 +48,7 @@ function rules_scheduler_schema() {
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
'description' => 'The fully qualified class name of a the queue item handler.',
'description' => 'The fully-qualified class name of the queue item handler.',
),
),
'primary key' => array('tid'),
@@ -61,6 +62,24 @@ function rules_scheduler_schema() {
return $schema;
}
/**
* Implements hook_install().
*/
function rules_scheduler_install() {
// Create the queue to hold scheduled tasks.
$queue = DrupalQueue::get('rules_scheduler_tasks', TRUE);
$queue->createQueue();
}
/**
* Implements hook_uninstall().
*/
function rules_scheduler_uninstall() {
// Clean up after ourselves by deleting the queue and all items in it.
$queue = DrupalQueue::get('rules_scheduler_tasks');
$queue->deleteQueue();
}
/**
* Upgrade from Rules scheduler 6.x-1.x to 7.x.
*/
@@ -136,7 +155,7 @@ function rules_scheduler_update_7203() {
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
'description' => 'The fully qualified class name of a the queue item handler.',
'description' => 'The fully-qualified class name of the queue item handler.',
));
}
@@ -154,6 +173,21 @@ function rules_scheduler_update_7204() {
}
}
/**
* Use blob:big for rules_scheduler.data for compatibility with PostgreSQL.
*/
function rules_scheduler_update_7205() {
if (db_field_exists('rules_scheduler', 'data')) {
db_change_field('rules_scheduler', 'data', 'data', array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'serialize' => TRUE,
'description' => 'The whole, serialized evaluation data.',
));
}
}
/**
* Rules upgrade callback for mapping the action name.
*/
@@ -103,7 +103,7 @@ function rules_scheduler_menu() {
'access arguments' => array('administer rules'),
'file' => 'rules_scheduler.admin.inc',
);
$items[RULES_SCHEDULER_PATH .'/%rules_scheduler_task/delete'] = array(
$items[RULES_SCHEDULER_PATH . '/%rules_scheduler_task/delete'] = array(
'title' => 'Delete a scheduled task',
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
@@ -115,7 +115,10 @@ function rules_scheduler_menu() {
}
/**
* Load a task by a given task ID.
* Loads a task by a given task ID.
*
* @param int $tid
* The task ID.
*/
function rules_scheduler_task_load($tid) {
$result = db_select('rules_scheduler', 'r')
@@ -126,7 +129,10 @@ function rules_scheduler_task_load($tid) {
}
/**
* Delete a task by a given task ID.
* Deletes a task by a given task ID.
*
* @param int $tid
* The task ID.
*/
function rules_scheduler_task_delete($tid) {
db_delete('rules_scheduler')
@@ -137,9 +143,9 @@ function rules_scheduler_task_delete($tid) {
/**
* Schedule a task to be executed later on.
*
* @param $task
* @param array $task
* An array representing the task with the following keys:
* - config: The machine readable name of the to be scheduled component.
* - config: The machine readable name of the to-be-scheduled component.
* - date: Timestamp when the component should be executed.
* - state: (deprecated) Rules evaluation state to use for scheduling.
* - data: Any additional data to store with the task.
@@ -166,8 +172,8 @@ function rules_scheduler_schedule_task($task) {
/**
* Queue tasks that are ready for execution.
*
* @return boolean
* Returns TRUE if any queue items where created, otherwise FALSE.
* @return bool
* TRUE if any queue items where created, otherwise FALSE.
*/
function rules_scheduler_queue_tasks() {
$items_created = FALSE;
@@ -209,6 +215,6 @@ function rules_scheduler_rules_config_delete($rules_config) {
function rules_scheduler_views_api() {
return array(
'api' => '3.0-alpha1',
'path' => drupal_get_path('module', 'rules_scheduler') .'/includes',
'path' => drupal_get_path('module', 'rules_scheduler') . '/includes',
);
}
@@ -5,6 +5,7 @@
* Rules integration for the rules scheduler module.
*
* @addtogroup rules
*
* @{
*/
@@ -115,7 +116,9 @@ function rules_scheduler_action_schedule_info_alter(&$element_info, RulesPlugin
}
/**
* Validate callback for the schedule action to make sure the component exists and is not dirty.
* Validate callback for the schedule action.
*
* Makes sure the component exists and is not dirty.
*
* @see rules_element_invoke_component_validate()
*/
@@ -137,7 +140,7 @@ function rules_scheduler_action_schedule_validate(RulesPlugin $element) {
*/
function rules_scheduler_action_schedule_help() {
return t("Note that component evaluation is triggered by <em>cron</em> make sure cron is configured correctly by checking your site's !status. The scheduling time accuracy depends on your configured cron interval. See <a href='@url'>the online documentation</a> for more information on how to schedule evaluation of components.",
array('!status' => l('Status report', 'admin/reports/status'),
array('!status' => l(t('Status report'), 'admin/reports/status'),
'@url' => rules_external_help('scheduler')));
}
@@ -192,7 +195,7 @@ function rules_scheduler_action_delete($component_name = NULL, $task_identifier
}
/**
* Cancel scheduled task action validation callback.
* Cancels scheduled task action validation callback.
*/
function rules_scheduler_action_delete_validate($element) {
if (empty($element->settings['task']) && empty($element->settings['task:select']) &&
@@ -206,7 +209,7 @@ function rules_scheduler_action_delete_validate($element) {
* Help for the cancel action.
*/
function rules_scheduler_action_delete_help() {
return t('This action allows you to delete scheduled tasks that are waiting for future execution.') .' '. t('They can be addressed by an identifier or by the component name, whereas if both are specified only tasks fulfilling both requirements will be deleted.');
return t('This action allows you to delete scheduled tasks that are waiting for future execution.') . ' ' . t('They can be addressed by an identifier or by the component name, whereas if both are specified only tasks fulfilling both requirements will be deleted.');
}
/**
@@ -5,9 +5,15 @@
* Rules Scheduler tests.
*/
/**
* Test cases for the Rules Scheduler module.
*/
class RulesSchedulerTestCase extends DrupalWebTestCase {
static function getInfo() {
/**
* Declares test metadata.
*/
public static function getInfo() {
return array(
'name' => 'Rules Scheduler tests',
'description' => 'Test scheduling components.',
@@ -15,10 +21,13 @@ class RulesSchedulerTestCase extends DrupalWebTestCase {
);
}
function setUp() {
/**
* Overrides DrupalWebTestCase::setUp().
*/
protected function setUp() {
parent::setUp('rules_scheduler', 'rules_scheduler_test');
RulesLog::logger()->clear();
variable_set('rules_debug_log', 1);
variable_set('rules_debug_log', TRUE);
}
/**
@@ -27,7 +36,7 @@ class RulesSchedulerTestCase extends DrupalWebTestCase {
* Note that this also makes sure Rules properly handles timezones, else this
* test could fail due to a wrong 'now' timestamp.
*/
function testComponentSchedule() {
public function testComponentSchedule() {
$set = rules_rule_set(array(
'node1' => array('type' => 'node', 'label' => 'node'),
));
@@ -51,7 +60,7 @@ class RulesSchedulerTestCase extends DrupalWebTestCase {
$rule->execute($node);
// Run cron to let the rules scheduler do its work.
drupal_cron_run();
$this->cronRun();
$node = node_load($node->nid, NULL, TRUE);
$this->assertFalse($node->status, 'The component has been properly scheduled.');
@@ -59,9 +68,9 @@ class RulesSchedulerTestCase extends DrupalWebTestCase {
}
/**
* Make sure recurion prevention is working fine for scheduled rule sets.
* Makes sure recursion prevention is working fine for scheduled rule sets.
*/
function testRecursionPrevention() {
public function testRecursionPrevention() {
$set = rules_rule_set(array(
'node1' => array('type' => 'node', 'label' => 'node'),
));
@@ -78,7 +87,7 @@ class RulesSchedulerTestCase extends DrupalWebTestCase {
$rule->event('node_update');
$rule->action('schedule', array(
'component' => 'rules_test_set_2',
'identifier' => '',
'identifier' => 'test_recursion_prevention',
'date' => 'now',
'param_node1:select' => 'node',
));
@@ -87,13 +96,32 @@ class RulesSchedulerTestCase extends DrupalWebTestCase {
// Create a node, what triggers the rule.
$node = $this->drupalCreateNode(array('title' => 'The title.', 'status' => 1));
// Run cron to let the rules scheduler do its work.
drupal_cron_run();
$this->cronRun();
$node = node_load($node->nid, NULL, TRUE);
$this->assertFalse($node->status, 'The component has been properly scheduled.');
$text1 = RulesLog::logger()->render();
$text2 = RulesTestCase::t('Not evaluating reaction rule %unlabeled to prevent recursion.', array('unlabeled' => $rule->name));
$this->assertTrue((strpos($text1, $text2) !== FALSE), "Scheduled recursion prevented.");
// Create a simple user account with permission to see the dblog.
$user = $this->drupalCreateUser(array('access site reports'));
$this->drupalLogin($user);
// View the database log.
$this->drupalGet('admin/reports/dblog');
// Can't use
// $this->clickLink('Rules debug information: " Scheduled evaluation...')
// because xpath doesn't allow : or " in the string.
// So instead, use our own xpath to figure out the href of the second link
// on the page (the first link is the most recent log entry, which is the
// log entry for the user login, above.)
// All links.
$links = $this->xpath('//a[contains(@href, :href)]', array(':href' => 'admin/reports/event/'));
// Strip off /?q= from href.
$href = explode('=', $links[1]['href']);
// Click the link for the RulesLog entry.
$this->drupalGet($href[1]);
$this->assertRaw(RulesTestCase::t('Not evaluating reaction rule %unlabeled to prevent recursion.', array('unlabeled' => $rule->name)), "Scheduled recursion prevented.");
RulesLog::logger()->checkLog();
}
@@ -112,10 +140,10 @@ class RulesSchedulerTestCase extends DrupalWebTestCase {
));
// Run cron to let the rules scheduler do its work.
drupal_cron_run();
$this->cronRun();
// The task handler should have set the variable to TRUE now.
$this->assertTrue(variable_get($variable));
}
}
}
@@ -5,9 +5,8 @@ core = 7.x
files[] = rules_scheduler_test.inc
hidden = TRUE
; Information added by Drupal.org packaging script on 2015-03-16
version = "7.x-2.9"
; Information added by Drupal.org packaging script on 2019-01-24
version = "7.x-2.12"
core = "7.x"
project = "rules"
datestamp = "1426527210"
datestamp = "1548305586"