You are here

public static function AcquiaPurgeProcessorAjax::isUserOwningTheQueue in Acquia Purge 7

Determine if the processor should run.

Parameters

AcquiaPurgeService $service: The Acquia Purge service object.

Return value

bool Either TRUE or FALSE.

2 calls to AcquiaPurgeProcessorAjax::isUserOwningTheQueue()
AcquiaPurgeProcessorAjax::onInit in lib/processor/AcquiaPurgeProcessorAjax.php
Implements event onInit.
AcquiaPurgeProcessorAjax::pathCallback in lib/processor/AcquiaPurgeProcessorAjax.php
Process a chunk of items form the queue and respond in JSON.

File

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

Class

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

Code

public static function isUserOwningTheQueue(AcquiaPurgeService $service) {

  // Anonymous users can never process the queue.
  if (!user_is_logged_in()) {
    return FALSE;
  }

  // Retrieve the list of user names owning an ongoing purge process.
  $uiusers = $service
    ->state()
    ->get('uiusers', array())
    ->get();

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

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

  // Are we running on a Acquia Cloud environment?
  if (!$service
    ->hostingInfo()
    ->isThisAcquiaCloud()) {
    return FALSE;
  }

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