class ContextUpload in TMGMT Translator Smartling 8.4
Same name and namespace in other branches
- 8 src/Plugin/QueueWorker/ContextUpload.php \Drupal\tmgmt_smartling\Plugin\QueueWorker\ContextUpload
- 8.2 src/Plugin/QueueWorker/ContextUpload.php \Drupal\tmgmt_smartling\Plugin\QueueWorker\ContextUpload
- 8.3 src/Plugin/QueueWorker/ContextUpload.php \Drupal\tmgmt_smartling\Plugin\QueueWorker\ContextUpload
Executes interface translation queue tasks.
Plugin annotation
@QueueWorker(
id = "smartling_context_upload",
title = @Translation("Upload context"),
cron = {"time" = 30}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
- class \Drupal\tmgmt_smartling\Plugin\QueueWorker\ContextUpload implements ContainerFactoryPluginInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
Expanded class hierarchy of ContextUpload
File
- src/
Plugin/ QueueWorker/ ContextUpload.php, line 22
Namespace
Drupal\tmgmt_smartling\Plugin\QueueWorkerView source
class ContextUpload extends QueueWorkerBase implements ContainerFactoryPluginInterface {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $contextUploader;
/**
* The queue object.
*
* @var \Drupal\Core\Queue\QueueInterface
*/
protected $queue;
/**
* @var LoggerInterface
*/
protected $logger;
/**
* @var \Drupal\Core\Config\Config
*/
protected $config;
/**
* Constructs a new LocaleTranslation object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\tmgmt_smartling\Context\ContextUploader $context_uploader
* The module handler.
* @param \Drupal\Core\Queue\QueueInterface $queue
* The queue object.
* @param \Drupal\Core\Config\ConfigFactory $config_factory
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, ContextUploader $context_uploader, QueueInterface $queue, LoggerInterface $logger, ConfigFactory $config_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->contextUploader = $context_uploader;
$this->queue = $queue;
$this->logger = $logger;
$this->config = $config_factory
->get('tmgmt.translator.smartling');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('tmgmt_smartling.utils.context.uploader'), $container
->get('queue')
->get('smartling_context_upload', TRUE), $container
->get('logger.channel.smartling'), $container
->get('config.factory'));
}
/**
* {@inheritdoc}
*/
public function processItem($data) {
if (!$data['job_id']) {
return;
}
$job_id = $data['job_id'];
$url = $data['url'];
$filename = $data['filename'];
$job = \Drupal::entityTypeManager()
->getStorage('tmgmt_job')
->load($job_id);
//$date = $data['upload_date'];
if ($job && $job
->hasTranslator()) {
$settings = $job
->getTranslator()
->getSettings();
}
else {
$this->logger
->warning("Job with ID=@id has no translator plugin.", [
'@id' => $job_id,
]);
return;
}
// Method 'isReadyAcceptContext' will return FALSE in case there is no
// some/all required credentials. In this case we will re-add item into the
// queue. We have to prevent this because we need to re-add item only in
// case when Smartling is still processing uploaded file and isn't ready to
// accept the context. This is the corner case which is rarely reproducable.
if (empty($settings['user_id']) || empty($settings['project_id']) || empty($settings['token_secret'])) {
$this->logger
->warning('Skipping uploading context for the job with id = @id because credentials are not correct.', [
'@id' => $job_id,
]);
return;
}
if (!$this->contextUploader
->isReadyAcceptContext($filename, $settings)) {
$data['counter'] = isset($data['counter']) ? $data['counter'] + 1 : 1;
$this->queue
->createItem($data);
return;
}
try {
$this->contextUploader
->upload($url, $filename, $settings);
} catch (\Exception $e) {
$this->logger
->error($e
->getMessage());
return [];
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContextUpload:: |
protected | property | ||
ContextUpload:: |
protected | property | The module handler. | |
ContextUpload:: |
protected | property | ||
ContextUpload:: |
protected | property | The queue object. | |
ContextUpload:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
ContextUpload:: |
public | function |
Works on a single queue item. Overrides QueueWorkerInterface:: |
|
ContextUpload:: |
public | function |
Constructs a new LocaleTranslation object. Overrides PluginBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. |