You are here

function _ultimate_cron_preload_cron_data in Ultimate Cron 6

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

Load all cronjob settings and processes.

Return value

array Array of cronjobs and their data.

3 calls to _ultimate_cron_preload_cron_data()
drush_ultimate_cron_cron_list in ./ultimate_cron.drush.inc
List cron jobs.
ultimate_cron_nagios_get_job_info in ./ultimate_cron.nagios.inc
Get information about running jobs - currently running or failed.
ultimate_cron_view_page in ./ultimate_cron.admin.inc
Page overviewing cron jobs.

File

./ultimate_cron.module, line 1341
@todo Add filter on overview page. @todo Add log view (with graph). @todo Make proper markup for overview page. @todo Refactor drush stuff, too many intimate relations with Background Process @todo Refactor Cron % offset stuff. Too mixed up and…

Code

function _ultimate_cron_preload_cron_data() {
  $handle_prefix = variable_get('ultimate_cron_handle_prefix', ULTIMATE_CRON_HANDLE_PREFIX);
  if (module_exists('ctools')) {
    ctools_include('export');
    $functions = ctools_export_crud_load_all('ultimate_cron');
  }
  else {
    $functions = array();
    $result = db_query("SELECT name, settings FROM {ultimate_cron}");
    while ($function = db_fetch_object($result)) {
      if (!empty($function->settings)) {
        $function->settings = unserialize($function->settings);
      }
      $functions[$function->name] = $function;
    }
  }
  $hooks = ultimate_cron_get_hooks();
  $processes = array();
  if (function_exists('background_process_update_status')) {
    $result = db_query("SELECT handle, service_host, start_stamp AS start, exec_status AS status FROM {background_process} WHERE handle LIKE '%s%%'", $handle_prefix);
  }
  else {
    $result = db_query("SELECT handle, service_host, start, status FROM {background_process} WHERE handle LIKE '%s%%'", $handle_prefix);
  }
  while ($process = db_fetch_object($result)) {
    $processes[$process->handle] = $process;
  }
  $data = array();
  foreach ($hooks as $name => $hook) {
    $settings = empty($functions[$name]->settings) ? array() : $functions[$name]->settings;
    $settings += $hook['settings'];
    $handle = $handle_prefix . $name;
    $data[$name] = array(
      'settings' => $settings,
      'background_process' => empty($processes[$handle]) ? NULL : (object) $processes[$handle],
    );
  }
  return $data;
}