Skip to content
Snippets Groups Projects

Issue #3323520: Create a way to empty a queue

2 files
+ 40
2
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -5,6 +5,7 @@ namespace Drupal\advancedqueue\Commands;
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
use Drupal\advancedqueue\Job;
use Drupal\advancedqueue\ProcessorInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drush\Commands\DrushCommands;
@@ -28,6 +29,13 @@ class AdvancedQueueCommands extends DrushCommands {
*/
protected $processor;
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructs a new AdvancedQueueCommands object.
*
@@ -36,11 +44,12 @@ class AdvancedQueueCommands extends DrushCommands {
* @param \Drupal\advancedqueue\ProcessorInterface $processor
* The queue processor.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, ProcessorInterface $processor) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, ProcessorInterface $processor, Connection $connection) {
parent::__construct();
$this->entityTypeManager = $entity_type_manager;
$this->processor = $processor;
$this->connection = $connection;
}
/**
@@ -135,4 +144,33 @@ class AdvancedQueueCommands extends DrushCommands {
return new RowsOfFields($rows);
}
/**
* Clear a queue.
*
* @param string $queue_id
* The queue ID.
*
* @throws \Exception
*
* @command advancedqueue:queue:clear
* @usage advancedqueue:queue:clear commerce_recurring
*/
public function clear($queue_id) {
if ($this->io()->confirm(dt("Are you sure you want to remove queue items for the the @queue_id queue?", ['@queue_id' => $queue_id]))) {
$queue_storage = $this->entityTypeManager->getStorage('advancedqueue_queue');
/** @var \Drupal\advancedqueue\Entity\QueueInterface $queue */
$queue = $queue_storage->load($queue_id);
if (!$queue) {
throw new \Exception(dt('Could not find queue "@queue_id".', ['@queue_id' => $queue_id]));
}
$this->connection->delete('advancedqueue')
->condition('queue_id', $queue_id)
->execute();
$this->io()->success(dt('The queue items for the the @queue queue have been deleted.', [
'@queue' => $queue->label(),
]));
}
}
}
Loading