You are here

function ultimate_cron_function_log_page in Ultimate Cron 6

Same name and namespace in other branches
  1. 8 ultimate_cron.admin.inc \ultimate_cron_function_log_page()
  2. 7 ultimate_cron.admin.inc \ultimate_cron_function_log_page()

Function log page.

1 string reference to 'ultimate_cron_function_log_page'
ultimate_cron_menu in ./ultimate_cron.module
Implementation of hook_menu().

File

./ultimate_cron.admin.inc, line 454

Code

function ultimate_cron_function_log_page($function) {
  $hooks = ultimate_cron_get_hooks();
  if (!isset($hooks[(string) $function])) {
    drupal_not_found();
    exit;
  }
  drupal_add_css(drupal_get_path('module', 'ultimate_cron') . '/css/ultimate_cron.admin.css');
  $header = array(
    array(
      'data' => t('Start'),
      'field' => 'start_stamp',
      'sort' => 'DESC',
    ),
    array(
      'data' => t('End'),
      'field' => 'end_stamp',
    ),
    t('Duration'),
    t('Service host'),
    t('Status'),
    t('Message'),
  );
  drupal_set_title(check_plain($function));
  $sql = "SELECT l.lid, l.name, l.start_stamp, l.end_stamp, l.service_host, l.exec_status, l.msg, l.severity FROM {ultimate_cron_log} l WHERE l.name = '%s'";
  $sql .= tablesort_sql($header);
  $result = pager_query($sql, 10, 0, NULL, $function);
  $logs = array();
  while ($log = db_fetch_object($result)) {
    $logs[] = $log;
  }
  $handle_prefix = variable_get('ultimate_cron_handle_prefix', ULTIMATE_CRON_HANDLE_PREFIX);
  $output = '';
  $rows = array();
  if (empty($_GET['page']) && ($process = background_process_get_process($handle_prefix . $function))) {
    $data = array(
      array(
        'class' => 'ultimate-cron-admin-start',
      ),
      array(
        'class' => 'ultimate-cron-admin-end',
      ),
      array(
        'class' => 'ultimate-cron-admin-duration',
      ),
      array(
        'class' => 'ultimate-cron-admin-service-host',
      ),
      array(
        'class' => 'ultimate-cron-admin-status ultimate-cron-admin-status-running',
      ),
      array(
        'class' => 'ultimate-cron-admin-message',
      ),
    );
    $duration = time() - $process->start_stamp;
    $duration = gmdate('H:i:s', (int) $duration);
    $progress = progress_get_progress($handle_prefix . $function);
    if ($progress && $progress->progress > 0) {
      $duration .= sprintf(" (%d%%)", $progress->progress * 100);
    }
    $data[0]['data'] = format_date((int) $process->start_stamp, 'custom', 'Y-m-d H:i:s');
    $data[1]['data'] = t('N/A');
    $data[2]['data'] = $duration;
    $data[3]['data'] = $process->service_host ? $process->service_host : t('N/A');
    $data[4]['data'] = '<span>' . t('running') . '</span>';
    $data[5]['data'] = '';
    $rows[] = $data;
  }
  foreach ($logs as $log) {
    $log->function = $log->name;
    $log->status = $log->exec_status;
    $log->start = $log->start_stamp;
    $log->end = $log->end_stamp;
    $severity_type = $log->severity < 0 ? 'success' : ($log->severity >= WATCHDOG_NOTICE ? 'info' : ($log->severity >= WATCHDOG_WARNING ? 'warning' : 'error'));
    $css_status = $severity_type;
    $data = array(
      array(
        'class' => 'ultimate-cron-admin-start',
      ),
      array(
        'class' => 'ultimate-cron-admin-end',
      ),
      array(
        'class' => 'ultimate-cron-admin-duration',
      ),
      array(
        'class' => 'ultimate-cron-admin-service-host',
      ),
      array(
        'class' => 'ultimate-cron-admin-status ultimate-cron-admin-status-' . $css_status,
      ),
      array(
        'class' => 'ultimate-cron-admin-message',
      ),
    );
    $data[0]['data'] = format_date((int) $log->start, 'custom', 'Y-m-d H:i:s');
    $data[1]['data'] = format_date((int) $log->end, 'custom', 'Y-m-d H:i:s');
    $data[2]['data'] = gmdate('H:i:s', (int) ($log->end - $log->start));
    $data[3]['data'] = $log->service_host;
    $data[4]['data'] = '<span>' . $log->status . '</span>';
    $data[5]['data'] = $log->msg;
    $rows[] = $data;
  }
  $output .= theme('table', $header, $rows);
  $output .= theme('pager');
  return $output;
}