You are here

function drush_elysia_cron_run_wrapper in Elysia Cron 6.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 elysia_cron.drush.inc \drush_elysia_cron_run_wrapper()
  4. 7.2 elysia_cron.drush.inc \drush_elysia_cron_run_wrapper()
  5. 7 elysia_cron.drush.inc \drush_elysia_cron_run_wrapper()

A drush command callback.

wraps the elysia_cron_run function, passing manual = true

2 string references to 'drush_elysia_cron_run_wrapper'
elysia_cron_drush_command in ./elysia_cron.drush.inc
Implementation of hook_drush_command().
elysia_cron_drush_invoke in ./elysia_cron.drush.inc

File

./elysia_cron.drush.inc, line 75

Code

function drush_elysia_cron_run_wrapper($op = false, $target = false) {

  /*
    drush_log("test notice", "notice");
    drush_log("test ok", "ok");
    drush_log("test completed", "completed");
    drush_log("test warning", "warning");
    drush_log("test error", "error");
    drush_print("print");
  */
  global $elysia_cron_drush;
  $quiet = drush_get_option("quiet", false);
  $verbose = drush_get_option("verbose", false);
  if (!$verbose) {
    $verbose = drush_get_option("elysia-cron-verbose", false);
  }
  $elysia_cron_drush = $quiet ? 1 : !$verbose ? 2 : 3;
  switch ($op) {
    case 'list':
      global $elysia_cron_settings_by_channel;
      elysia_cron_initialize();
      foreach ($elysia_cron_settings_by_channel as $channel => $jobs) {
        if (!$verbose) {
          $line = array(
            "@" . $channel,
          );
        }
        else {
          $line = array(
            "Channel: @" . $channel,
          );
          if ($running = elysia_cron_is_channel_running($channel)) {
            $line[] = "RUNNING NOW, since " . elysia_cron_date($running);
          }
          if (!empty($jobs['#data']['disabled'])) {
            $line[] = "DISABLED";
          }
          if (!$running) {
            $line[] = "Last run: " . elysia_cron_date(_ec_variable_get('elysia_cron_last_run', 0));
          }
        }
        drush_print(implode($line, ", "));
        foreach ($jobs as $job => $conf) {
          if ($job[0] != '#') {
            if (!$verbose) {
              $line = array(
                $job,
              );
            }
            else {
              $line = array(
                "- Job: " . $job,
              );
              if (!empty($conf['running'])) {
                $line[] = "RUNNING NOW, since " . elysia_cron_date($conf['running']);
              }
              if (!empty($conf['disabled'])) {
                $line[] = "DISABLED";
              }
              if (empty($conf['running']) && elysia_cron_should_run($conf)) {
                $line[] = "Ready to run";
              }
              if (empty($conf['running'])) {
                $line[] = "Last run: " . elysia_cron_date($conf['last_run']);
              }
            }
            drush_print(implode($line, ", "));
          }
        }
      }
      break;
    case 'run':
      if (empty($target)) {
        elysia_cron_run(true, drush_get_option("ignore-disable", false), drush_get_option("ignore-time", false), drush_get_option("ignore-running", false));

        //drush_log("Cron run complete", "completed");
      }
      elseif ($target[0] == '@') {
        elysia_cron_initialize();
        if (elysia_cron_channel_exists(substr($target, 1))) {
          elysia_cron_run_channel(substr($target, 1), drush_get_option("ignore-disable", false), drush_get_option("ignore-time", false), drush_get_option("ignore-running", false));

          //drush_log("Cron run complete", "completed");
        }
        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, drush_get_option("ignore-disable", false), drush_get_option("ignore-time", false), drush_get_option("ignore-running", false));

          //drush_log("Cron run complete", "completed");
        }
        else {
          drush_set_error('Job ' . $target . ' does not exists');
        }
      }
      break;
    case 'disable':
    case 'enable':
      if (!empty($target)) {
        if ($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;
      break;
    default:
      drush_print_help(drush_get_command());
  }
}