You are here

function acquia_purge_expire_cache in Acquia Purge 7

Same name and namespace in other branches
  1. 6 acquia_purge.module \acquia_purge_expire_cache()

Implements hook_expire_cache().

File

./acquia_purge.module, line 170
Acquia Purge, Top-notch Varnish purging on Acquia Cloud!

Code

function acquia_purge_expire_cache($urls, $wildcards, $object_type, $object) {

  // When running in passive mode, we stop automatic queuing.
  if (_acquia_purge_variable('acquia_purge_passivemode')) {
    return;
  }

  // Check for errors once, but refuse operation during the entire request.
  static $error;
  if (is_null($error)) {
    $diagnostics = _acquia_purge_service()
      ->diagnostics();
    if ($diagnostics
      ->isSystemBlocked()) {
      $errors = $diagnostics
        ->get(ACQUIA_PURGE_SEVLEVEL_ERROR);
      $diagnostics
        ->log($errors);

      // Only visualize errors when the user has permission and isn't silenced.
      $notsilent = !_acquia_purge_variable('acquia_purge_silentmode');
      $notcli = php_sapi_name() !== 'cli';
      if ($notsilent && $notcli && user_access('purge on-screen')) {
        foreach ($errors as $i => $error) {
          $errors[$i] = '<p>' . $error['description'] . '</p>';
        }
        drupal_set_message(t("<p>The system cannot publicly refresh the changes you just made,\n            because of the following error conditions:</p>!items<p>Please\n            contact your system administrator or development partner!</p>", array(
          '!items' => theme('item_list', array(
            'items' => $errors,
          )),
        )), 'error');
      }
    }
  }
  if ($error) {
    return;
  }

  // Add '<front>' to the list as empty strings don't pass validation.
  if (in_array('', $urls)) {
    $urls['<front>'] = '<front>';
  }

  // Now test every item against our strict validation checks.
  foreach ($urls as $id => $path) {
    if (_acquia_purge_input_validate($path)) {
      unset($urls[$id]);
    }
    elseif (_acquia_purge_variable('acquia_purge_trim_slashes')) {
      $urls[$id] = rtrim($path, '/');
    }
    else {
      $urls[$id] = $path;
    }
  }

  // Queue all paths that we received from Expire.
  _acquia_purge_service()
    ->addPaths($urls);
}