[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/rules/rules_scheduler/ -> rules_scheduler.rules.inc (source)

   1  <?php
   2  // $Id: rules_scheduler.rules.inc,v 1.1.2.7 2009/09/06 16:24:13 klausi Exp $
   3  
   4  
   5  /**
   6   * @file
   7   * Rules integration for the rules scheduler module.
   8   */
   9  
  10  /**
  11   * Implementation of hook_rules_action_info().
  12   */
  13  function rules_scheduler_rules_action_info() {
  14    $items = array();
  15    // Add actions for all rule sets.
  16    foreach (rules_get_configured_items('rule_sets') as $name => $set_info) {
  17      $items['rules_action_schedule_set_'. $name] = $set_info + array(
  18        'module' => 'Rule Scheduler',
  19        'base' => 'rules_scheduler_action',
  20        'set' => $name,
  21      );
  22      $item = &$items['rules_action_schedule_set_'. $name];
  23      $item['label'] = t('Schedule "@set"', array('@set' => $set_info['label']));
  24      $item += array('arguments' => array());
  25      $date_arg = array('task_date' => array(
  26          'type' => 'date',
  27          'label' => t('Scheduled evaluation date'),
  28        ));
  29      $item['arguments'] = array_merge($date_arg, $item['arguments']);
  30      $identifier_arg = array('task_identifier' => array(
  31          'type' => 'string',
  32          'label' => t('Identifier'),
  33          'description' => t('User provided string to identify the task. Existing tasks for this rule set with the same identifier will be replaced.'),
  34        ));
  35      $item['arguments'] = array_merge($identifier_arg, $item['arguments']);
  36    }
  37    
  38    // Add action to delete scheduled tasks
  39    $items['rules_action_delete_scheduled_set'] = array(
  40      'label' => t('Delete scheduled tasks'),
  41      'module' => 'Rule Scheduler',
  42      'base' => 'rules_scheduler_action_delete',
  43      'arguments' => array(
  44        'task_identifier' => array(
  45          'type' => 'string',
  46          'label' => t('Identifier'),
  47          'description' => t('All tasks that are annotated with this user provided identifier will be deleted.'),
  48        ),
  49        'ruleset' => array(
  50          'type' => 'string',
  51          'label' => t('Rule set'),
  52          'description' => t('All tasks that execute this rule set will be deleted.'),
  53        ),
  54      ),
  55    );
  56    return $items;
  57  }
  58  
  59  /**
  60   * Base action implementation for scheduling all rule sets
  61   */
  62  function rules_scheduler_action() {
  63    $args     = func_get_args();
  64    // Remove additional information from the arguments array
  65    $state    = array_pop($args);
  66    $element  = array_pop($args);
  67    $settings = array_pop($args);
  68    // Remove task ID and date arguments
  69    $task_id = array_shift($args);
  70    $date = array_shift($args);
  71    // Remove task ID and date from info entry
  72    array_shift($element['#info']['arguments']);
  73    array_shift($element['#info']['arguments']);
  74    
  75    rules_scheduler_schedule_task($element['#info']['set'], $date, $task_id, $element['#info']['arguments'], $args, TRUE);
  76  }
  77  
  78  /**
  79   * Help for the base action implementation.
  80   */
  81  function rules_scheduler_action_help() {
  82    return t("The evaluation of the rule set is going to be scheduled by cron. So make sure you have configured cron correctly by checking your site's !status.", array('!status' => l('Status report', 'admin/reports/status'))) .' '. t('Also note that the scheduling time accuracy depends on your configured cron interval.');
  83  }
  84  
  85  /**
  86   * Action implementation for deleting already scheduled tasks.
  87   */
  88  function rules_scheduler_action_delete($task_identifier = NULL, $rule_set_name = NULL) {
  89    if (!empty($rule_set_name)) {
  90      if (!empty($task_identifier)) {
  91        db_query("DELETE FROM {rules_scheduler} WHERE set_name = '%s' AND identifier = '%s'", $rule_set_name, $task_identifier);
  92      }
  93      else {
  94        db_query("DELETE FROM {rules_scheduler} WHERE set_name = '%s'", $rule_set_name);
  95      }
  96    }
  97    else {
  98      if (!empty($task_identifier)) {
  99        db_query("DELETE FROM {rules_scheduler} WHERE identifier = '%s'", $task_identifier);
 100      }
 101    }
 102  }
 103  
 104  /**
 105   * Help for the delete action.
 106   */
 107  function rules_scheduler_action_delete_help() {
 108    return t('This action allows you to cancel scheduled tasks that are waiting for future execution.') .' '. t('They can be addressed by an identifier or by the rule set name, if both are specified only tasks fulfilling both requirements will be deleted.');
 109  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7