more module updates

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-20 18:02:17 +02:00
parent 37fbabab56
commit 7c85261e56
100 changed files with 6518 additions and 913 deletions

View File

@@ -0,0 +1,99 @@
<?php
/**
* Default scheduled task handler.
*/
class RulesSchedulerDefaultTaskHandler implements RulesSchedulerTaskHandlerInterface {
/**
* The task array.
*
* @var array
*/
protected $task;
/**
* Constructs a repetitive task handler object.
*/
public function __construct(array $task) {
$this->task = $task;
}
/**
* Implements RulesSchedulerTaskHandlerInterface::runTask().
*/
public function runTask() {
if ($component = rules_get_cache('comp_' . $this->task['config'])) {
$replacements = array('%label' => $component->label(), '%plugin' => $component->plugin());
$replacements['%identifier'] = $this->task['identifier'] ? $this->task['identifier'] : t('without identifier');
rules_log('Scheduled evaluation of %plugin %label, task %identifier.', $replacements, RulesLog::INFO, $component, TRUE);
$state = unserialize($this->task['data']);
$state->restoreBlocks();
// Block the config to prevent any future recursion.
$state->block($component);
// Finally evaluate the component with the given state.
$component->evaluate($state);
$state->unblock($component);
rules_log('Finished evaluation of %plugin %label, task %identifier.', $replacements, RulesLog::INFO, $component, FALSE);
$state->cleanUp();
}
}
/**
* Implements RulesSchedulerTaskHandlerInterface::afterTaskQueued().
*/
public function afterTaskQueued() {
// Delete the task from the task list.
db_delete('rules_scheduler')
->condition('tid', $this->task['tid'])
->execute();
}
/**
* Implements RulesSchedulerTaskHandlerInterface::getTask().
*/
public function getTask() {
return $this->task;
}
}
/**
* Interface for scheduled task handlers.
*
* Task handlers control the behavior of a task when it's queued or executed.
* Unless specified otherwise, the RulesSchedulerDefaultTaskHandler task handler
* is used.
*
* @see rules_scheduler_run_task()
* @see rules_scheduler_cron()
* @see RulesSchedulerDefaultTaskHandler
*/
interface RulesSchedulerTaskHandlerInterface {
/**
* Processes a queue item.
*
* @throws RulesEvaluationException
* If there are any problems executing the task.
*
* @see rules_scheduler_run_task()
*/
public function runTask();
/**
* Processes a task after it has been queued.
*
* @see rules_scheduler_cron()
*/
public function afterTaskQueued();
/**
* Returns the task associated with the task handler.
*
* @return array
* The task (queue item) array.
*/
public function getTask();
}

View File

@@ -0,0 +1,81 @@
<?php
/**
* @file
* Rules Scheduler Drush integration.
*/
/**
* Implements hook_drush_command().
*/
function rules_scheduler_drush_command() {
$items = array();
$items['rules-scheduler-tasks'] = array(
'description' => 'Checks 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.',
),
'drupal dependencies' => array('rules', 'rules_scheduler'),
'aliases' => array('rusch'),
'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.',
),
);
return $items;
}
/**
* Implements hook_drush_help().
*/
function rules_scheduler_drush_help($section) {
switch ($section) {
case 'drush:rules-scheduler-tasks':
return dt('Checks for scheduled tasks to be added the queue. Can optionally claim tasks from the queue to work on.');
}
}
/**
* Command callback for processing the rules_scheduler_tasks queue.
*
* @see rules_scheduler_cron_queue_info().
* @see rules_scheduler_cron().
*/
function drush_rules_scheduler_tasks() {
if (rules_scheduler_queue_tasks()) {
// hook_exit() is not invoked for drush runs, so register it as shutdown
// callback for logging the rules log to the watchdog.
drupal_register_shutdown_function('rules_exit');
// Clear the log before running tasks via the queue to avoid logging
// unrelated logs from previous operations.
RulesLog::logger()->clear();
drush_log(dt('Added scheduled tasks to the queue.'), 'success');
}
$claim = drush_get_option('claim', FALSE);
if ($claim) {
// Fetch the queue information and let other modules alter it.
$queue_name = 'rules_scheduler_tasks';
$info = module_invoke('rules_scheduler', 'cron_queue_info');
drupal_alter('cron_queue_info', $info);
$function = $info[$queue_name]['worker callback'];
// The drush option can override the default process time.
$time = is_numeric($claim) ? (int) $claim : $info[$queue_name]['time'];
$end = time() + $time;
// Claim items and process the queue.
$queue = DrupalQueue::get($queue_name);
$claimed = 0;
while (time() < $end && ($item = $queue->claimItem())) {
$function($item->data);
$queue->deleteItem($item);
$claimed++;
}
if ($claimed) {
drush_log(dt('Claimed and worked on !claimed scheduled tasks for up to !time seconds.', array('!claimed' => $claimed, '!time' => $time)), 'success');
}
}
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* @file
* Include file for Rules Scheduler tests.
*/
/**
* Test task handler class.
*/
class RulesTestTaskHandler extends RulesSchedulerDefaultTaskHandler {
/**
* Overrides RulesSchedulerDefaultTaskHandler::runTask().
*/
public function runTask() {
$task = $this->getTask();
$data = unserialize($task['data']);
// Set the variable defined in the test to TRUE.
variable_set($data['variable'], TRUE);
}
}

View File

@@ -0,0 +1,13 @@
name = "Rules Scheduler Tests"
description = "Support module for the Rules Scheduler tests."
package = Testing
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"
core = "7.x"
project = "rules"
datestamp = "1426527210"

View File

@@ -0,0 +1,6 @@
<?php
/**
* @file
* Rules Scheduler test module.
*/