You are here

class JobDownload in TMGMT Extension Suite 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/QueueWorker/JobDownload.php \Drupal\tmgmt_extension_suit\Plugin\QueueWorker\JobDownload
  2. 8.2 src/Plugin/QueueWorker/JobDownload.php \Drupal\tmgmt_extension_suit\Plugin\QueueWorker\JobDownload

Executes interface translation queue tasks.

Plugin annotation


@QueueWorker(
  id = "tmgmt_extension_suit_download",
  title = @Translation("Job translation download"),
  cron = {"time" = 30}
)

Hierarchy

Expanded class hierarchy of JobDownload

File

src/Plugin/QueueWorker/JobDownload.php, line 21

Namespace

Drupal\tmgmt_extension_suit\Plugin\QueueWorker
View source
class JobDownload extends QueueWorkerBase implements ContainerFactoryPluginInterface {

  /**
   * 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\Core\Queue\QueueInterface $queue
   *   The queue object.
   */
  public function __construct(array $configuration, $plugin_id, array $plugin_definition, QueueInterface $queue, LoggerInterface $logger) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->queue = $queue;
    $this->logger = $logger;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('queue')
      ->get('tmgmt_extension_suit_download', TRUE), $container
      ->get('logger.channel.tmgmt_extension_suit'));
  }

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    $id = $data['id'];
    try {
      $job = entity_load('tmgmt_job', $id);
      if (empty($job)) {
        $this->logger
          ->error(t('Downloading translation for a job :job_id is failed: non-existent job. This job has been deleted from admin UI but queue item is still in the queue.', [
          ':job_id' => $id,
        ]));
        return;
      }
      $plugin = $job
        ->getTranslator()
        ->getPlugin();
      if ($plugin instanceof ExtendedTranslatorPluginInterface && $plugin
        ->isReadyForDownload($job)) {
        $plugin
          ->downloadTranslation($job);
      }
    } catch (\Exception $e) {
      $this->logger
        ->error($e
        ->getMessage());
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JobDownload::$config protected property
JobDownload::$logger protected property
JobDownload::$queue protected property The queue object.
JobDownload::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
JobDownload::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
JobDownload::__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.