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()
Helper function to execute the chosen action upon selected objects.
2 calls to _views_bulk_operations_execute()
- views_bulk_operations_execute in ./
views_bulk_operations.module - API function to programmatically invoke a VBO.
- views_bulk_operations_form_submit in ./
views_bulk_operations.module - Submit handler for the selected operation.
File
- ./
views_bulk_operations.module, line 544 - Allows operations to be performed on items selected in a view.
Code
function _views_bulk_operations_execute($view, $objects, $operation, $operation_arguments, $options) {
// Get the object info we're dealing with.
$object_info = _views_bulk_operations_object_info_for_view($view);
if (!$object_info) {
return;
}
// Add action arguments.
$params = array();
if ($operation['configurable'] && is_array($operation_arguments)) {
$params += $operation_arguments;
}
// Add static callback arguments. Note that in the case of actions, static arguments
// are picked up from the database in actions_do().
if (isset($operation['callback arguments'])) {
$params += $operation['callback arguments'];
}
// Add this view as parameter.
$params['view'] = array(
'vid' => !empty($view->vid) ? $view->vid : $view->name,
'exposed_input' => $view
->get_exposed_input(),
'arguments' => $view->args,
);
// Add static settings to the params.
if (!empty($options['settings'])) {
$params['settings'] = $options['settings'];
}
if (version_compare(VERSION, '6.10', '<')) {
// Hack to force actions_do() to process any number of invocations.
// Check http://drupal.org/node/290282 to understand more.
// This was fixed as of D6.10: http://cvs.drupal.org/viewvc.py/drupal/drupal/includes/actions.inc?view=log&pathrev=DRUPAL-6-10
variable_set('actions_max_stack', 10000000);
}
if ($operation['aggregate'] != VBO_AGGREGATE_FORCED && $options['execution_type'] == VBO_EXECUTION_BATCH) {
$operations = array();
foreach ($objects as $num => $row) {
$oid = $row->{$view->base_field};
$operations[] = array(
'_views_bulk_operations_batch_process',
array(
$oid,
$row,
),
);
}
// Save the options in the session because Batch API doesn't give a way to
// send a parameter to the finished callback.
$_SESSION['vbo_options']['display_result'] = $options['display_result'];
$_SESSION['vbo_options']['operation'] = $operation;
$_SESSION['vbo_options']['params'] = $params;
$_SESSION['vbo_options']['object_info'] = $object_info;
$batch = array(
'operations' => $operations,
'finished' => '_views_bulk_operations_batch_finished',
'title' => t('Performing %action on selected rows...', array(
'%action' => $operation['label'],
)),
);
batch_set($batch);
}
else {
if ($operation['aggregate'] != VBO_AGGREGATE_FORCED && module_exists('job_queue') && $options['execution_type'] == VBO_EXECUTION_QUEUE) {
global $user;
foreach ($objects as $row) {
$oid = $row->{$view->base_field};
job_queue_add('_views_bulk_operations_queue_process', t('Perform %action on @type %oid.', array(
'%action' => $operation['label'],
'@type' => t($object_info['type']),
'%oid' => $oid,
)), array(
$oid,
$row,
$operation,
$params,
$user->uid,
$options['display_result'],
$object_info,
));
$oids[] = $oid;
}
if ($options['display_result']) {
drupal_set_message(t('Enqueued %action on @types %oid. Check the <a href="@queue">queued jobs page</a>.', array(
'%action' => $operation['label'],
'@types' => format_plural(count($objects), t($object_info['type']), t($object_info['type'] . 's')),
'%oid' => implode(', ', $oids),
'@queue' => url('admin/reports/job_queue'),
)));
}
}
else {
/*if ($options['execution_type'] == VBO_EXECUTION_DIRECT)*/
@set_time_limit(0);
$context['results']['rows'] = 0;
$context['results']['time'] = microtime(TRUE);
_views_bulk_operations_direct_process($view, $operation, $objects, $params, $object_info, $context);
_views_bulk_operations_direct_finished(TRUE, $context['results'], array(), $options['display_result']);
}
}
}