You are here

function elysia_cron_cron in Elysia Cron 7.2

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

Implements hook_cron().

Hook cron is invoked only by standard drupal cron. It's used to replace drupal cron.

File

./elysia_cron.module, line 144

Code

function elysia_cron_cron() {
  global $_elysia_cron_exit_phase, $_elysia_cron_drush;

  // First cron run is executed in standard drupal way.
  // This is to enable the use of install profiles.
  if (variable_get('cron_last', 0) <= variable_get('install_time', 0)) {
    return;
  }

  // If cron has been executed via "drush core-cron" or any other custom drush
  // command then we run internal cron handler which is designed to handle
  // cron executions from drush.
  if (function_exists('elysia_cron_drush_detect') && elysia_cron_drush_detect()) {
    elysia_cron_drush_invoke();
  }

  // If the path is 'admin/*', or if the user is not anonymous,
  // this is a manual cron run (probably by admin/logs/status),
  // but not if we are in the exit phase (= this a "poormanscron" run).
  $manual_run = empty($_elysia_cron_exit_phase) && (arg(0) == 'admin' || !empty($GLOBALS['user']->uid));
  $result = elysia_cron_run($manual_run);
  if ($manual_run) {
    if ($result) {
      elysia_cron_message('Cron ran successfully');
    }
    else {
      elysia_cron_message('Cron run failed, disabled or nothing to do');
    }

    // In manual execution it's better to set cron_last variable in standard way
    // (so the user sees the execution time updates).
    // This invalidates variable cache, but it's a manual execution,
    // it should be not a great performance problem.
    if (empty($_elysia_cron_drush)) {
      variable_set('cron_last', time());
    }
    drupal_goto('admin/reports/status');
  }

  // If we are in "poormanscron" mode it's better to force setting of cron_last.
  // This invalidates variable cache, but is needed for right execution check.
  // @see system_run_automated_cron() in system.module
  if (!empty($_elysia_cron_exit_phase)) {
    variable_set('cron_last', time());
  }
  drupal_exit();
}