You are here

public function EntityDeleteHandler::execute in Services Client 7.2

Execute event and send event to remove endpoint.

Return value

ServicesClientEventResult

Overrides EventHandler::execute

File

include/event.inc, line 1049

Class

EntityDeleteHandler
General entity delete handler.

Code

public function execute() {

  // Create action result.
  $result = new ServicesClientEventResult();
  $result
    ->setHandler($this);
  $result->event = $this
    ->getEvent();
  $result->object = NULL;
  $result->entity = $this
    ->getEntity();
  $result->entity_type = $result->event->entity_type;

  // Allow other modules to react on before request.
  module_invoke_all('services_client_before_request', $this, NULL);
  $this
    ->log(ServicesClientLogLevel::INFO, "DELETING; connection : @connection, event : @event, entity_type : @entity_type, entity_id : @entity_id, uuid : @uuid", array(
    '@event' => $this->event->name,
    '@connection' => $this
      ->getConnectionId(),
    '@entity_type' => $this->event->entity_type,
    '@entity_id' => $this
      ->getEntityId(),
    '@uuid' => $this
      ->getEntity()->uuid,
  ));
  try {
    $result->response = $this
      ->doSync(NULL);
    $result->request = $this
      ->getConnection()
      ->getRequest();
  } catch (ServicesClientConnectionResponseException $e) {
    $e
      ->log();
    $result->error_message = $e
      ->getServicesMessage();
    $result->error_code = $e
      ->getErrorCode();
    $result->request = $e->request;

    // Determien what error type, by default we assume remote server failed.
    $error_type = ServicesClientErrorType::REMOTE_SERVER;

    // Logic errors that came from remote site, like can't login
    if ($e
      ->getErrorCode() >= 400 && $e
      ->getErrorCode() < 500) {
      $error_type = ServicesClientErrorType::REMOTE_LOGIC;
    }
    elseif ($e
      ->getErrorCode() < 100) {
      $error_type = ServicesClientErrorType::NETWORK;
    }

    // Set error type
    $result->error_type = $error_type;
  } catch (Exception $e) {
    $result->error_message = $e
      ->getMessage();
    $result->error_type = ServicesClientErrorType::UNKNOWN;
  }
  $this
    ->logErrorResult($result);
  $this
    ->afterSync(NULL, $result);

  // Allow other modules to react on after request.
  module_invoke_all('services_client_after_request', $this, NULL, $result);
  return $result;
}