You are here

public function LingotekApi::deleteDocument in Lingotek Translation 8.2

Same name and namespace in other branches
  1. 8 src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::deleteDocument()

Delete a document on Lingotek.

Parameters

string $id: The document id.

Return value

mixed

Overrides LingotekApiInterface::deleteDocument

Deprecated

in 8.x-2.14, will be removed in 8.x-2.16. Use ::cancelDocument instead.

File

src/Remote/LingotekApi.php, line 117

Class

LingotekApi
A simple connector to the Lingotek Translation API.

Namespace

Drupal\lingotek\Remote

Code

public function deleteDocument($id) {
  try {
    $this->logger
      ->debug('Lingotek::deleteDocument called with id ' . $id);
    $response = $this->lingotekClient
      ->delete('/api/document/' . $id);
  } catch (\Exception $e) {
    $http_status_code = $e
      ->getCode();
    if ($http_status_code === Response::HTTP_NOT_FOUND) {
      $this->logger
        ->error('Error deleting document: %message.', [
        '%message' => $e
          ->getMessage(),
      ]);
      return new Response($e
        ->getMessage(), Response::HTTP_NOT_FOUND);
    }
    $this->logger
      ->error('Error deleting document: %message.', [
      '%message' => $e
        ->getMessage(),
    ]);
    throw new LingotekApiException('Failed to delete document: ' . $e
      ->getMessage(), $http_status_code, $e);
  }
  $this->logger
    ->debug('deleteDocument response received, code %code and body %body', [
    '%code' => $response
      ->getStatusCode(),
    '%body' => (string) $response
      ->getBody(TRUE),
  ]);
  return $response;
}