You are here

class BynderTestImageRemove in Bynder 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/QueueWorker/BynderTestImageRemove.php \Drupal\bynder\Plugin\QueueWorker\BynderTestImageRemove
  2. 8.2 src/Plugin/QueueWorker/BynderTestImageRemove.php \Drupal\bynder\Plugin\QueueWorker\BynderTestImageRemove
  3. 4.0.x src/Plugin/QueueWorker/BynderTestImageRemove.php \Drupal\bynder\Plugin\QueueWorker\BynderTestImageRemove

Removes uploaded test images.

Plugin annotation


@QueueWorker(
  id = "bynder_test_image_remove",
  title = @Translation("Bynder test image remove"),
  cron = {"time" = 60}
)

Hierarchy

Expanded class hierarchy of BynderTestImageRemove

File

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

Namespace

Drupal\bynder\Plugin\QueueWorker
View source
class BynderTestImageRemove extends QueueWorkerBase implements ContainerFactoryPluginInterface {

  /**
   * The minimum delay in seconds for items to wait until processed.
   *
   * @var int
   */
  const DELAY = 600;

  /**
   * Bynder api service.
   *
   * @var \Drupal\bynder\BynderApiInterface
   *   Bynder api service.
   */
  protected $bynder;

  /**
   * The time service.
   *
   * @var \Drupal\Component\Datetime\TimeInterface
   */
  protected $time;

  /**
   * BynderTestImageRemove constructor.
   *
   * @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\bynder\BynderApiInterface $bynder
   *   The Bynder API service.
   * @param \Drupal\Component\Datetime\TimeInterface $time
   *   The time service.
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  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'));
  }

  /**
   * {@inheritdoc}
   */
  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.');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BynderTestImageRemove::$bynder protected property Bynder api service.
BynderTestImageRemove::$time protected property The time service.
BynderTestImageRemove::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
BynderTestImageRemove::DELAY constant The minimum delay in seconds for items to wait until processed.
BynderTestImageRemove::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
BynderTestImageRemove::__construct public function BynderTestImageRemove constructor. 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.