Skip to content
Snippets Groups Projects

Issue #3337086 by taraskorpach: Fixed passed items to the queue

3 files
+ 119
41
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -2,7 +2,11 @@
namespace Drupal\commerce_stock_notifications\Plugin\QueueWorker;
use Drupal\commerce_stock_notifications\Entity\StockNotificationInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Sends out notifications when items are in stock.
@@ -13,13 +17,53 @@ use Drupal\Core\Queue\QueueWorkerBase;
* cron = {"time" = 240}
* )
*/
class CommerceStockNotificationPurgeQueue extends QueueWorkerBase {
class CommerceStockNotificationPurgeQueue extends QueueWorkerBase implements ContainerFactoryPluginInterface {
/**
* The notification storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $notificationStorage;
/**
* Constructs a new CommerceStockNotificationPurgeQueue object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The pluginId for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->notificationStorage = $entity_type_manager->getStorage('commerce_stock_notification');
}
/**
* {@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) {
$data->delete();
$notification = $this->notificationStorage->load($data);
if ($notification instanceof StockNotificationInterface) {
$notification->delete();
}
}
}
Loading