You are here

function hosting_task_view in Hosting 7.4

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

Implements hook_view().

File

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

Code

function hosting_task_view($node, $view_mode, $langcode = NULL) {
  drupal_add_js(drupal_get_path('module', 'hosting') . '/hosting.js');
  $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),
    '#markup' => _hosting_node_link($node->rid),
  );
  if ($node->task_status != HOSTING_TASK_QUEUED) {
    if ($node->task_status == HOSTING_TASK_PROCESSING) {
      $node->content['info']['started'] = array(
        '#type' => 'item',
        '#title' => t('Started'),
        '#markup' => format_date($node->executed),
        '#weight' => 1,
      );
      $node->content['info']['delta'] = array(
        '#type' => 'item',
        '#title' => t('Processing time'),
        '#markup' => format_interval(REQUEST_TIME - $node->executed),
        '#weight' => 2,
      );
    }
    elseif ($node->executed != NULL) {
      $node->content['info']['executed'] = array(
        '#type' => 'item',
        '#title' => t('Executed'),
        '#markup' => format_date($node->executed),
        '#weight' => 1,
      );
      $node->content['info']['delta'] = array(
        '#type' => 'item',
        '#title' => t('Execution time'),
        '#markup' => format_interval($node->delta),
        '#weight' => 2,
      );
    }
  }
  else {
    $queues = hosting_get_queues();
    $queue = $queues['tasks'];
    $next = _hosting_queue_next_run($queue);
    $node->content['info']['notexecuted'] = array(
      '#type' => 'item',
      '#title' => t('This task has not been processed yet'),
      '#markup' => t('It will be processed around %date, if the queue is not too crowded. The queue is currently run every %freq, was last run %last and processes %items items at a time. Server time is %time.', array(
        '%freq' => format_interval($queue['frequency']),
        '%date' => format_date($next, 'custom', 'H:i:sO'),
        '%last' => hosting_format_interval($queue['last_run']),
        '%items' => $queue['items'],
        '%time' => format_date(REQUEST_TIME, 'custom', 'H:i:sO'),
      )),
    );
  }
  if ($node->task_status) {
    $node->content['info']['status'] = array(
      '#type' => 'item',
      '#title' => t('Status'),
      '#markup' => _hosting_parse_error_code($node->task_status),
    );
  }
  $node->content['info']['#suffix'] = '</div>';
  if (user_access('retry failed tasks') && ($node->task_status == HOSTING_TASK_ERROR || $node->task_status == HOSTING_TASK_WARNING || $node->task_status == HOSTING_TASK_SUCCESS)) {
    $node->content['retry'] = array(
      'form' => drupal_get_form('hosting_task_retry_form', $node->nid),
      '#weight' => 5,
    );

    // Change the name of the form button to "Run Again" if the task ended ok.
    if ($node->task_status == HOSTING_TASK_WARNING || $node->task_status == HOSTING_TASK_SUCCESS) {
      $node->content['retry']['form']['retry']['#value'] = t('Run Again');
    }
  }
  if (user_access('update status of tasks') && $node->task_status == HOSTING_TASK_PROCESSING) {
    $node->content['update-status'] = array(
      'form' => drupal_get_form('hosting_task_update_status_form', $node->vid),
      '#weight' => 5,
    );
  }
  if (user_access('access task logs')) {
    if (in_array($node->task_status, array(
      HOSTING_TASK_ERROR,
      HOSTING_TASK_WARNING,
    ))) {
      $url_options = array(
        'attributes' => array(
          'class' => array(
            'hosting-button-enabled',
          ),
          'target' => '_self',
        ),
        'fragment' => 'warning',
      );
      if (module_exists('overlay') && overlay_get_mode() == 'child') {
        $url_options['query'] = array(
          'render' => 'overlay',
        );
      }
      $node->content['jump-link-warning'] = array(
        '#markup' => '<div>' . l(t('Jump to first warning'), request_path(), $url_options) . '</div>',
        '#weight' => 8,
      );
    }
    if ($node->task_status == HOSTING_TASK_ERROR) {
      $url_options['fragment'] = 'error';
      $node->content['jump-link-error'] = array(
        '#markup' => '<div>' . l(t('Jump to first error'), request_path(), $url_options) . '</div>',
        '#weight' => 9,
      );
    }
    if ($table = _hosting_task_log_table($node)) {
      $node->content['hosting_log'] = array(
        '#weight' => 10,
        'table' => $table,
      );
    }
  }
  return $node;
}