You are here

function background_process_service_access in Background Process 6

Same name and namespace in other branches
  1. 8 background_process.module \background_process_service_access()
  2. 7.2 background_process.module \background_process_service_access()
  3. 7 background_process.module \background_process_service_access()

Access handler for service call

1 call to background_process_service_access()
_background_process_queue in ./background_process.module
Worker callback for processing queued function call
1 string reference to 'background_process_service_access'
background_process_menu in ./background_process.module
Implements hook_menu().

File

./background_process.module, line 283

Code

function background_process_service_access($handle, $token) {

  // Damn those slashes!
  $handle = rawurldecode($handle);
  $token = rawurldecode($token);

  // Ensure no session!
  session_save_session(FALSE);
  unset($_SESSION);
  $process = background_process_get_process($handle);
  if (!$process) {
    watchdog('bg_process', 'Unknown process: %handle', array(
      '%handle' => $handle,
    ));
    return FALSE;
  }
  if ($token !== $process->token) {
    watchdog('bg_process', 'Invalid token: %token for handle: %handle', array(
      '%token' => $token,
      '%handle' => $handle,
    ));
    return FALSE;
  }

  // Login as the user that requested the call
  if ($process->uid) {
    global $user;
    $user = user_load($process->uid);
    if (!$user) {

      // Invalid user!
      return FALSE;
    }
  }
  else {
    $user = drupal_anonymous_user();
  }
  return TRUE;
}