You are here

protected static function ContactStorageExportBatches::writeToTempFile in Contact Storage Export 8

Write to the temp file.

Parameters

string $data: The data to add to the file.

Throws

\Drupal\Core\Entity\EntityStorageException

1 call to ContactStorageExportBatches::writeToTempFile()
ContactStorageExportBatches::prepareMessages in src/ContactStorageExportBatches.php
Prepare the contact_message objects for export to CSV.

File

src/ContactStorageExportBatches.php, line 282

Class

ContactStorageExportBatches
Class ContactStorageExportBatches.

Namespace

Drupal\contact_storage_export

Code

protected static function writeToTempFile($data) {
  $file = self::getTempFile();
  if (file_put_contents($file
    ->getFileUri(), $data, FILE_APPEND) === FALSE) {
    $url = Url::fromRoute('entity.contact_form.export_form', []);
    $url_string = $url
      ->toString();
    $response = new RedirectResponse($url_string);
    $response
      ->send();
    $message = t('The export was unsuccessful for an unknown reason. Please check your error logs.');
    $messenger = \Drupal::messenger();
    $messenger
      ->addWarning($message);
  }
  $file
    ->setSize($file
    ->getFileUri());
  $file
    ->save();
}