Commit 9214e4a6 authored by Loparev's avatar Loparev
Browse files

Handle daily bucket jobs per provider

parent e71f75c6
......@@ -8,10 +8,9 @@
namespace Drupal\tmgmt_smartling\Smartling;
use Drupal;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\tmgmt\Entity\Translator;
use Drupal\tmgmt_extension_suit\Utils\UniqueQueueItem;
use Drupal\tmgmt_smartling\Smartling\ConfigManager\SmartlingConfigManager;
use Psr\Log\LoggerInterface;
use Smartling\Jobs\JobStatus;
......@@ -50,31 +49,19 @@ class BucketJobManager {
*
* @param \Psr\Log\LoggerInterface $logger
* @param \Drupal\tmgmt_smartling\Smartling\SmartlingApiWrapper $api_wrapper
* @param \Drupal\tmgmt_smartling\Smartling\ConfigManager\SmartlingConfigManager $config_manager
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* @param \Drupal\tmgmt_extension_suit\Utils\UniqueQueueItem $unique_queue_item_util
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
*/
public function __construct(
LoggerInterface $logger,
SmartlingApiWrapper $api_wrapper,
SmartlingConfigManager $config_manager,
ModuleHandlerInterface $module_handler,
UniqueQueueItem $unique_queue_item_util,
ConfigFactoryInterface $config_factory
UniqueQueueItem $unique_queue_item_util
) {
$this->logger = $logger;
$this->apiWrapper = $api_wrapper;
$this->moduleHandler = $module_handler;
$this->uniqueQueueItemUtil = $unique_queue_item_util;
// Pick up first available Smartling provider settings.
$smartling_provider = $config_manager->getAvailableConfigs();
if (!empty($smartling_provider)) {
$this->settings = $smartling_provider[0]->get('settings');
$this->apiWrapper->setSettings($this->settings);
}
}
/**
......@@ -91,10 +78,14 @@ class BucketJobManager {
/**
* @param array $jobs
* @param Translator $translator
*
* @return array
*/
public function handle(array $jobs) {
public function handle(array $jobs, Translator $translator) {
$this->settings = $translator->getSettings();
$this->apiWrapper->setSettings($this->settings);
$job_uid = NULL;
$job_name = $this->getName();
$response = $this->apiWrapper->listJobs($job_name, [
......
......@@ -7,5 +7,5 @@ type: module
dependencies:
- tmgmt:tmgmt (>=8.x-1.11)
- tmgmt:tmgmt_file
- tmgmt_extension_suit:tmgmt_extension_suit (>=8.x-3.3)
- tmgmt_extension_suit:tmgmt_extension_suit (>=8.x-3.4)
- drupal:serialization
......@@ -12,7 +12,6 @@ use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
use Drupal\tmgmt\Entity\Job;
use Drupal\tmgmt\Entity\Translator;
......@@ -854,12 +853,21 @@ function tmgmt_smartling_add_to_job_form_submit(array $settings, Translator $tra
/**
* Implements hook_tmgmt_extension_suit_updated_entity_jobs().
*/
function tmgmt_smartling_tmgmt_extension_suit_updated_entity_jobs(array $job_ids) {
function tmgmt_smartling_tmgmt_extension_suit_updated_entity_jobs(array $job_ids, $translator_id) {
$jobs = Job::loadMultiple($job_ids);
$translator = Translator::load($translator_id);
foreach ($jobs as $job) {
$translator_plugin = $job->getTranslatorPlugin();
if (empty($translator) || empty($jobs)) {
return [];
}
$translator_plugin = $translator->getPlugin();
if (empty($translator_plugin) || $translator_plugin->getPluginId() !== 'smartling') {
return [];
}
foreach ($jobs as $job) {
if ($translator_plugin instanceof ExtendedTranslatorPluginInterface) {
Drupal::getContainer()
->get('logger.channel.smartling')
......@@ -870,7 +878,10 @@ function tmgmt_smartling_tmgmt_extension_suit_updated_entity_jobs(array $job_ids
}
}
return Drupal::service('tmgmt_smartling.bucket_job_manager')->handle(Job::loadMultiple($job_ids));
return Drupal::service('tmgmt_smartling.bucket_job_manager')->handle(
$jobs,
$translator
);
}
/**
......
......@@ -58,7 +58,7 @@ services:
tmgmt_smartling.bucket_job_manager:
class: \Drupal\tmgmt_smartling\Smartling\BucketJobManager
arguments: ['@logger.channel.smartling', '@tmgmt_smartling.smartling_api_wrapper', '@tmgmt_smartling.smartling_config_manager', '@module_handler', '@tmgmt_extension_suit.utils.queue_unique_item', '@config.factory']
arguments: ['@logger.channel.smartling', '@tmgmt_smartling.smartling_api_wrapper', '@module_handler', '@tmgmt_extension_suit.utils.queue_unique_item']
tmgmt_smartling.smartling_config_manager:
class: \Drupal\tmgmt_smartling\Smartling\ConfigManager\SmartlingConfigManager
......
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