You are here

function views_bulk_operations_execute in Views Bulk Operations (VBO) 6

Same name and namespace in other branches
  1. 6.3 views_bulk_operations.module \views_bulk_operations_execute()
  2. 7.3 views_bulk_operations.module \views_bulk_operations_execute()

API function to programmatically invoke a VBO.

2 calls to views_bulk_operations_execute()
drush_views_bulk_operations_execute in ./views_bulk_operations.drush.inc
Implementation of 'vbo-execute' command.
views_bulk_operations_action in ./views_bulk_operations.module
Execution function for views_bulk_operations_action action.

File

./views_bulk_operations.module, line 16
Allows operations to be performed on items selected in a view.

Code

function views_bulk_operations_execute($vid, $operation_callback, $operation_arguments = array(), $view_exposed_input = array(), $view_arguments = array(), $respect_limit = FALSE) {
  $view = views_get_view($vid);
  if (!is_object($view)) {
    watchdog('vbo', 'Could not find view %vid.', array(
      '%vid' => $vid,
    ), WATCHDOG_ERROR);
    return;
  }
  $vd = new views_bulk_operations_destructor($view);

  // this will take care of calling $view->destroy() on exit.
  // Find the view display that has the VBO style.
  $found = FALSE;
  foreach (array_keys($view->display) as $display) {
    $display_options =& $view->display[$display]->display_options;
    if (isset($display_options['style_plugin']) && $display_options['style_plugin'] == 'bulk') {
      $view
        ->set_display($display);
      $found = TRUE;
      break;
    }
  }
  if (!$found) {
    watchdog('vbo', 'Could not find a VBO display in view %vid.', array(
      '%vid' => $vid,
    ), WATCHDOG_ERROR);
    return;
  }

  // Execute the view.
  $view
    ->set_exposed_input($view_exposed_input);
  $view
    ->set_arguments($view_arguments);
  $view
    ->set_items_per_page($respect_limit ? $display_options['items_per_page'] : 0);
  $view
    ->execute();
  if (empty($view->result)) {
    watchdog('vbo', 'No results for view %vid.', array(
      '%vid' => $vid,
    ), WATCHDOG_WARNING);
    return;
  }

  // Find the selected operation.
  $plugin = $view->style_plugin;
  $operations = $plugin
    ->get_selected_operations();
  if (!isset($operations[$operation_callback])) {
    watchdog('vbo', 'Could not find operation %operation in view %vid.', array(
      '%operation' => $operation_callback,
      '%vid' => $vid,
    ), WATCHDOG_ERROR);
    return;
  }
  $operation = $plugin
    ->get_operation_info($operation_callback);

  // Execute the operation on the view results.
  $execution_type = $plugin->options['execution_type'];
  if ($execution_type == VBO_EXECUTION_BATCH) {
    $execution_type = VBO_EXECUTION_DIRECT;

    // we don't yet support Batch API here
  }
  _views_bulk_operations_execute($view, $view->result, $operation, $operation_arguments, array(
    'execution_type' => $execution_type,
    'display_result' => $plugin->options['display_result'],
    'max_performance' => $plugin->options['max_performance'],
    'settings' => $operation['options']['settings'],
  ));
}