You are here

public function Lingotek::getProcessStatus in Lingotek Translation 4.0.x

Same name and namespace in other branches
  1. 3.7.x src/Lingotek.php \Drupal\lingotek\Lingotek::getProcessStatus()
  2. 3.8.x src/Lingotek.php \Drupal\lingotek\Lingotek::getProcessStatus()

Gets the status of the process.

Parameters

string $process_id: The process ID in Lingotek.

Return value

bool|int Returns TRUE if the import process is completed. FALSE if it was not existing or failed. The percentage if it's still in progress.

Overrides LingotekInterface::getProcessStatus

File

src/Lingotek.php, line 831

Class

Lingotek
The connecting class between Drupal and Lingotek

Namespace

Drupal\lingotek

Code

public function getProcessStatus($process_id) {
  try {
    $response = $this->api
      ->getProcess($process_id);
    if ($response
      ->getStatusCode() == Response::HTTP_OK) {

      // If an exception didn't happen, the document is succesfully imported.
      // The status value there is related with translation status, so we must
      // ignore it.
      $bodyResponse = Json::decode($response
        ->getBody(), TRUE);
      $progress = $bodyResponse['properties']['progress'];
      $completed = $progress === self::PROGRESS_COMPLETE && $bodyResponse['properties']['status'] === 'COMPLETED';
      return $completed ? TRUE : $progress;
    }
  } catch (LingotekApiException $exception) {
    return FALSE;
  }
  return FALSE;
}