You are here

class ContextUpload in TMGMT Translator Smartling 8.2

Same name and namespace in other branches
  1. 8.4 src/Plugin/QueueWorker/ContextUpload.php \Drupal\tmgmt_smartling\Plugin\QueueWorker\ContextUpload
  2. 8 src/Plugin/QueueWorker/ContextUpload.php \Drupal\tmgmt_smartling\Plugin\QueueWorker\ContextUpload
  3. 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

Expanded class hierarchy of ContextUpload

File

src/Plugin/QueueWorker/ContextUpload.php, line 22

Namespace

Drupal\tmgmt_smartling\Plugin\QueueWorker
View 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;
    }
    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

Namesort descending Modifiers Type Description Overrides
ContextUpload::$config protected property
ContextUpload::$contextUploader protected property The module handler.
ContextUpload::$logger protected property
ContextUpload::$queue protected property The queue object.
ContextUpload::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
ContextUpload::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
ContextUpload::__construct public function Constructs a new LocaleTranslation object. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.