Commit d286a599 authored by Loparev's avatar Loparev
Browse files

Introduced "Download by job item" option

parent 204aaa0e
......@@ -29,6 +29,7 @@ settings:
enable_notifications: true
async_mode: false
enable_basic_auth: false
download_by_job_items: false
basic_auth:
login: ''
password: ''
......@@ -61,6 +61,9 @@ tmgmt.translator.settings.smartling:
enable_basic_auth:
type: boolean
label: 'Enable basic auth for context'
download_by_job_items:
type: boolean
label: 'Download and apply translations per job item'
basic_auth:
type: mapping
label: 'Basic auth'
......
......@@ -652,6 +652,7 @@ class SmartlingTranslator extends TranslatorPluginBase implements
'enable_notifications' => TRUE,
'async_mode' => FALSE,
'enable_basic_auth' => FALSE,
'download_by_job_items' => FALSE,
'basic_auth' => [
'login' => '',
'password' => '',
......
......@@ -249,6 +249,13 @@ class SmartlingTranslatorUi extends TranslatorPluginUiBase {
],
];
$form['download_by_job_items'] = [
'#type' => 'checkbox',
'#title' => t('Download and apply translations per job item'),
'#description' => t('Only enable <b>if you experience download execution timeout issues</b>.'),
'#default_value' => $translator->getSetting('download_by_job_items'),
];
// Cron & queues table.
$form['cron_and_queues'] = [
'#type' => 'details',
......
......@@ -173,6 +173,7 @@ abstract class SmartlingTestBase extends TMGMTTestBase {
'translatable_attributes' => $providerSettings['settings[translatable_attributes]'],
'enable_smartling_logging' => $providerSettings['settings[enable_smartling_logging]'],
'enable_notifications' => $providerSettings['settings[enable_notifications]'],
'download_by_job_items' => $providerSettings['settings[download_by_job_items]']
],
]);
......
......@@ -48,7 +48,8 @@ function tmgmt_smartling_cron() {
foreach ($smartling_provider_configs as $smartling_provider_config) {
$api_wrapper = \Drupal::getContainer()->get("tmgmt_smartling.smartling_api_wrapper");
$api_wrapper->setSettings($smartling_provider_config->get("settings"));
$settings = $smartling_provider_config->get("settings");
$api_wrapper->setSettings($settings);
$search_params = new SearchTranslationRequestParams();
$search_params->setState(TranslationSubmissionStates::STATE_TRANSLATED);
......@@ -94,12 +95,22 @@ function tmgmt_smartling_cron() {
continue;
}
foreach ($job->getItems() as $item) {
if ($settings['download_by_job_items']) {
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(),
]
);
}
}
else {
Drupal::service('tmgmt_extension_suit.utils.queue_unique_item')
->addItem(
'tmgmt_extension_suit_download', [
'tjid' => $tmgmt_job_id,
'tjiid' => $item->id(),
'id' => $tmgmt_job_id,
]
);
}
......@@ -230,6 +241,12 @@ function tmgmt_smartling_download_file(JobInterface $job, JobItemInterface $pass
// No translation found.
$force_import[$job_item->id()] = $job_item;
}
// Force import in case connector works in "download by job item"
// mode.
if (!empty($passed_job_item)) {
$force_import[$passed_job_item->id()] = $passed_job_item;
}
}
// Compare old and new hashes in order to decide should we apply
......
......@@ -23,6 +23,7 @@ $settings = [
'settings[enable_notifications]' => TRUE,
'settings[async_mode]' => FALSE,
'settings[enable_basic_auth]' => FALSE,
'settings[download_by_job_items]' => FALSE,
'settings[basic_auth][login]' => '',
'settings[basic_auth][password]' => '',
];
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