You are here

protected function EventHandler::getRemoteIdByUUID in Services Client 7.2

Load remote ID by UUID based on remote UUID configuration.

Parameters

string $uuid: UUID identifier.

string $a1_resource: UUID module Alpha 1 version resource name. ('user', 'node')

string $a3_resource: UUID module Alpha 3+ version resource name. ('user', 'node')

string $a3_attribute: Alpha 3+ attribute that should be searched in retrieved object.

Return value

int Remote ID if found, otherwise NULL.

Throws

ServicesClientConnectionResponseException

2 calls to EventHandler::getRemoteIdByUUID()
EventHandler::getRemoteEntityId in include/event.inc
Retrieve remote entity ID.
NodeSaveHandler::getRemoteUserId in include/event.inc
Retrieve remote user ID.

File

include/event.inc, line 623

Class

EventHandler
Event handler plugin.

Code

protected function getRemoteIdByUUID($uuid, $a1_resource, $a3_resource, $a3_attribute = 'uuid') {

  // By UUID version decide what type of remote id is requested.
  if ($this->config['uuid_version'] == 'alpha1') {
    $result = $this
      ->getConnection()
      ->get('uuid', $a1_resource, array(
      'uuid' => $uuid,
    ));

    // Make sure we're getting scalar value
    if (is_array($result) && count($result) == 1 && isset($result[0])) {
      $result = $result[0];
    }
  }
  else {
    try {
      $result = $this
        ->getConnection()
        ->get($a3_resource, $uuid);
      if (!empty($result) && isset($result[$a3_attribute])) {
        $result = $result[$a3_attribute];
      }
      else {
        $result = NULL;
      }
    } catch (ServicesClientConnectionResponseException $e) {

      // Only log error different than 404, which means that entity doens't exists
      // on remote server.
      if ($e
        ->getErrorCode() != 404) {
        $e
          ->log();
        throw $e;
      }
      $result = NULL;
    }
  }
  return $result;
}