You are here

class LingotekDownloaderQueueWorker in Lingotek Translation 3.2.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/QueueWorker/LingotekDownloaderQueueWorker.php \Drupal\lingotek\Plugin\QueueWorker\LingotekDownloaderQueueWorker
  2. 4.0.x src/Plugin/QueueWorker/LingotekDownloaderQueueWorker.php \Drupal\lingotek\Plugin\QueueWorker\LingotekDownloaderQueueWorker
  3. 3.0.x src/Plugin/QueueWorker/LingotekDownloaderQueueWorker.php \Drupal\lingotek\Plugin\QueueWorker\LingotekDownloaderQueueWorker
  4. 3.1.x src/Plugin/QueueWorker/LingotekDownloaderQueueWorker.php \Drupal\lingotek\Plugin\QueueWorker\LingotekDownloaderQueueWorker
  5. 3.3.x src/Plugin/QueueWorker/LingotekDownloaderQueueWorker.php \Drupal\lingotek\Plugin\QueueWorker\LingotekDownloaderQueueWorker
  6. 3.4.x src/Plugin/QueueWorker/LingotekDownloaderQueueWorker.php \Drupal\lingotek\Plugin\QueueWorker\LingotekDownloaderQueueWorker
  7. 3.5.x src/Plugin/QueueWorker/LingotekDownloaderQueueWorker.php \Drupal\lingotek\Plugin\QueueWorker\LingotekDownloaderQueueWorker
  8. 3.6.x src/Plugin/QueueWorker/LingotekDownloaderQueueWorker.php \Drupal\lingotek\Plugin\QueueWorker\LingotekDownloaderQueueWorker
  9. 3.7.x src/Plugin/QueueWorker/LingotekDownloaderQueueWorker.php \Drupal\lingotek\Plugin\QueueWorker\LingotekDownloaderQueueWorker
  10. 3.8.x src/Plugin/QueueWorker/LingotekDownloaderQueueWorker.php \Drupal\lingotek\Plugin\QueueWorker\LingotekDownloaderQueueWorker

Provides base functionality for the Lingotek Queue Workers.

Plugin annotation


@QueueWorker(
  id = "lingotek_downloader_queue_worker",
  title = @Translation("Lingotek Download Queue"),
  cron = {"time" = 60}
)

Hierarchy

Expanded class hierarchy of LingotekDownloaderQueueWorker

1 file declares its use of LingotekDownloaderQueueWorker
LingotekQueueWorkerTest.php in tests/src/Unit/LingotekQueueWorkerTest.php

File

src/Plugin/QueueWorker/LingotekDownloaderQueueWorker.php, line 20

Namespace

Drupal\lingotek\Plugin\QueueWorker
View source
class LingotekDownloaderQueueWorker extends QueueWorkerBase {

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    $locale = $data['locale'];
    $entity_type_id = $data['entity_type_id'];
    $entity_id = $data['entity_id'];
    $document_id = $data['document_id'];
    $entity = \Drupal::entityTypeManager()
      ->getStorage($entity_type_id)
      ->load($entity_id);
    if ($entity instanceof ConfigEntityInterface) {

      /** @var \Drupal\lingotek\LingotekConfigTranslationServiceInterface $translation_service */
      $translation_service = \Drupal::service('lingotek.config_translation');
    }
    elseif ($entity instanceof ContentEntityInterface) {

      /** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
      $translation_service = \Drupal::service('lingotek.content_translation');
    }
    if (empty($translation_service)) {
      $message = new FormattableMarkup('Can not download - entity (@instance) is not supported instance of a class', [
        '@instance' => gettype($entity),
      ]);
      \Drupal::logger('lingotek')
        ->error($message);
      throw new \Exception($message);
    }
    $translation_service
      ->setTargetStatus($entity, $locale, Lingotek::STATUS_READY);
    $download = $translation_service
      ->downloadDocument($entity, $locale);
    if ($download === FALSE || $download === NULL) {
      $message = new FormattableMarkup('No download for target @locale happened in document @document on @entity @bundle @id.', [
        '@locale' => $locale,
        '@document' => $document_id,
        '@entity' => $entity
          ->label(),
        '@id' => $entity
          ->id(),
        '@bundle' => $entity
          ->bundle(),
      ]);
      \Drupal::logger('lingotek')
        ->error($message);
      throw new \Exception($message);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LingotekDownloaderQueueWorker::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
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 2
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.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 98