You are here

function _acquia_purge_queue_is_user_purging in Acquia Purge 6

Same name and namespace in other branches
  1. 7 acquia_purge.deprecated.inc \_acquia_purge_queue_is_user_purging()

Queue manager: determines if the current owns a running purge session.

@returns Boolean TRUE when the current user with the exact same session initiated a purge session earlier and thus owns the purge session.

See also

_acquia_purge_queue_add()

2 calls to _acquia_purge_queue_is_user_purging()
acquia_purge_init in ./acquia_purge.module
Implements hook_init().
_acquia_purge_trigger_client_side_purging in ./acquia_purge.module
Trigger client-side AJAX based purging during this request.
1 string reference to '_acquia_purge_queue_is_user_purging'
acquia_purge_menu in ./acquia_purge.module
Implements hook_menu().

File

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

Code

function _acquia_purge_queue_is_user_purging() {
  global $user;

  // Anonymous users are never able to trigger purges by design, if this would
  // ever become a necessity we'll introduce a permission to protect most sites.
  if (!isset($user->roles[DRUPAL_AUTHENTICATED_RID])) {
    return FALSE;
  }

  // Retrieve the list of user names owning a ongoing purge process.
  $owners = variable_get('acquia_purge_queue_owners', array());

  // If the owners list is empty, that means no active purges are ongoing.
  if (!count($owners)) {
    return FALSE;
  }

  // Is the current user one of the owners of the actively ongoing purge?
  if (!in_array($user->name, $owners)) {
    return FALSE;
  }

  // Are we running on a Acquia Cloud environment?
  if (!_acquia_purge_are_we_on_acquiacloud()) {
    return FALSE;
  }

  // All tests passed, this user can process the queue.
  return TRUE;
}