You are here

function views_data_export_plugin_display_export::execute_initial in Views data export 7.4

Same name and namespace in other branches
  1. 6.3 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_display_export::execute_initial()
  2. 6 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_display_export::execute_initial()
  3. 6.2 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_display_export::execute_initial()
  4. 7 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_display_export::execute_initial()
  5. 7.3 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_display_export::execute_initial()

Initializes the whole export process and starts off the batch process.

Page execution will be ended at the end of this function.

1 call to views_data_export_plugin_display_export::execute_initial()
views_data_export_plugin_display_export::execute in plugins/views_data_export_plugin_display_export.inc
Execute this display handler.

File

plugins/views_data_export_plugin_display_export.inc, line 289
Contains the bulk export display plugin.

Class

views_data_export_plugin_display_export
The plugin that batches its rendering.

Code

function execute_initial() {

  // Register this export with our central table - get a unique eid
  // Also store our view in a cache to be retrieved with each batch call
  $this->batched_execution_state = views_data_export_new($this->view->name, $this->view->current_display, $this
    ->outputfile_create());
  views_data_export_view_store($this->batched_execution_state->eid, $this->view);

  // We need to build the index right now, before we lose $_GET etc.
  $this
    ->initialize_index();

  //$this->batched_execution_state->fid = $this->outputfile_create();

  // Initialize the progress counter
  $this->batched_execution_state->sandbox['max'] = db_query('SELECT COUNT(*) FROM {' . $this
    ->index_tablename() . '}')
    ->fetchField();

  // Record the time we started.
  list($usec, $sec) = explode(' ', microtime());
  $this->batched_execution_state->sandbox['started'] = (double) $usec + (double) $sec;

  // Build up our querystring for the final page callback.
  $querystring = array(
    'eid' => $this->batched_execution_state->eid,
    'return-url' => NULL,
  );

  // If we have a configured return path, use that.
  if ($this
    ->get_option('return_path')) {
    $querystring['return-url'] = $this
      ->get_option('return_path');
  }
  else {
    if (!empty($_GET['attach']) && isset($this->view->display[$_GET['attach']])) {

      // Get the path of the attached display:
      $querystring['return-url'] = $this->view
        ->get_url(NULL, $this->view->display[$_GET['attach']]->handler
        ->get_path());
    }
  }

  //Set the batch off
  $batch = array(
    'operations' => array(
      array(
        '_views_data_export_batch_process',
        array(
          $this->batched_execution_state->eid,
          $this->view->current_display,
          $this->view
            ->get_exposed_input(),
        ),
      ),
    ),
    'title' => t('Building export'),
    'init_message' => t('Export is starting up.'),
    'progress_message' => t('Exporting @percentage% complete,'),
    'error_message' => t('Export has encountered an error.'),
  );

  // We do not return, so update database sandbox now
  views_data_export_update($this->batched_execution_state);
  $final_destination = $this->view
    ->get_url();

  // Provide a way in for others at this point
  // e.g. Drush to grab this batch and yet execute it in
  // it's own special way
  $batch['view_name'] = $this->view->name;
  $batch['exposed_filters'] = $this->view
    ->get_exposed_input();
  $batch['display_id'] = $this->view->current_display;
  $batch['eid'] = $this->batched_execution_state->eid;
  $batch_redirect = array(
    $final_destination,
    array(
      'query' => $querystring,
    ),
  );
  drupal_alter('views_data_export_batch', $batch, $batch_redirect);

  // Modules may have cleared out $batch, indicating that we shouldn't process further.
  if (!empty($batch)) {
    batch_set($batch);

    // batch_process exits
    batch_process($batch_redirect);
  }
}