summaryrefslogtreecommitdiffstats
path: root/core/modules/media/src/Plugin/QueueWorker/ThumbnailDownloader.php
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-05-19 12:57:59 (GMT)
committerNathaniel Catchpole2017-05-19 12:57:59 (GMT)
commit01621e5880b7e0efd335cb0bae243c25fc3b1c2e (patch)
tree28fcea3833aced2c323208dd9f1617ab1437f385 /core/modules/media/src/Plugin/QueueWorker/ThumbnailDownloader.php
parentf186fa6cf0c0618329028d5ced2c273279fa5095 (diff)
Issue #2831274 by slashrsm, seanB, Wim Leers, chr.fritsch, phenaproxima, naveenvalecha, marcoscano, webflo, Gábor Hojtsy, amateescu, Boobaa, iMiksu, mtodor, effulgentsia, xjm, Berdir, tim.plunkett, dawehner, tkoleary, tstoeckler, tedbow, alexpott, yoroy, catch, Bojhan, andypost, jhedstrom, jibran, aspilicious, boztek, cbr, bigbaldy, alex0412, dagmar, blueminds, ekes, Dave Reid, Sam152, bojanz, pixelmord, jonathanshaw, CTaPByK, webchick, samuel.mortenson, dbt102, dishabhadra, proweb.ua, rakesh.gectcr, rasikap, paranojik, pameeela, neardark, NormySan, Primsi, nicolas.rafaelli, romainj, royal121, vladan.me, vpeltot, woprrr, vilepickle, toni04, scheban, tduong, temkin, tim-e, mbovan, mashermike, felribeiro, giancarlosotelo, hctom, euphoric_mv, eric.duran7@gmail.com, edurenye, eelkeblok, H1ghlander, Jaesin, hkirsman, ja_ca, NickWilde, joachim, joshi.rohit100, marcingy, NerOcrO, Mixologic, jcisio, jfrederick, Lukas von Blarer, Maouna: Bring Media entity module to core as Media module
Diffstat (limited to 'core/modules/media/src/Plugin/QueueWorker/ThumbnailDownloader.php')
-rw-r--r--core/modules/media/src/Plugin/QueueWorker/ThumbnailDownloader.php68
1 files changed, 68 insertions, 0 deletions
diff --git a/core/modules/media/src/Plugin/QueueWorker/ThumbnailDownloader.php b/core/modules/media/src/Plugin/QueueWorker/ThumbnailDownloader.php
new file mode 100644
index 0000000..8ad8801
--- /dev/null
+++ b/core/modules/media/src/Plugin/QueueWorker/ThumbnailDownloader.php
@@ -0,0 +1,68 @@
+<?php
+
+namespace Drupal\media\Plugin\QueueWorker;
+
+use Drupal\Core\Entity\EntityTypeManagerInterface;
+use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
+use Drupal\Core\Queue\QueueWorkerBase;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Process a queue of media items to fetch their thumbnails.
+ *
+ * @QueueWorker(
+ * id = "media_entity_thumbnail",
+ * title = @Translation("Thumbnail downloader"),
+ * cron = {"time" = 60}
+ * )
+ */
+class ThumbnailDownloader extends QueueWorkerBase implements ContainerFactoryPluginInterface {
+
+ /**
+ * The entity type manager service.
+ *
+ * @var \Drupal\Core\Entity\EntityTypeManagerInterface
+ */
+ protected $entityTypeManager;
+
+ /**
+ * Constructs a new class instance.
+ *
+ * @param array $configuration
+ * A configuration array containing information about the plugin instance.
+ * @param string $plugin_id
+ * The plugin_id for the plugin instance.
+ * @param mixed $plugin_definition
+ * The plugin implementation definition.
+ * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
+ * Entity type manager service.
+ */
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
+ parent::__construct($configuration, $plugin_id, $plugin_definition);
+ $this->entityTypeManager = $entity_type_manager;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
+ return new static(
+ $configuration,
+ $plugin_id,
+ $plugin_definition,
+ $container->get('entity_type.manager')
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function processItem($data) {
+ /** @var \Drupal\media\Entity\Media $media */
+ if ($media = $this->entityTypeManager->getStorage('media')->load($data['id'])) {
+ $media->updateQueuedThumbnail();
+ $media->save();
+ }
+ }
+
+}