function views_bulk_operations_execute in Views Bulk Operations (VBO) 6.3
Same name and namespace in other branches
- 6 views_bulk_operations.module \views_bulk_operations_execute()
- 7.3 views_bulk_operations.module \views_bulk_operations_execute()
API function to programmatically invoke a VBO.
2 calls to views_bulk_operations_execute()
- views_bulk_operations_action in ./views_bulk_operations.module 
- Execution function for views_bulk_operations_action action.
- views_bulk_operations_drush_execute in ./views_bulk_operations.drush.inc 
- Implementation of 'vbo execute' command.
File
- ./views_bulk_operations.module, line 1291 
- 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()) {
  $view = views_get_view($vid);
  if (!is_object($view)) {
    _views_bulk_operations_report_error('Could not find view %vid.', array(
      '%vid' => $vid,
    ));
    return;
  }
  // 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) {
    _views_bulk_operations_report_error('Could not find a VBO display in view %vid.', array(
      '%vid' => $vid,
    ));
    return;
  }
  // Execute the view.
  $view
    ->set_exposed_input($view_exposed_input);
  $view
    ->set_arguments($view_arguments);
  $view
    ->build($plugin->view->current_display);
  $view->query
    ->set_limit(NULL);
  // reset the work done by the pager
  $view->query
    ->set_offset(NULL);
  $view
    ->execute();
  // Find the selected operation.
  $plugin = $view->style_plugin;
  $operations = $plugin
    ->get_selected_operations();
  if (!isset($operations[$operation_callback])) {
    _views_bulk_operations_report_error('Could not find operation %operation in view %vid.', array(
      '%operation' => $operation_callback,
      '%vid' => $vid,
    ));
    return;
  }
  $operation = $plugin
    ->get_operation_info($operation_callback);
  // Execute the operation on the view results.
  foreach ($view->result as $num => $result) {
    $objects[$num + 1] = $result;
  }
  $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, $objects, $operation, $operation_arguments, array(
    'execution_type' => $execution_type,
    'display_result' => $plugin->options['display_result'],
    'settings' => $plugin
      ->get_operation_settings($operation),
  ));
}