Commit ec084660 authored by Loparev's avatar Loparev
Browse files

Do not search by file uri + use file uri from translation request for downloading

parent d286a599
......@@ -139,7 +139,6 @@ class TranslationRequestManager {
$search_params = new SearchTranslationRequestParams();
$search_params->setOriginalAssetKey($asset_key);
$search_params->setTargetAssetKey($asset_key);
$search_params->setFileUri($job->getTranslatorPlugin()->getFileName($job));
$search_params->setTargetLocaleId($job->getRemoteTargetLanguage());
$translation_requests = $this->apiWrapper->searchTranslationRequest($this->getBucketName($job), $search_params);
......
......@@ -30,7 +30,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->translationRequestManagerMock->expects($this->once())
->method('getTranslationRequest')
->with($translate_job)
->willReturn(['translationRequestUid' => 'test']);
->willReturn(['translationRequestUid' => 'test', 'fileUri' => 'test_file_uri.xml']);
$this->apiWrapperMock->expects($this->once())
->method('getApi')
......@@ -49,7 +49,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->fileApiMock->expects($this->once())
->method('downloadFile')
->with(
'JobID1_en_de.xml',
'test_file_uri.xml',
'de',
$this->callback(function($subject) {
$params = $subject->exportToArray();
......@@ -62,7 +62,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->pluginMock->expects($this->once())
->method('validateImport')
->with(
'public://tmgmt_smartling_translations/JobID1_en_de.xml',
'public://tmgmt_smartling_translations/test_file_uri.xml',
$translate_job
)
->willReturn(TRUE);
......@@ -70,7 +70,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->pluginMock->expects($this->once())
->method('import')
->with(
'public://tmgmt_smartling_translations/JobID1_en_de.xml',
'public://tmgmt_smartling_translations/test_file_uri.xml',
$translate_job
)
->willReturn([]);
......@@ -83,7 +83,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->apiWrapperMock->expects($this->at(2))
->method('createFirebaseRecord')
->with('tmgmt_smartling', 'notifications', 10, [
"message" => 'Translation for "public://tmgmt_smartling_translations/JobID1_en_de.xml" (job id = 1) was successfully downloaded and imported.',
"message" => 'Translation for "public://tmgmt_smartling_translations/test_file_uri.xml" (job id = 1) was successfully downloaded and imported.',
"type" => "status",
]);
......@@ -163,7 +163,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->translationRequestManagerMock->expects($this->once())
->method('getTranslationRequest')
->willReturn(['translationRequestUid' => 'test']);
->willReturn(['translationRequestUid' => 'test', 'fileUri' => 'test_file_uri.xml']);
$this->apiWrapperMock->expects($this->once())
->method('getApi')
......@@ -182,7 +182,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->fileApiMock->expects($this->once())
->method('downloadFile')
->with(
'JobID1_en_de.xml',
'test_file_uri.xml',
'de',
$this->callback(function($subject) {
$params = $subject->exportToArray();
......@@ -200,7 +200,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->pluginMock->expects($this->once())
->method('validateImport')
->with(
'public://tmgmt_smartling_translations/JobID1_en_de.xml',
'public://tmgmt_smartling_translations/test_file_uri.xml',
$translate_job
)
->willReturn(TRUE);
......@@ -211,7 +211,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->apiWrapperMock->expects($this->once())
->method('createFirebaseRecord')
->with('tmgmt_smartling', 'notifications', 10, [
"message" => 'Translation for "public://tmgmt_smartling_translations/JobID1_en_de.xml" (job id = 1) was successfully downloaded but import was skipped: downloaded and existing translations are equal.',
"message" => 'Translation for "public://tmgmt_smartling_translations/test_file_uri.xml" (job id = 1) was successfully downloaded but import was skipped: downloaded and existing translations are equal.',
"type" => "warning",
]);
......@@ -223,7 +223,7 @@ class DownloadFlowTest extends SmartlingTestBase {
*/
public function testDownloadFailFlow() {
$exception = new \Exception("Test");
$translation_request = ['translationRequestUid' => 'test'];
$translation_request = ['translationRequestUid' => 'test', 'fileUri' => 'test_file_uri.xml'];
$translate_job = $this->createJobWithItems([
'batch_uid' => 'uid',
'batch_execute_on_job' => 1,
......@@ -251,7 +251,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->fileApiMock->expects($this->once())
->method('downloadFile')
->with(
'JobID1_en_de.xml',
'test_file_uri.xml',
'de',
$this->callback(function($subject) {
$params = $subject->exportToArray();
......@@ -277,7 +277,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->apiWrapperMock->expects($this->once())
->method('createFirebaseRecord')
->with('tmgmt_smartling', 'notifications', 10, [
"message" => 'File JobID1_en_de.xml (job id = 1) wasn\'t downloaded. Please see logs for more info.',
"message" => 'File test_file_uri.xml (job id = 1) wasn\'t downloaded. Please see logs for more info.',
"type" => "error",
]);
......@@ -299,7 +299,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->translationRequestManagerMock->expects($this->once())
->method('getTranslationRequest')
->with($translate_job)
->willReturn(['translationRequestUid' => 'test']);
->willReturn(['translationRequestUid' => 'test', 'fileUri' => 'test_file_uri.xml']);
$this->apiWrapperMock->expects($this->once())
->method('getApi')
......@@ -318,7 +318,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->fileApiMock->expects($this->once())
->method('downloadFile')
->with(
'JobID1_en_de.xml',
'test_file_uri.xml',
'de',
$this->callback(function($subject) {
$params = $subject->exportToArray();
......@@ -331,7 +331,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->pluginMock->expects($this->once())
->method('validateImport')
->with(
'public://tmgmt_smartling_translations/JobID1_en_de.xml',
'public://tmgmt_smartling_translations/test_file_uri.xml',
$translate_job
)
->willReturn(FALSE);
......@@ -345,7 +345,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->apiWrapperMock->expects($this->once())
->method('createFirebaseRecord')
->with('tmgmt_smartling', 'notifications', 10, [
"message" => 'Translation for "public://tmgmt_smartling_translations/JobID1_en_de.xml" (job id = 1) was successfully downloaded but validation failed. See logs for more info.',
"message" => 'Translation for "public://tmgmt_smartling_translations/test_file_uri.xml" (job id = 1) was successfully downloaded but validation failed. See logs for more info.',
"type" => "error",
]);
......@@ -357,7 +357,7 @@ class DownloadFlowTest extends SmartlingTestBase {
*/
public function testDownloadFailFlowImportFailed() {
$exception = new \Exception("Test");
$translation_request = ['translationRequestUid' => 'test'];
$translation_request = ['translationRequestUid' => 'test', 'fileUri' => 'test_file_uri.xml'];
$translate_job = $this->createJobWithItems([
'batch_uid' => 'uid',
'batch_execute_on_job' => 1,
......@@ -385,7 +385,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->fileApiMock->expects($this->once())
->method('downloadFile')
->with(
'JobID1_en_de.xml',
'test_file_uri.xml',
'de',
$this->callback(function($subject) {
$params = $subject->exportToArray();
......@@ -398,7 +398,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->pluginMock->expects($this->once())
->method('validateImport')
->with(
'public://tmgmt_smartling_translations/JobID1_en_de.xml',
'public://tmgmt_smartling_translations/test_file_uri.xml',
$translate_job
)
->willReturn(TRUE);
......@@ -406,7 +406,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->pluginMock->expects($this->once())
->method('import')
->with(
'public://tmgmt_smartling_translations/JobID1_en_de.xml',
'public://tmgmt_smartling_translations/test_file_uri.xml',
$translate_job
)
->will($this->throwException($exception));
......@@ -421,7 +421,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->apiWrapperMock->expects($this->once())
->method('createFirebaseRecord')
->with('tmgmt_smartling', 'notifications', 10, [
"message" => 'Translation for "public://tmgmt_smartling_translations/JobID1_en_de.xml" (job id = 1) was successfully downloaded but import failed. See logs for more info.',
"message" => 'Translation for "public://tmgmt_smartling_translations/test_file_uri.xml" (job id = 1) was successfully downloaded but import failed. See logs for more info.',
"type" => "error",
]);
......@@ -576,7 +576,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->translationRequestManagerMock->expects($this->once())
->method('getTranslationRequest')
->with($translate_job)
->willReturn(['translationRequestUid' => 'test']);
->willReturn(['translationRequestUid' => 'test', 'fileUri' => 'test_file_uri.xml']);
$this->apiWrapperMock->expects($this->once())
->method('getApi')
......@@ -586,7 +586,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->fileApiMock->expects($this->once())
->method('downloadFile')
->with(
'JobID1_en_de.public',
'test_file_uri.xml',
'de',
$this->callback(function($subject) {
$params = $subject->exportToArray();
......@@ -599,7 +599,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->pluginMock->expects($this->once())
->method('validateImport')
->with(
'public://tmgmt_smartling_translations/JobID1_en_de.public',
'public://tmgmt_smartling_translations/test_file_uri.xml',
$translate_job
)
->willReturn(TRUE);
......@@ -607,7 +607,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->pluginMock->expects($this->once())
->method('import')
->with(
'public://tmgmt_smartling_translations/JobID1_en_de.public',
'public://tmgmt_smartling_translations/test_file_uri.xml',
$translate_job
)
->willReturn([
......@@ -771,7 +771,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->translationRequestManagerMock->expects($this->once())
->method('getTranslationRequest')
->with($translate_job)
->willReturn(['translationRequestUid' => 'test']);
->willReturn(['translationRequestUid' => 'test', 'fileUri' => 'test_file_uri.xml']);
$this->apiWrapperMock->expects($this->once())
->method('getApi')
......@@ -781,7 +781,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->fileApiMock->expects($this->once())
->method('downloadFile')
->with(
'JobID1_en_de.public',
'test_file_uri.xml',
'de',
$this->callback(function($subject) {
$params = $subject->exportToArray();
......@@ -794,7 +794,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->pluginMock->expects($this->once())
->method('validateImport')
->with(
'public://tmgmt_smartling_translations/JobID1_en_de.public',
'public://tmgmt_smartling_translations/test_file_uri.xml',
$translate_job
)
->willReturn(TRUE);
......@@ -802,7 +802,7 @@ class DownloadFlowTest extends SmartlingTestBase {
$this->pluginMock->expects($this->once())
->method('import')
->with(
'public://tmgmt_smartling_translations/JobID1_en_de.public',
'public://tmgmt_smartling_translations/test_file_uri.xml',
$translate_job
)
->willReturn([
......
......@@ -235,7 +235,6 @@ class TranslationRequestManagerTest extends SmartlingTestBase {
$search_params = new SearchTranslationRequestParams();
$search_params->setOriginalAssetKey($asset_key);
$search_params->setTargetAssetKey($asset_key);
$search_params->setFileUri($this->job->getTranslatorPlugin()->getFileName($this->job));
$search_params->setTargetLocaleId($this->job->getRemoteTargetLanguage());
$translation_request_manager_mock = $this
......
......@@ -158,7 +158,7 @@ function tmgmt_smartling_download_file(JobInterface $job, JobItemInterface $pass
try {
$smartling_api = $api_wrapper->getApi('file');
$retrieval_type = $job->getTranslator()->getSetting('retrieval_type');
$filename = $job->getTranslatorPlugin()->getFileName($job);
$filename = $translation_request["fileUri"];
$download_parameters = new DownloadFileParameters();
$download_parameters->set('retrievalType', $retrieval_type);
$extension = pathinfo($filename, PATHINFO_EXTENSION);
......@@ -169,7 +169,7 @@ function tmgmt_smartling_download_file(JobInterface $job, JobItemInterface $pass
$api_wrapper->createFirebaseRecord("tmgmt_smartling", "notifications", 10, [
"message" => t('File @name (job id = @job_id) wasn\'t downloaded. Please see logs for more info.', [
'@name' => $job->getTranslatorPlugin()->getFileName($job),
'@name' => $filename,
'@job_id' => $job->id(),
])->render(),
"type" => "error",
......@@ -180,7 +180,7 @@ function tmgmt_smartling_download_file(JobInterface $job, JobItemInterface $pass
return FALSE;
}
$path = $job->getSetting('scheme') . '://tmgmt_smartling_translations/' . $job->getTranslatorPlugin()->getFileName($job);
$path = $job->getSetting('scheme') . '://tmgmt_smartling_translations/' . $filename;
$dirname = dirname($path);
if (\Drupal::service('file_system')->prepareDirectory($dirname, FileSystemInterface::CREATE_DIRECTORY) && ($file = file_save_data($xml, $path, FileSystemInterface::EXISTS_REPLACE))) {
......
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