You are here

function background_batch_overview_page in Background Process 7.2

Same name and namespace in other branches
  1. 6 background_batch/background_batch.pages.inc \background_batch_overview_page()
  2. 7 background_batch/background_batch.pages.inc \background_batch_overview_page()

Overview of current and recent batch jobs.

1 string reference to 'background_batch_overview_page'
background_batch_menu in background_batch/background_batch.module
Implements hook_menu().

File

background_batch/background_batch.pages.inc, line 14
Pages for background batch.

Code

function background_batch_overview_page() {
  $data = array();
  $bids = db_select('batch', 'b', array(
    'target' => 'background_process',
  ))
    ->fields('b')
    ->orderBy('b.bid', 'DESC')
    ->execute()
    ->fetchAllAssoc('bid', PDO::FETCH_OBJ);
  $processes = array();
  foreach ($bids as $bid => $batch) {
    $process = BackgroundProcess::loadByHandle('background_batch:' . $bid);
    if ($process) {
      $progress = sprintf("%.02f%%", $process
        ->getProgress() * 100);
      $message = $process
        ->getProgressMessage();
      $start = format_date((int) $process
        ->getStartTime(), 'small');
      $eta = $process
        ->calculateETA();
      $eta = $eta ? format_date((int) $process
        ->calculateETA(), 'small') : t('N/A');
    }
    else {
      $batch = unserialize($batch->batch);
      $current_set = $batch['sets'][$batch['current_set']];
      list($progress, $message) = BackgroundBatchContext::processMessage($current_set);
      $progress = sprintf("%.02f%%", $progress * 100);
      $start = format_date((int) $current_set['start'], 'small');
      $eta = empty($batch['finish_time']) ? t('Not running') : format_date((int) $batch['finish_time'], 'small');
    }
    $data[] = array(
      l($bid, 'batch', array(
        'query' => array(
          'op' => 'start',
          'id' => $bid,
        ),
      )),
      $progress,
      $message,
      $start,
      $eta,
    );
  }
  $header = array(
    'Batch ID',
    'Progress',
    'Message',
    'Started',
    'Finished/ETA',
  );
  return theme('table', array(
    'header' => $header,
    'rows' => $data,
  ));
}