You are here

public function UltimateCronLauncher::run in Ultimate Cron 7.2

Run the job.

Parameters

UltimateCronJob $job: The job to run.

File

./ultimate_cron.plugin.inc, line 988
Plugin framework for Ultimate Cron.

Class

UltimateCronLauncher
Abstract class for Ultimate Cron launchers.

Code

public function run($job) {

  // Prevent session information from being saved while cron is running.
  $original_session_saving = drupal_save_session();
  drupal_save_session(FALSE);

  // Force the current user to anonymous to ensure consistent permissions on
  // cron runs.
  $original_user = $GLOBALS['user'];
  $GLOBALS['user'] = drupal_anonymous_user();
  $php_self = NULL;
  try {

    // Signal to whomever might be listening, that we're cron!
    // @investigate Is this safe? (He asked knowingly ...)
    $php_self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : '';
    $_SERVER['PHP_SELF'] = 'cron.php';
    $job
      ->invoke();

    // Restore state.
    $_SERVER['PHP_SELF'] = $php_self;
  } catch (Throwable $e) {

    // Restore state.
    if (isset($php_self)) {
      $_SERVER['PHP_SELF'] = $php_self;
    }
    ultimate_cron_watchdog_throwable('ultimate_cron', $e, 'Error running @name: @error', array(
      '@name' => $job->name,
      '@error' => (string) $e,
    ), WATCHDOG_ERROR);
  } catch (Exception $e) {

    // Restore state.
    if (isset($php_self)) {
      $_SERVER['PHP_SELF'] = $php_self;
    }
    watchdog_exception('ultimate_cron', $e, 'Error running @name: @error', array(
      '@name' => $job->name,
      '@error' => (string) $e,
    ), WATCHDOG_ERROR);
  }

  // Restore the user.
  $GLOBALS['user'] = $original_user;
  drupal_save_session($original_session_saving);
}