You are here

function message_ui_delete_multiple_messages_submit in Message UI 7

Submit handler - delete the messages.

File

./message_ui.module, line 864
Main file for the message UI module.

Code

function message_ui_delete_multiple_messages_submit($form, $form_state) {

  // Get the message IDs.
  $query = new entityFieldQuery();
  $result = $query
    ->entityCondition('entity_type', 'message')
    ->propertyCondition('type', $form_state['values']['types'], 'IN')
    ->execute();
  if (empty($result['message'])) {

    // No messages found, return.
    drupal_set_message(t('No messages were found according to the parameters you entered'), 'error');
    return;
  }

  // Prepare the message IDs chunk array for batch operation.
  $chunks = array_chunk(array_keys($result['message']), 100);
  $operations = array();
  foreach ($chunks as $chunk) {
    $operations[] = array(
      'message_delete_multiple',
      array(
        $chunk,
      ),
    );
  }

  // Set the batch.
  $batch = array(
    'operations' => $operations,
    'title' => t('deleting messages.'),
    'init_message' => t('Starting to delete messages.'),
    'progress_message' => t('Processed @current out of @total.'),
    'error_message' => t('The batch operation has failed.'),
  );
  batch_set($batch);
  batch_process($_GET['q']);
}