You are here

function hosting_task_view in Hosting 5

Same name and namespace in other branches
  1. 6.2 task/hosting_task.module \hosting_task_view()
  2. 7.4 task/hosting_task.module \hosting_task_view()
  3. 7.3 task/hosting_task.module \hosting_task_view()

Implementation of hook_view().

1 call to hosting_task_view()
hosting_wizard_hosting_verify in ./hosting.wizard.inc

File

task/hosting_task.module, line 290
Web server node type is defined here.

Code

function hosting_task_view($node, $teaser = FALSE, $page = FALSE) {
  drupal_add_js(drupal_get_path('module', 'hosting') . '/hosting.js');
  $node = node_prepare($node, $teaser);
  $ref = node_load($node->rid);
  hosting_set_breadcrumb($node);
  $node->content['info']['#prefix'] = '<div id="hosting-task-info" class="clear-block">';
  $node->content['info']['reference'] = array(
    '#type' => 'item',
    '#title' => drupal_ucfirst($ref->type),
    '#value' => _hosting_node_link($node->rid),
  );
  if (!$node->queued) {
    $node->content['info']['executed'] = array(
      '#type' => 'item',
      '#title' => t('Executed'),
      '#value' => format_date($node->executed),
    );
  }
  else {
    $queues = hosting_get_queues();
    $queue = $queues['tasks'];
    $freq = $queue['frequency'];
    $last = $queue['last_run'];
    $now = time();

    # the first part is the regular case: the task was never run, compute the next time

    # the second part is the case where the task wasn't run in the last queue run even though it was scheduled, so we compute the next iteration
    $next = max($last + $freq, $now - ($now - $last) % $freq + $freq);
    if ($freq < 60 * 60 * 12) {

      # 12h

      # display only the time if we have short iterations
      $date = format_date($next, 'custom', 'H:i:sO');
    }
    else {
      $date = format_date($next, 'medium');
    }
    $items = $queue['items'];
    $node->content['info']['notexecuted'] = array(
      '#type' => 'item',
      '#title' => t('This task has not been processed yet'),
      '#value' => t('It will be processed around %date, if the queue is not too crowded. The queue is currently ran every %freq, was last ran %last and processes %items items at a time. Server time is %time.', array(
        '%freq' => format_interval($freq),
        '%date' => $date,
        '%last' => hosting_format_interval($last),
        '%items' => $items,
        '%time' => format_date($now, 'custom', 'H:i:sO'),
      )),
    );
  }
  if ($node->task_status) {
    $node->content['info']['status'] = array(
      '#type' => 'item',
      '#title' => t('Status'),
      '#value' => _hosting_parse_error_code($node->task_status),
    );
  }
  $node->content['info']['#suffix'] = '</div>';
  if (user_access('retry failed tasks') && !$node->queued && $node->task_status == HOSTING_TASK_ERROR) {
    $node->content['retry'] = array(
      '#type' => 'markup',
      '#value' => drupal_get_form('hosting_task_retry_form', $node->nid),
      '#weight' => 5,
    );
  }
  if (user_access('access task logs')) {
    if ($table = _hosting_task_log_table($node->vid)) {
      $node->content['hosting_log'] = array(
        '#weight' => 10,
        '#type' => 'item',
        '#value' => $table,
      );
    }
  }
  return $node;
}