BynderTestImageRemove.php in Bynder 8.2
File
src/Plugin/QueueWorker/BynderTestImageRemove.php
View source
<?php
namespace Drupal\bynder\Plugin\QueueWorker;
use Drupal\bynder\BynderApiInterface;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\Core\Queue\RequeueException;
use Symfony\Component\DependencyInjection\ContainerInterface;
class BynderTestImageRemove extends QueueWorkerBase implements ContainerFactoryPluginInterface {
const DELAY = 600;
protected $bynder;
protected $time;
public function __construct(array $configuration, $plugin_id, $plugin_definition, BynderApiInterface $bynder, TimeInterface $time) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->bynder = $bynder;
$this->time = $time;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('bynder_api'), $container
->get('datetime.time'));
}
public function processItem($data) {
if ($data['created'] + static::DELAY <= $this->time
->getRequestTime()) {
$this->bynder
->deleteMedia($data['mediaid']);
}
else {
throw new RequeueException('Minimum wait time has not passed for this item.');
}
}
}