Commit 651a9eb9 authored by Loparev's avatar Loparev
Browse files

Download and apply translations by job items in order to decrease execution time

parent 30201dff
......@@ -14,6 +14,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Url;
use Drupal\file\FileUsage\DatabaseFileUsageBackend;
use Drupal\tmgmt\JobItemInterface;
use Drupal\tmgmt\Translator\TranslatableResult;
use Drupal\tmgmt\TranslatorPluginBase;
use Drupal\tmgmt\TranslatorInterface;
......@@ -694,14 +695,12 @@ class SmartlingTranslator extends TranslatorPluginBase implements
}
/**
* Downloads translation file and applies it.
*
* @param \Drupal\tmgmt\JobInterface $job
*
* @param JobInterface $job
* @param JobItemInterface|NULL $jobItem
* @return bool
*/
public function downloadTranslation(JobInterface $job) {
return tmgmt_smartling_download_file($job);
public function downloadTranslation(JobInterface $job, JobItemInterface $jobItem = NULL) {
return tmgmt_smartling_download_file($job, $jobItem);
}
/**
......
......@@ -94,17 +94,20 @@ function tmgmt_smartling_cron() {
continue;
}
Drupal::service('tmgmt_extension_suit.utils.queue_unique_item')
->addItem(
'tmgmt_extension_suit_download', [
'id' => $tmgmt_job_id,
]
);
foreach ($job->getItems() as $item) {
Drupal::service('tmgmt_extension_suit.utils.queue_unique_item')
->addItem(
'tmgmt_extension_suit_download', [
'tjid' => $tmgmt_job_id,
'tjiid' => $item->id(),
]
);
}
}
}
}
function tmgmt_smartling_download_file(JobInterface $job) {
function tmgmt_smartling_download_file(JobInterface $job, JobItemInterface $passed_job_item = NULL) {
$api_wrapper = $job->getTranslatorPlugin()->getApiWrapper($job->getTranslator()->getSettings());
$translation_request_manager = Drupal::service('tmgmt_smartling.translation_request_manager');
$logger = \Drupal::logger('tmgmt_smartling');
......@@ -204,6 +207,10 @@ function tmgmt_smartling_download_file(JobInterface $job) {
$entity_type_manager = \Drupal::entityTypeManager();
foreach ($job_items as $job_item) {
if (!empty($passed_job_item) && $job_item->id() != $passed_job_item->id()) {
continue;
}
// Load target translation. Save job item id if it
// doesn't have target translation.
try {
......@@ -235,6 +242,10 @@ function tmgmt_smartling_download_file(JobInterface $job) {
// Validation successful, start import.
foreach ($plugin->import($file->getFileUri(), $job) as $key => $value) {
if (isset($job_items[$key])) {
if (!empty($passed_job_item) && $job_items[$key]->id() != $passed_job_item->id()) {
continue;
}
if ($old_hash !== $hash || isset($force_import[$key])) {
// Set active state for the job item in order to be able
// force translation. It allows to override existing
......
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