You are here

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

Finish callback for the batch set the export form.

Parameters

bool $success: Whether the batch was successful or not.

array $results: The bath results.

array $operations: The batch operations.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse A redirection.

Throws

\Drupal\Core\TempStore\TempStoreException

1 call to ContactStorageExportBatches::finishBatch()
_contact_storage_export_finish_batch in ./contact_storage_export.module
Finish callback for the batch created in the export form.

File

src/ContactStorageExportBatches.php, line 194

Class

ContactStorageExportBatches
Class ContactStorageExportBatches.

Namespace

Drupal\contact_storage_export

Code

public static function finishBatch($success, array $results, array $operations) {
  if ($success) {

    // Store last exported ID if requested.
    if ($results['settings']['since_last_export']) {
      ContactStorageExport::setLastExportId($results['settings']['contact_form'], $results['current_id']);
    }

    // Save the data to the temp store.
    $key = ContactStorageExportTempstore::setTempstore($results['fid'], $results['settings']['filename']);

    // Redirect to download page.
    $route = 'contact_storage_export.contact_storage_download_form';
    $args = [
      'contact_form' => $results['settings']['contact_form'],
      'key' => $key,
    ];
    $url = Url::fromRoute($route, $args);
    $url_string = $url
      ->toString();
    $response = new RedirectResponse($url_string);
    return $response;
  }
  else {
    $message = t('There was no data to export.');
    $messenger = \Drupal::messenger();
    $messenger
      ->addWarning($message);
  }

  // Redirect back to export page.
  $route = 'entity.contact_form.export_form';
  $args = [
    'contact_form' => $results['settings']['contact_form'],
  ];
  $url = Url::fromRoute($route, $args);
  $url_string = $url
    ->toString();
  $response = new RedirectResponse($url_string);
  return $response;
}