You are here

function rules_scheduler_schedule_task in Rules 6

Same name and namespace in other branches
  1. 7.2 rules_scheduler/rules_scheduler.module \rules_scheduler_schedule_task()

Schedule a task by inserting it into the database.

Parameters

$rule_set_name: The machine readyble name of the rule set to be scheduled.

$date: Timestamp when the rule set should be executed.

$task_identifier: User provided string to identify the task within this rule set.

$arg_info: Array that contains information and structure of argument variables.

$arguments: Array of data for the given variables, in the same order as in $arg_info.

$log: Boolean flag to indicate whether the Rules log is available or not.

2 calls to rules_scheduler_schedule_task()
rules_scheduler_action in rules_scheduler/rules_scheduler.rules.inc
Base action implementation for scheduling all rule sets
rules_scheduler_manual_submit in rules_scheduler/rules_scheduler.admin.inc
Submit handler for manual scheduling of tasks.

File

rules_scheduler/rules_scheduler.module, line 93
Rules scheduler module.

Code

function rules_scheduler_schedule_task($rule_set_name, $date, $task_identifier = "", $arg_info = array(), $arguments = NULL, $log = FALSE) {
  $pack = rules_pack_variables($arg_info, $arguments);
  if ($pack !== FALSE) {
    if (!empty($task_identifier)) {

      // If there is a task with the same identifier and rule set,
      // we replace it, so we run a delete query first.
      db_query("DELETE FROM {rules_scheduler} WHERE set_name = '%s' AND identifier = '%s'", $rule_set_name, $task_identifier);
    }
    $rules_date = new rules_data_type_date();
    $date = $rules_date
      ->check_value(array(
      'label' => 'execution date',
    ), $date);
    drupal_write_record('rules_scheduler', $task = array(
      'date' => $date,
      'set_name' => $rule_set_name,
      'arguments' => $pack,
      'identifier' => $task_identifier,
    ));
  }
  elseif ($log) {
    rules_log(t('Packing arguments for scheduling the rule set %set failed.', array(
      '%set' => $rule_set_name,
    )), TRUE);
  }
}