You are here

function drush_views_bulk_operations_execute in Views Bulk Operations (VBO) 6

Same name and namespace in other branches
  1. 8.3 views_bulk_operations.drush.inc \drush_views_bulk_operations_execute()
  2. 8 views_bulk_operations.drush.inc \drush_views_bulk_operations_execute()
  3. 8.2 views_bulk_operations.drush.inc \drush_views_bulk_operations_execute()
  4. 4.0.x views_bulk_operations.drush.inc \drush_views_bulk_operations_execute()

Implementation of 'vbo-execute' command.

1 string reference to 'drush_views_bulk_operations_execute'
views_bulk_operations_drush_command in ./views_bulk_operations.drush.inc
Implementation of hook_drush_command().

File

./views_bulk_operations.drush.inc, line 82

Code

function drush_views_bulk_operations_execute($vid = NULL, $operation = NULL) {

  // Parse arguments.
  if (is_null($vid)) {
    drush_set_error('VIEWS_BULK_OPERATIONS_MISSING_VID', dt('Please specify a view ID to execute.'));
    return;
  }
  if (is_null($operation)) {
    drush_set_error('VIEWS_BULK_OPERATIONS_MISSING_OPERATION', dt('Please specify an operation to execute.'));
    return;
  }
  $args = func_get_args();
  $view_exposed_input = array();
  $operation_arguments = array();
  $view_arguments = array();
  if (count($args) > 2) {
    for ($i = 2; $i < count($args); $i++) {
      $parts = array();
      if (FALSE === preg_match('/^(?<type>\\w+):(?:(?<name>\\w+)=)?(?<value>(.*?))$/', $args[$i], $parts)) {
        drush_set_error('VIEWS_BULK_OPERATIONS_INVALID_PARAMETER', dt('The parameter %arg should be of the form type:[name=]value where type in {input, argument, operation}.', array(
          '%arg' => $args[$i],
        )));
        return;
      }
      switch ($parts['type']) {
        case 'input':
          $view_exposed_input[$parts['name']] = $parts['value'];
          break;
        case 'operation':
          $operation_arguments[$parts['name']] = $parts['value'];
          break;
        case 'argument':
          $view_arguments[] = $parts['value'];
          break;
        default:
          drush_set_error('VIEWS_BULK_OPERATIONS_UNKNOWN_PARAMETER', dt('The parameter type %type is unknown. Please specify either input, argument or operation.', array(
            '%type' => $parts['type'],
          )));
          return;
      }
    }
  }

  // Impersonate admin.
  global $user;
  $user = user_load(array(
    'uid' => '1',
  ));
  session_save_session(FALSE);

  // Execute the VBO.
  views_bulk_operations_execute($vid, $operation, $operation_arguments, $view_exposed_input, $view_arguments);
}