You are here

function queue_ui_overview_submit in Queue UI 6

Same name and namespace in other branches
  1. 7.2 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 109
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 queues using our hook_queue_info() that define batch.
      $defined_queues = queue_ui_defined_queues();
      $intersect = array_intersect(array_keys($defined_queues), $queues);
      foreach ($intersect as $name) {

        // Only if queue_info implementation defined batch can we set it here.
        if (isset($defined_queues[$name]['batch'])) {
          $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);
        }
      }
      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;
}