You are here

function views_bulk_operations_queue_item_process in Views Bulk Operations (VBO) 7.3

Processes the provided queue item.

Used as a worker callback defined by views_bulk_operations_cron_queue_info() to process the site queue, as well as by views_bulk_operations_active_queue_process() to process the active queue.

Parameters

$queue_item_arguments: The arguments of the queue item to process.

$log: An injected array of log messages, to be modified by reference. If NULL, the function defaults to using watchdog.

2 calls to views_bulk_operations_queue_item_process()
views_bulk_operations_active_queue_process in ./views_bulk_operations.module
Batch API callback: processes the active queue.
views_bulk_operations_direct_process in ./views_bulk_operations.module
Processes the passed rows directly (without batching and queueing).
1 string reference to 'views_bulk_operations_queue_item_process'
views_bulk_operations_cron_queue_info in ./views_bulk_operations.module
Implements of hook_cron_queue_info().

File

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

Code

function views_bulk_operations_queue_item_process($queue_item_data, &$log = NULL) {
  list($row_group, $operation, $options) = $queue_item_data['arguments'];
  $account = user_load($queue_item_data['uid']);
  $entity_type = $operation->entityType;
  $entity_ids = array();
  foreach ($row_group as $row_index => $row) {
    $entity_ids[] = $row['entity_id'];
  }
  $entities = _views_bulk_operations_entity_load($entity_type, $entity_ids, $options['revision']);
  foreach ($row_group as $row_index => $row) {
    $entity_id = $row['entity_id'];

    // A matching entity couldn't be loaded. Skip this item.
    if (!isset($entities[$entity_id])) {
      continue;
    }
    if ($options['revision']) {

      // Don't reload revisions for now, they are not statically cached and
      // usually don't run into the edge case described below.
      $entity = $entities[$entity_id];
    }
    else {

      // A previous action might have resulted in the entity being resaved
      // (e.g. node synchronization from a prior node in this batch), so try
      // to reload it. If no change occurred, the entity will be retrieved
      // from the static cache, resulting in no performance penalty.
      $entity = entity_load_single($entity_type, $entity_id);
      if (empty($entity)) {

        // The entity is no longer valid.
        continue;
      }
    }

    // If the current entity can't be accessed, skip it and log a notice.
    $skip_permission_check = $operation
      ->getAdminOption('skip_permission_check');
    if (!$skip_permission_check && !_views_bulk_operations_entity_access($operation, $entity_type, $entity, $account)) {
      $message = 'Skipped %operation on @type %title due to insufficient permissions.';
      $arguments = array(
        '%operation' => $operation
          ->label(),
        '@type' => $entity_type,
        '%title' => entity_label($entity_type, $entity),
      );
      if ($log) {
        $log[] = t($message, $arguments);
      }
      else {
        watchdog('views bulk operations', $message, $arguments, WATCHDOG_ALERT);
      }
      continue;
    }
    $operation_context = array(
      'progress' => $row['position'],
      'view_info' => $options['view_info'],
    );
    if ($operation
      ->needsRows()) {
      $operation_context['rows'] = array(
        $row_index => $row['views_row'],
      );
    }
    $operation
      ->execute($entity, $operation_context);
    unset($row_group[$row_index]);
  }
}