You are here

function acquia_purge_ajax_processor in Acquia Purge 6

Menu callback; process a chunk of purge items via AJAX.

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

4 string references to 'acquia_purge_ajax_processor'
acquia_purge_init in ./acquia_purge.module
Implements hook_init().
acquia_purge_menu in ./acquia_purge.module
Implements hook_menu().
drush_acquia_purge_ap_forget in ./acquia_purge.drush.inc
Forget all scheduled purges and empty the queue.
drush_acquia_purge_ap_process in ./acquia_purge.drush.inc
Purge all queued items from the command line.

File

./acquia_purge.admin.inc, line 14
Admin page callbacks and theme functions for the Acquia Purge module.

Code

function acquia_purge_ajax_processor() {
  $status = _acquia_purge_queue_stats();

  // Define a key 'error' that describes a potential error condition.
  $status['error'] = $status['locked'] = FALSE;

  // Lock acquiring assures us that nothing is purging the same paths at the
  // same time. All ways that trigger purging (ajax, drush) respect the locks.
  if (lock_acquire('acquia_purge_ajax_processor', ACQUIA_PURGE_QUEUE_LOCK_TIMEOUT)) {

    // Pop items from the queue and immediately process them.
    _acquia_purge_queue_pop('_acquia_purge_queue_processpurge');

    // Refresh the statistics post-run, so override most fields in $status.
    foreach (_acquia_purge_queue_stats() as $key => $value) {
      $status[$key] = $value;
    }

    // Ask our built-in diagnostics system to preliminary find issues that are
    // so risky we can expect problems. Everything starting with
    // ACQUIA_PURGE_SEVLEVEL_ERROR will cause purging to cease and log messages
    // to be written. Warn the user on any of them.
    if (count($e = _acquia_purge_get_diagnosis(ACQUIA_PURGE_SEVLEVEL_ERROR))) {
      $error = current($e);
      $status['error'] = $error['description'];
    }
    elseif (empty($status['purgehistory'])) {
      $status['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.");
    }

    // We're done so lets release the lock.
    lock_release('acquia_purge_ajax_processor');
  }
  else {
    $status['locked'] = TRUE;
  }

  // Render the status widget and add it to the statistics array.
  $status['widget'] = theme('acquia_purge_status_bar_widget', $status);

  // Return the status array with statistics...
  return drupal_json($status);
}