Commit b29bead1 authored by Loparev's avatar Loparev
Browse files

Used new SUBM v3 search endpoint for calls from cron

parent d26f239b
......@@ -19,6 +19,7 @@ use Smartling\Jobs\JobsApi;
use Smartling\ProgressTracker\ProgressTrackerApi;
use Smartling\Project\ProjectApi;
use Smartling\TranslationRequests\TranslationRequestsApi;
use Drupal\tmgmt_smartling\Smartling\Submission\TranslationRequestsApiV3;
/**
* Class SmartlingApiFactory
......@@ -85,6 +86,11 @@ class SmartlingApiFactory {
break;
case 'translation_request_v3':
$api = TranslationRequestsApiV3::create($auth_provider, $settings['project_id'], $logger);
break;
case 'audit':
$api = AuditLogApi::create($auth_provider, $settings['project_id'], $logger);
......
......@@ -423,6 +423,63 @@ class SmartlingApiWrapper {
return $result;
}
/**
* Returns translation request (without submission) by search params.
*
* @param $bucketName
* @param \Smartling\TranslationRequests\Params\SearchTranslationRequestParams $params
*
* @return mixed
*/
public function searchOnlyTranslationRequest($bucketName, SearchTranslationRequestParams $params) {
$result = [];
try {
$response = $this->getApi('translation_request_v3')->searchTranslationRequests($bucketName, $params);
$result = $response['items'];
}
catch (SmartlingApiException $e) {
$this->logger->error('Smartling failed to search translation request:<br/>
Bucket name: @bucket
Params: @params
Error: @error', [
'@bucket' => $bucketName,
'@params' => json_encode($params->exportToArray()),
'@error' => $e->getMessage(),
]);
}
return $result;
}
/**
* Returns translation request by uid.
*
* @param $bucketName
* @param $uid
*
* @return mixed
*/
public function getTranslationRequestByUid($bucketName, $uid) {
$result = FALSE;
try {
$result = $this->getApi('translation_request')->getTranslationRequest($bucketName, $uid);
}
catch (SmartlingApiException $e) {
$this->logger->error('Smartling failed to get translation request:<br/>
Bucket name: @bucket
Params: @params
Error: @error', [
'@bucket' => $bucketName,
'@uid' => $uid,
'@error' => $e->getMessage(),
]);
}
return $result;
}
/**
* Delete file.
*
......
<?php
namespace Drupal\tmgmt_smartling\Smartling\Submission;
use Smartling\TranslationRequests\TranslationRequestsApi;
/**
* Class TranslationRequestsApiV3
* @package Smartling\TranslationRequests
*/
class TranslationRequestsApiV3 extends TranslationRequestsApi
{
const ENDPOINT_URL = 'https://api.smartling.com/submission-service-api/v3/projects';
}
......@@ -55,7 +55,7 @@ function tmgmt_smartling_cron() {
$search_params->setLimit(100);
$bucket_name = Drupal::state()->get('tmgmt_smartling.bucket_name', 'tmgmt_smartling_default_bucket_name');
$result = $api_wrapper->searchTranslationRequest($bucket_name, $search_params);
$result = $api_wrapper->searchOnlyTranslationRequest($bucket_name, $search_params);
foreach ($result as $item) {
if (!isset($item['originalAssetKey']['tmgmt_job_id'])) {
......@@ -69,11 +69,20 @@ function tmgmt_smartling_cron() {
// TMGMT Job anymore.
if (empty($job)) {
try {
$translation_request_with_submission = $api_wrapper->getTranslationRequestByUid(
$bucket_name,
$item['translationRequestUid']
);
if (!isset($translation_request_with_submission['translationSubmissions'][0]['translationSubmissionUid'])) {
continue;
}
$update_submission_params = new UpdateTranslationSubmissionParams();
$update_submission_params
->setState(TranslationSubmissionStates::STATE_FAILED)
->setLastErrorMessage("TMGMT Job $tmgmt_job_id doesn't exist in Drupal and will not be scheduled for download")
->setTranslationSubmissionUid($item['translationSubmissions'][0]['translationSubmissionUid']);
->setTranslationSubmissionUid($translation_request_with_submission['translationSubmissions'][0]['translationSubmissionUid']);
$update_request_params = new UpdateTranslationRequestParams();
$update_request_params
......@@ -81,7 +90,7 @@ function tmgmt_smartling_cron() {
$api_wrapper->updateTranslationRequest(
$bucket_name,
$item['translationRequestUid'],
$translation_request_with_submission['translationRequestUid'],
$update_request_params
);
} catch (Exception $e) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment