You are here

function ultimate_cron_cron_queue_info in Ultimate Cron 7.2

Same name and namespace in other branches
  1. 8 ultimate_cron.module \ultimate_cron_cron_queue_info()
  2. 7 ultimate_cron.module \ultimate_cron_cron_queue_info()

Implements hook_cron_queue_info().

Used for code injection in order to hijack cron runs.

File

./ultimate_cron.module, line 974

Code

function ultimate_cron_cron_queue_info() {
  $debug = debug_backtrace();
  $cron_debug_level = 3;
  if (version_compare(PHP_VERSION, '7.0.0', '>=')) {

    // PHP 7 will not include call_user_func_array in the backtrace.
    $cron_debug_level--;
  }
  if (!empty($debug[$cron_debug_level]['function']) && $debug[$cron_debug_level]['function'] == 'drupal_cron_run') {
    if (!empty($debug[$cron_debug_level + 1])) {
      try {
        if ($debug[$cron_debug_level + 1]['function'] == 'install_finished') {

          // Looks like drupal_cron_run() was called unexpectedly.
          watchdog('ultimate_cron', 'Running cron in compatibility mode during site install.', array(), WATCHDOG_DEBUG);
        }
        else {

          // Looks like drupal_cron_run() was called unexpectedly.
          watchdog('ultimate_cron', 'drupal_cron_run() called unexpectedly by @file:@line function @function. Running core in compatibility mode.', array(
            '@function' => $debug[$cron_debug_level + 1]['function'],
            '@line' => $debug[$cron_debug_level]['line'],
            '@file' => $debug[$cron_debug_level]['file'],
          ), WATCHDOG_DEBUG);
        }
        ultimate_cron_cron_run_compatibility();
      } catch (Throwable $e) {

        // Restore the user.
        $GLOBALS['user'] = $GLOBALS['ultimate_cron_original_user'];
        drupal_save_session($GLOBALS['ultimate_cron_original_session_saving']);
        throw $e;
      } catch (Exception $e) {

        // Restore the user.
        $GLOBALS['user'] = $GLOBALS['ultimate_cron_original_user'];
        drupal_save_session($GLOBALS['ultimate_cron_original_session_saving']);
        throw $e;
      }
      return array();
    }

    // Looks like drupal_cron_run() was called just the way we like it.
    ultimate_cron_cron_run();
    exit;
  }
  return array();
}