You are here

public static function AcquiaPurgeProcessorAjax::pathCallback in Acquia Purge 7

Process a chunk of items form the queue and respond in JSON.

Return value

string Statistics array encoded as JSON, including a 'widget' HTML snippet.

File

lib/processor/AcquiaPurgeProcessorAjax.php, line 223
Contains AcquiaPurgeProcessorAjax.

Class

AcquiaPurgeProcessorAjax
Process the queue using a AJAX client-side UI.

Code

public static function pathCallback() {
  $service = _acquia_purge_service();
  $stats = $service
    ->stats();
  $stats['error'] = FALSE;
  $stats['widget'] = ' ';

  // Deny access when the current user didn't initiate queue processing.
  if (!self::isUserOwningTheQueue($service)) {
    $stats['running'] = FALSE;
    return drupal_json_output($stats);
  }

  // Test for blocking diagnostic issues and report any if found.
  if ($err = $service
    ->diagnostics()
    ->isSystemBlocked()) {
    $service
      ->diagnostics()
      ->log($err);
    $stats['error'] = $err['description'];
    return drupal_json_output($stats);
  }

  // Attempt to process a chunk from the queue.
  if ($service
    ->lockAcquire()) {
    $service
      ->process();
    foreach ($service
      ->stats() as $key => $value) {
      $stats[$key] = $value;
    }

    // When processing stalled, the history breadcrumb often stays empty and
    // this is a clear indication that errors occurred.
    if (empty($stats['purgehistory'])) {
      $stats['error'] = t("The system seems to be having difficulties\n          refreshing recent content changes. Your work won't be lost, but please\n          do ask your technical administrator to check the logs.");
    }
    $service
      ->lockRelease();
  }
  else {
    $stats['locked'] = TRUE;
  }

  // Render the status widget and render as JSON response.
  if (!$stats['error']) {
    $stats['widget'] = theme('acquia_purge_status_bar_widget', $stats);
  }
  return drupal_json_output($stats);
}