You are here

public static function ContactStorageExportBatches::processBatch in Contact Storage Export 8

Process callback for the batch set the export form.

Parameters

array $settings: The settings from the export form.

array $context: The batch context.

Throws

\Drupal\Core\Entity\EntityStorageException

1 call to ContactStorageExportBatches::processBatch()
_contact_storage_export_process_batch in ./contact_storage_export.module
Process callback for the batch created in the export form.

File

src/ContactStorageExportBatches.php, line 34

Class

ContactStorageExportBatches
Class ContactStorageExportBatches.

Namespace

Drupal\contact_storage_export

Code

public static function processBatch(array $settings, array &$context) {
  if (empty($context['sandbox'])) {

    // Store data in results for batch finish.
    $context['results']['data'] = [];
    $context['results']['settings'] = $settings;

    // Whether we are doing since last export.
    $last_id = 0;
    if ($settings['since_last_export']) {
      $last_id = ContactStorageExport::getLastExportId($settings['contact_form']);
    }

    // Create a temp file.
    $file = self::getTempFile();
    $context['results']['fid'] = $file
      ->id();

    // Set initial batch progress.
    $context['sandbox']['settings'] = $settings;
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['current_id'] = 0;
    $context['sandbox']['max'] = self::getMax($settings, $last_id);
  }
  else {
    $settings = $context['sandbox']['settings'];
  }
  if ($context['sandbox']['max'] == 0) {

    // If we have no rows to export, immediately finish.
    $context['finished'] = 1;
  }
  else {

    // Load the tempfile.
    self::$tempFile = File::load($context['results']['fid']);

    // Get the next batch worth of data.
    self::getContactFormData($settings, $context);

    // Check if we are now finished.
    if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
      $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
    }
  }
}