You are here

function elysia_cron_admin_page in Elysia Cron 7.2

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

Page callback for 'admin/config/system/cron' path.

Return value

array Renderable array.

Throws

Exception Exceptions from theme().

2 string references to 'elysia_cron_admin_page'
elysia_cron_menu in ./elysia_cron.module
Implements hook_menu().
elysia_cron_menu_alter in ./elysia_cron.module
Implements hook_menu_alter().

File

./elysia_cron.admin.inc, line 17
Admin page callbacks for the elysia cron module.

Code

function elysia_cron_admin_page() {
  $aoutput = array();
  if (elysia_cron_access('execute elysia_cron')) {
    $aoutput[] = drupal_get_form('elysia_cron_run_form');
  }
  $output = '';
  elysia_cron_initialize();
  global $_elysia_cron_settings_by_channel;
  $global_disabled = variable_get('elysia_cron_disabled', FALSE);
  $last_channel = elysia_cron_last_channel();
  $output .= '<p>' . t('Global disable') . ': <i>' . ($global_disabled ? '<span class="warn">' . t('YES') . '</span>' : t('no')) . '</i></p>';
  $output .= '<p>' . t('Last channel executed') . ': <i>' . ($last_channel ? $last_channel : t('n/a')) . '</i></p>';
  $running = '';
  foreach ($_elysia_cron_settings_by_channel as $channel => $data) {
    if (elysia_cron_is_channel_running($channel)) {
      $running .= $channel . ' ';
    }
  }
  if ($running) {
    $output .= '<p>' . t('Running channels') . ': <span class="warn">' . $running . '</span></p>';
  }
  $output .= '<p>' . t('Last run') . ': ' . elysia_cron_date(_ec_variable_get('elysia_cron_last_run', 0)) . '</p>';
  $rows = array();
  $ipath = drupal_get_path('module', 'elysia_cron') . '/images/icon_';
  foreach ($_elysia_cron_settings_by_channel as $channel => $data) {
    $running = elysia_cron_is_channel_running($channel);
    $rows[] = array(
      array(
        'data' => '<h3>' . t('Channel') . ': ' . $channel . ($data['#data']['disabled'] ? ' <span class="warn">(' . t('DISABLED') . ')</span>' : '') . '</h3>',
        'colspan' => 2,
        'header' => TRUE,
      ),
      array(
        'data' => elysia_cron_date($data['#data']['last_run']),
        'header' => TRUE,
      ),
      array(
        'data' => $data['#data']['last_execution_time'] . 's ' . t('(Shutdown: !shutdown)', array(
          '!shutdown' => $data['#data']['last_shutdown_time'] . 's',
        )),
        'header' => TRUE,
      ),
      array(
        'data' => $data['#data']['execution_count'],
        'header' => TRUE,
      ),
      array(
        'data' => $data['#data']['avg_execution_time'] . 's / ' . $data['#data']['max_execution_time'] . 's',
        'header' => TRUE,
      ),
    );
    $messages = '';
    if ($running) {
      $messages .= t('Running since !date', array(
        '!date' => elysia_cron_date($running),
      )) . '<br />';
    }
    if ($data['#data']['last_aborted'] || $data['#data']['abort_count']) {
      $msg = array();
      if ($data['#data']['last_aborted']) {
        $msg[] = t('Last aborted') . (!empty($data['#data']['last_abort_function']) ? ': <span class="warn">' . t('On function !function', array(
          '!function' => $data['#data']['last_abort_function'],
        )) . '</span>' : '');
      }
      if ($data['#data']['abort_count']) {
        $msg[] = t('Abort count') . ': <span class="warn">' . $data['#data']['abort_count'] . '</span>';
      }
      $messages .= implode(', ', $msg) . '<br />';
    }
    if ($messages) {
      $rows[] = array(
        '',
        '',
        array(
          'data' => $messages,
          'colspan' => 4,
          'header' => TRUE,
        ),
      );
      $rows[] = array(
        array(
          'data' => '',
          'colspan' => 6,
        ),
      );
    }
    foreach ($data as $job => $conf) {
      $icon = 'idle';
      $caption = '<b>' . $job . '</b>';
      $tip = t('Idle');
      if ($conf['disabled']) {
        $icon = 'disabled';
        $caption = '<strike><b>' . $job . '</b></strike>';
        $tip = t('Disabled');
      }
      elseif (!empty($conf['running'])) {
        $icon = 'running';
        $caption = '<b><u>' . $job . '</u></b>';
        $tip = t('Running');
      }
      elseif (elysia_cron_should_run($conf)) {
        $icon = 'waiting';
        $tip = t('Waiting for execution');
      }
      if ($job != '#data') {
        $force_run = elysia_cron_access('execute elysia_cron') ? l(t('Force run'), 'admin/config/system/cron/execute/' . $job, array(
          'attributes' => array(
            'onclick' => 'return confirm("' . t('Force execution of !job?', array(
              '!job' => $job,
            )) . '");',
          ),
        )) : '';
        $icon_image = theme('image', array(
          'path' => $ipath . $icon . '.png',
          'alt' => $tip,
          'title' => $tip,
        ));
        $rows[] = array(
          array(
            'data' => $icon_image,
            'align' => 'right',
          ),
          array(
            'data' => $caption . ': <i>' . elysia_cron_description($job) . '</i> ',
            'colspan' => 4,
          ),
          array(
            'data' => $force_run,
            'align' => 'right',
          ),
        );
        $rows[] = array(
          '',
          check_plain($conf['rule']) . (!empty($conf['weight']) ? ' <small>(' . t('Weight') . ': ' . $conf['weight'] . ')</small>' : ''),
          elysia_cron_date($conf['last_run']),
          $conf['last_execution_time'] . 's',
          $conf['execution_count'],
          $conf['avg_execution_time'] . 's / ' . $conf['max_execution_time'] . 's',
        );
      }
    }
    $rows[] = array(
      '&nbsp;',
      '',
      '',
      '',
      '',
      '',
    );
  }
  $output .= theme('table', array(
    'header' => array(
      '',
      t('Job / Rule'),
      t('Last run'),
      t('Last exec time'),
      t('Exec count'),
      t('Avg/Max Exec time'),
    ),
    'rows' => $rows,
  ));
  $output .= '<br />';
  $legend_icons = array(
    'idle' => theme('image', array(
      'path' => $ipath . 'idle.png',
      'alt' => t('Idle'),
      'title' => t('Idle'),
    )),
    'waiting' => theme('image', array(
      'path' => $ipath . 'waiting.png',
      'alt' => t('Waiting for execution'),
      'title' => t('Waiting for execution'),
    )),
    'running' => theme('image', array(
      'path' => $ipath . 'running.png',
      'alt' => t('Running'),
      'title' => t('Running'),
    )),
    'disabled' => theme('image', array(
      'path' => $ipath . 'disabled.png',
      'alt' => t('Disabled'),
      'title' => t('Disabled'),
    )),
  );
  $output .= theme('table', array(
    'header' => array(
      t('Legend'),
    ),
    'rows' => array(
      array(
        $legend_icons['idle'] . ' - ' . t("Job shouldn't do anything right now"),
      ),
      array(
        $legend_icons['waiting'] . ' - ' . t('Job is ready to be executed, and is waiting for system cron call'),
      ),
      array(
        $legend_icons['running'] . ' - ' . t('Job is running right now'),
      ),
      array(
        $legend_icons['disabled'] . ' - ' . t("Job is disabled by settings, and won't run until enabled again"),
      ),
      array(
        t("Notes: job times don't include shutdown times (only shown on channel times)."),
      ),
      array(
        t('If an abort occurs usually the job is not properly terminated, and so job timings can be inaccurate or wrong.'),
      ),
    ),
  ));
  $aoutput[] = array(
    '#type' => 'markup',
    '#markup' => $output,
  );
  return $aoutput;
}