You are here

function queue_ui_overview_submit in Queue UI 7.2

Same name and namespace in other branches
  1. 6 queue_ui.pages.inc \queue_ui_overview_submit()
  2. 7 queue_ui.pages.inc \queue_ui_overview_submit()

Overview submit handler.

1 string reference to 'queue_ui_overview_submit'
queue_ui_overview_form in ./queue_ui.pages.inc

File

./queue_ui.pages.inc, line 151
queue_ui.pages.inc

Code

function queue_ui_overview_submit($form, &$form_state, $queues) {
  $values = $form_state['values'];

  // Switch off submitted action.
  switch ($values['op']) {
    case $values['cron']:

      // Set variables for cron to TRUE.
      $defined_queues = queue_ui_defined_queues();
      $intersect = array_intersect(array_keys($defined_queues), $queues);
      foreach ($intersect as $name) {
        if (isset($defined_queues[$name]['cron'])) {
          variable_set('queue_ui_cron_' . $name, TRUE);
        }
      }
      break;
    case $values['batch']:

      // Process queue(s) with batch.
      // We can only run batch on either queues using our hook_queue_info() that
      // define batch, or queues defined with hook_cron_queue_info().
      // Get the queues defined with hook_queue_info().
      $defined_queues = queue_ui_defined_queues();

      // Get the cron queues.
      $cron_queues = module_invoke_all('cron_queue_info');
      drupal_alter('cron_queue_info', $cron_queues);
      foreach ($queues as $name) {
        if (isset($defined_queues[$name])) {
          $batch = $defined_queues[$name]['batch'];

          // Add queue as argument to operations by resetting the operations array.
          $operations = array();
          $queue = DrupalQueue::get($name);
          foreach ($batch['operations'] as $operation) {

            // First element is the batch process callback, second is the argument.
            $operations[] = array(
              $operation[0],
              array_merge(array(
                $queue,
              ), $operation[1]),
            );
          }
          $batch['operations'] = $operations;

          // Set.
          batch_set($batch);
          continue;
        }
        if (isset($cron_queues[$name])) {
          $batch = array(
            'operations' => array(
              array(
                'queue_ui_cron_queue_batch_process',
                array(
                  $name,
                  $cron_queues[$name],
                ),
              ),
            ),
          );
          batch_set($batch);
          continue;
        }
      }
      break;
    case $values['delete']:

      // Confirm before deleting. Go multistep!
      $form_state['rebuild'] = TRUE;
      $form_state['storage']['queues'] = $queues;
      $form_state['storage']['step'] = 'queue_ui_confirm_delete';
      break;
    case $values['release']:
      foreach ($queues as $name) {
        $num_updated = db_update('queue')
          ->fields(array(
          'expire' => 0,
        ))
          ->condition('name', $name, '=')
          ->execute();
        drupal_set_message(t('!count lease reset in queue !name', array(
          '!count' => $num_updated,
          '!name' => $name,
        )));
      }
      break;
  }
  return;
}