You are here

function drush_elysia_cron_run_wrapper in Elysia Cron 7.2

Same name and namespace in other branches
  1. 5.2 elysia_cron.drush.inc \drush_elysia_cron_run_wrapper()
  2. 5 elysia_cron.drush.inc \drush_elysia_cron_run_wrapper()
  3. 6.2 elysia_cron.drush.inc \drush_elysia_cron_run_wrapper()
  4. 6 elysia_cron.drush.inc \drush_elysia_cron_run_wrapper()
  5. 7 elysia_cron.drush.inc \drush_elysia_cron_run_wrapper()

Custom callback for 'elysia-cron' drush command.

2 string references to 'drush_elysia_cron_run_wrapper'
elysia_cron_drush_command in ./elysia_cron.drush.inc
Implements hook_drush_command().
elysia_cron_drush_invoke in ./elysia_cron.drush.inc
Wrapper for drush_invoke().

File

./elysia_cron.drush.inc, line 81
Drush integration for Elysia cron module.

Code

function drush_elysia_cron_run_wrapper($op = FALSE, $target = FALSE) {
  global $_elysia_cron_drush;
  $force = drush_get_option('force', FALSE);
  if (variable_get('maintenance_mode', FALSE)) {
    $ignore_maintenance = $force || drush_get_option('ignore-maintenance', FALSE);
    if (!$ignore_maintenance && !variable_get('elysia_cron_run_maintenance', FALSE)) {
      drush_set_error('Cron run is not allowed in maintenance mode');
      return;
    }
  }
  $quiet = drush_get_option('quiet', FALSE);
  $verbose = drush_get_option('verbose', FALSE);
  if (!$verbose) {
    $verbose = drush_get_option('elysia-cron-verbose', FALSE);
  }
  if ($quiet) {
    $_elysia_cron_drush = 1;
  }
  elseif ($verbose) {
    $_elysia_cron_drush = 3;
  }
  else {
    $_elysia_cron_drush = 2;
  }
  switch ($op) {
    case 'list':
      global $_elysia_cron_settings_by_channel;
      elysia_cron_initialize();
      foreach ($_elysia_cron_settings_by_channel as $channel => $jobs) {
        $lines = array();
        if (!$verbose) {
          $line = array(
            '@' . $channel,
          );
        }
        else {
          $line = array(
            'Channel: @' . $channel,
          );
          if ($running = elysia_cron_is_channel_running($channel)) {
            $line[] = dt('Running, since !time', array(
              '!time' => elysia_cron_date($running),
            ));
          }
          if (!empty($jobs['#data']['disabled'])) {
            $line[] = dt('Disabled');
          }
          if (!$running) {
            $line[] = dt('Last run: !time', array(
              '!time' => elysia_cron_date(_ec_variable_get('elysia_cron_last_run', 0)),
            ));
          }
        }
        drush_print(implode(', ', $line));
        foreach ($jobs as $job => $conf) {
          $line = array();
          if (strpos($job, '#') !== 0) {
            if (!$verbose) {
              drush_print($job);
            }
            else {
              $line['name'] = $job;
              $line['status'] = empty($conf['disabled']) ? dt('Enabled') : dt('Disabled');
              $line['run_status'] = empty($conf['running']) && elysia_cron_should_run($conf) ? dt('Ready to run') : dt('Waiting');
              $line['run_status'] = !empty($conf['running']) ? dt('Running, since !time', array(
                '!time' => elysia_cron_date($conf['running']),
              )) : $line['run_status'];
              $line['last_run'] = !empty($conf['last_run']) ? dt('Last run: !time', array(
                '!time' => elysia_cron_date($conf['last_run']),
              )) : '';
              $lines[] = $line;
            }
          }
        }
        if ($lines) {
          drush_print_table($lines);
        }
      }
      break;
    case 'run':

      // Collect options.
      $ignore_disable = $force || drush_get_option('ignore-disable', FALSE);
      $ignore_time = $force || drush_get_option('ignore-time', FALSE);
      $ignore_running = $force || drush_get_option('ignore-running', FALSE);
      if (empty($target)) {
        elysia_cron_run(FALSE, $ignore_disable, $ignore_time, $ignore_running);
      }
      elseif (strpos($target, '@') === 0) {
        elysia_cron_initialize();
        if (elysia_cron_channel_exists(substr($target, 1))) {
          elysia_cron_run_channel(substr($target, 1), $ignore_disable, $ignore_time, $ignore_running);
        }
        else {
          drush_set_error('Channel ' . substr($target, 1) . ' does not exists');
        }
      }
      else {
        elysia_cron_initialize();
        if (elysia_cron_job_exists($target)) {
          elysia_cron_run_job($target, $ignore_disable, $ignore_time, $ignore_running);
        }
        else {
          drush_set_error('Job ' . $target . ' does not exists');
        }
      }
      break;
    case 'disable':
    case 'enable':
      if (!empty($target)) {
        if (strpos($target, '@') === 0) {
          elysia_cron_set_channel_disabled(substr($target, 1), $op == 'disable');
        }
        else {
          elysia_cron_set_job_disabled($target, $op == 'disable');
        }
        drush_log('Done', 'ok');
      }
      else {
        drush_set_error('Target not specified');
      }
      break;
    default:
      drush_print_help(drush_get_command());
      break;
  }
}