Loading queue_ui.drush.inc +55 −43 Original line number Diff line number Diff line <?php /** * @file * Provide Drush command for queue_ui module. */ /** * Implements hook_drush_command(). */ Loading Loading @@ -33,107 +38,114 @@ function queue_ui_drush_command() { } /** * Process queue * Process queue. * * @param string $queue_name * @param string $queueName * The name of the queue being inspected. */ function drush_queue_ui_queue_process($queue_name = NULL) { // Require the choice name to be filled if ($queue_name = _queue_ui_queue_choice($queue_name)) { // Add operations and start to batch process function drush_queue_ui_queue_process($queueName = NULL) { // Require the choice name to be filled. if ($queueName = _queue_ui_queue_choice($queueName)) { // Add operations and start to batch process. _queue_ui_start_batch([ ['\Drupal\queue_ui\QueueUIBatch::step', [$queue_name]] ['\Drupal\queue_ui\QueueUIBatch::step', [$queueName]], ]); } } /** * Process all queues * Process all queues. */ function drush_queue_ui_queue_process_all() { $operations = []; $queues = \Drupal::service('plugin.manager.queue_worker')->getDefinitions(); // Add operations for each queue foreach ($queues as $queue_name => $queue_definition) { $operations[] = ['\Drupal\queue_ui\QueueUIBatch::step', [$queue_name]]; // Add operations for each queue. foreach ($queues as $queueName => $queue_definition) { $operations[] = ['\Drupal\queue_ui\QueueUIBatch::step', [$queueName]]; } // Start batch process // Start batch process. _queue_ui_start_batch($operations); } /** * Remove lease from queue * Remove lease from queue. * * @param string $queue_name * @param string $queueName * The name of the queue being inspected. */ function drush_queue_ui_queue_release($queue_name = NULL) { // Require the choice name to be filled if ($queue_name = _queue_ui_queue_choice($queue_name)) { _queue_ui_release_queue($queue_name); function drush_queue_ui_queue_release($queueName = NULL) { // Require the choice name to be filled. if ($queueName = _queue_ui_queue_choice($queueName)) { _queue_ui_release_queue($queueName); } } /** * Remove lease from all queues * Remove lease from all queues. */ function drush_queue_ui_queue_release_all() { $queues = \Drupal::service('plugin.manager.queue_worker')->getDefinitions(); // Release each queue foreach ($queues as $queue_name => $queue_definition) { _queue_ui_release_queue($queue_name); // Release each queue. foreach ($queues as $queueName => $queue_definition) { _queue_ui_release_queue($queueName); } } /** * Remove leases from all items in a queue * Remove leases from all items in a queue. * * @param $queue_name * @param string $queueName * The name of the queue being inspected. */ function _queue_ui_release_queue($queue_name) { function _queue_ui_release_queue($queueName) { /** @var \Drupal\queue_ui\QueueUIInterface $queue_ui */ $queue_ui = \Drupal::service('plugin.manager.queue_ui')->fromQueueName($queue_name); $queue_ui = \Drupal::service('plugin.manager.queue_ui')->fromQueueName($queueName); // Remove leases $num_updated = $queue_ui->releaseItems($queue_name); // Remove leases. $num_updated = $queue_ui->releaseItems($queueName); drush_log(t('@count lease reset in queue @name', [ '@count' => $num_updated, '@name' => $queue_name '@name' => $queueName, ]), 'ok'); } /** * Give the user a choice prompt * Give the user a choice prompt. * * @param string $queueName * The name of the queue being inspected. * * @param $queue_name * @return mixed * A mixed value of queue name */ function _queue_ui_queue_choice($queue_name) { // Queue name is not provided if (empty($queue_name)) { // Get all defined queue names function _queue_ui_queue_choice($queueName) { // Queue name is not provided. if (empty($queueName)) { // Get all defined queue names. $defined_queues = \Drupal::service('plugin.manager.queue_worker')->getDefinitions(); $queue_names = array_map(function($queue) { // Render queue title $queueNames = array_map(function ($queue) { // Render queue title. return $queue['title']->render(); }, $defined_queues); // Show a list of all defined queues $queue_name = drush_choice($queue_names, t('Which queue do you want to process?')); // Show a list of all defined queues. $queueName = drush_choice($queueNames, t('Which queue do you want to process?')); } return $queue_name; return $queueName; } /** * Helper function to start a batch process * Helper function to start a batch process. * * @param $operations * @param array $operations * Contains the operations that needs to be processed. */ function _queue_ui_start_batch($operations) { function _queue_ui_start_batch(array $operations) { $batch = [ 'operations' => $operations, ]; Loading queue_ui.module +9 −4 Original line number Diff line number Diff line <?php /** * hook_queue_info_alter() * @file * Queue ui module file. */ /** * Hook_queue_info_alter() */ function queue_ui_queue_info_alter(&$queues) { foreach ($queues as $queue_name => $definition) { foreach ($queues as $queueName => $definition) { // Check if a time limit override exists for this queue. if ($time_limit = \Drupal::state()->get('queue_ui_cron_' . $queue_name)) { if ($time_limit = \Drupal::state()->get('queue_ui_cron_' . $queueName)) { // Override the original definition. $queues[$queue_name]['cron']['time'] = $time_limit; $queues[$queueName]['cron']['time'] = $time_limit; } } } queue_ui.routing.yml +4 −4 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ queue_ui.confirm_clear_form: _permission: 'admin queue_ui' queue_ui.inspect: path: admin/config/system/queue-ui/inspect/{queue_name} path: admin/config/system/queue-ui/inspect/{queueName} defaults: _form: '\Drupal\queue_ui\Form\InspectForm' _title: 'Inspect queue' Loading @@ -22,7 +22,7 @@ queue_ui.inspect: _permission: 'admin queue_ui' queue_ui.inspect.view: path: admin/config/system/queue-ui/{queue_name}/view/{queue_item} path: admin/config/system/queue-ui/{queueName}/view/{queueItem} defaults: _form: '\Drupal\queue_ui\Form\ItemDetailForm' _title: 'Queue item details' Loading @@ -30,14 +30,14 @@ queue_ui.inspect.view: _permission: 'admin queue_ui' queue_ui.inspect.release: path: admin/config/system/queue-ui/{queue_name}/release/{queue_item} path: admin/config/system/queue-ui/{queueName}/release/{queueItem} defaults: _form: '\Drupal\queue_ui\Form\ConfirmItemReleaseForm' requirements: _permission: 'admin queue_ui' queue_ui.inspect.delete: path: admin/config/system/queue-ui/{queue_name}/delete/{queue_item} path: admin/config/system/queue-ui/{queueName}/delete/{queueItem} defaults: _form: '\Drupal\queue_ui\Form\ConfirmItemDeleteForm' requirements: Loading queue_ui.services.yml +2 −1 Original line number Diff line number Diff line Loading @@ -2,3 +2,4 @@ services: plugin.manager.queue_ui: class: Drupal\queue_ui\QueueUIManager parent: default_plugin_manager arguments: ['@queue'] src/Annotation/QueueUI.php +4 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,8 @@ use Drupal\Component\Annotation\Plugin; /** * Defines a QueueUI annotation object. * Plugin Namespace: Plugin\QueueUI * * Plugin Namespace: Plugin\QueueUI. * * @Annotation */ Loading @@ -20,6 +21,8 @@ class QueueUI extends Plugin { public $id; /** * The class name. * * @var string */ public $class_name; Loading Loading
queue_ui.drush.inc +55 −43 Original line number Diff line number Diff line <?php /** * @file * Provide Drush command for queue_ui module. */ /** * Implements hook_drush_command(). */ Loading Loading @@ -33,107 +38,114 @@ function queue_ui_drush_command() { } /** * Process queue * Process queue. * * @param string $queue_name * @param string $queueName * The name of the queue being inspected. */ function drush_queue_ui_queue_process($queue_name = NULL) { // Require the choice name to be filled if ($queue_name = _queue_ui_queue_choice($queue_name)) { // Add operations and start to batch process function drush_queue_ui_queue_process($queueName = NULL) { // Require the choice name to be filled. if ($queueName = _queue_ui_queue_choice($queueName)) { // Add operations and start to batch process. _queue_ui_start_batch([ ['\Drupal\queue_ui\QueueUIBatch::step', [$queue_name]] ['\Drupal\queue_ui\QueueUIBatch::step', [$queueName]], ]); } } /** * Process all queues * Process all queues. */ function drush_queue_ui_queue_process_all() { $operations = []; $queues = \Drupal::service('plugin.manager.queue_worker')->getDefinitions(); // Add operations for each queue foreach ($queues as $queue_name => $queue_definition) { $operations[] = ['\Drupal\queue_ui\QueueUIBatch::step', [$queue_name]]; // Add operations for each queue. foreach ($queues as $queueName => $queue_definition) { $operations[] = ['\Drupal\queue_ui\QueueUIBatch::step', [$queueName]]; } // Start batch process // Start batch process. _queue_ui_start_batch($operations); } /** * Remove lease from queue * Remove lease from queue. * * @param string $queue_name * @param string $queueName * The name of the queue being inspected. */ function drush_queue_ui_queue_release($queue_name = NULL) { // Require the choice name to be filled if ($queue_name = _queue_ui_queue_choice($queue_name)) { _queue_ui_release_queue($queue_name); function drush_queue_ui_queue_release($queueName = NULL) { // Require the choice name to be filled. if ($queueName = _queue_ui_queue_choice($queueName)) { _queue_ui_release_queue($queueName); } } /** * Remove lease from all queues * Remove lease from all queues. */ function drush_queue_ui_queue_release_all() { $queues = \Drupal::service('plugin.manager.queue_worker')->getDefinitions(); // Release each queue foreach ($queues as $queue_name => $queue_definition) { _queue_ui_release_queue($queue_name); // Release each queue. foreach ($queues as $queueName => $queue_definition) { _queue_ui_release_queue($queueName); } } /** * Remove leases from all items in a queue * Remove leases from all items in a queue. * * @param $queue_name * @param string $queueName * The name of the queue being inspected. */ function _queue_ui_release_queue($queue_name) { function _queue_ui_release_queue($queueName) { /** @var \Drupal\queue_ui\QueueUIInterface $queue_ui */ $queue_ui = \Drupal::service('plugin.manager.queue_ui')->fromQueueName($queue_name); $queue_ui = \Drupal::service('plugin.manager.queue_ui')->fromQueueName($queueName); // Remove leases $num_updated = $queue_ui->releaseItems($queue_name); // Remove leases. $num_updated = $queue_ui->releaseItems($queueName); drush_log(t('@count lease reset in queue @name', [ '@count' => $num_updated, '@name' => $queue_name '@name' => $queueName, ]), 'ok'); } /** * Give the user a choice prompt * Give the user a choice prompt. * * @param string $queueName * The name of the queue being inspected. * * @param $queue_name * @return mixed * A mixed value of queue name */ function _queue_ui_queue_choice($queue_name) { // Queue name is not provided if (empty($queue_name)) { // Get all defined queue names function _queue_ui_queue_choice($queueName) { // Queue name is not provided. if (empty($queueName)) { // Get all defined queue names. $defined_queues = \Drupal::service('plugin.manager.queue_worker')->getDefinitions(); $queue_names = array_map(function($queue) { // Render queue title $queueNames = array_map(function ($queue) { // Render queue title. return $queue['title']->render(); }, $defined_queues); // Show a list of all defined queues $queue_name = drush_choice($queue_names, t('Which queue do you want to process?')); // Show a list of all defined queues. $queueName = drush_choice($queueNames, t('Which queue do you want to process?')); } return $queue_name; return $queueName; } /** * Helper function to start a batch process * Helper function to start a batch process. * * @param $operations * @param array $operations * Contains the operations that needs to be processed. */ function _queue_ui_start_batch($operations) { function _queue_ui_start_batch(array $operations) { $batch = [ 'operations' => $operations, ]; Loading
queue_ui.module +9 −4 Original line number Diff line number Diff line <?php /** * hook_queue_info_alter() * @file * Queue ui module file. */ /** * Hook_queue_info_alter() */ function queue_ui_queue_info_alter(&$queues) { foreach ($queues as $queue_name => $definition) { foreach ($queues as $queueName => $definition) { // Check if a time limit override exists for this queue. if ($time_limit = \Drupal::state()->get('queue_ui_cron_' . $queue_name)) { if ($time_limit = \Drupal::state()->get('queue_ui_cron_' . $queueName)) { // Override the original definition. $queues[$queue_name]['cron']['time'] = $time_limit; $queues[$queueName]['cron']['time'] = $time_limit; } } }
queue_ui.routing.yml +4 −4 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ queue_ui.confirm_clear_form: _permission: 'admin queue_ui' queue_ui.inspect: path: admin/config/system/queue-ui/inspect/{queue_name} path: admin/config/system/queue-ui/inspect/{queueName} defaults: _form: '\Drupal\queue_ui\Form\InspectForm' _title: 'Inspect queue' Loading @@ -22,7 +22,7 @@ queue_ui.inspect: _permission: 'admin queue_ui' queue_ui.inspect.view: path: admin/config/system/queue-ui/{queue_name}/view/{queue_item} path: admin/config/system/queue-ui/{queueName}/view/{queueItem} defaults: _form: '\Drupal\queue_ui\Form\ItemDetailForm' _title: 'Queue item details' Loading @@ -30,14 +30,14 @@ queue_ui.inspect.view: _permission: 'admin queue_ui' queue_ui.inspect.release: path: admin/config/system/queue-ui/{queue_name}/release/{queue_item} path: admin/config/system/queue-ui/{queueName}/release/{queueItem} defaults: _form: '\Drupal\queue_ui\Form\ConfirmItemReleaseForm' requirements: _permission: 'admin queue_ui' queue_ui.inspect.delete: path: admin/config/system/queue-ui/{queue_name}/delete/{queue_item} path: admin/config/system/queue-ui/{queueName}/delete/{queueItem} defaults: _form: '\Drupal\queue_ui\Form\ConfirmItemDeleteForm' requirements: Loading
queue_ui.services.yml +2 −1 Original line number Diff line number Diff line Loading @@ -2,3 +2,4 @@ services: plugin.manager.queue_ui: class: Drupal\queue_ui\QueueUIManager parent: default_plugin_manager arguments: ['@queue']
src/Annotation/QueueUI.php +4 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,8 @@ use Drupal\Component\Annotation\Plugin; /** * Defines a QueueUI annotation object. * Plugin Namespace: Plugin\QueueUI * * Plugin Namespace: Plugin\QueueUI. * * @Annotation */ Loading @@ -20,6 +21,8 @@ class QueueUI extends Plugin { public $id; /** * The class name. * * @var string */ public $class_name; Loading