You are here

public function ConfigController::downloadExport in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/config/src/Controller/ConfigController.php \Drupal\config\Controller\ConfigController::downloadExport()

Downloads a tarball of the site configuration.

1 string reference to 'ConfigController::downloadExport'
config.routing.yml in core/modules/config/config.routing.yml
core/modules/config/config.routing.yml

File

core/modules/config/src/Controller/ConfigController.php, line 130

Class

ConfigController
Returns responses for config module routes.

Namespace

Drupal\config\Controller

Code

public function downloadExport() {
  try {
    $this->fileSystem
      ->delete($this->fileSystem
      ->getTempDirectory() . '/config.tar.gz');
  } catch (FileException $e) {

    // Ignore failed deletes.
  }
  $archiver = new ArchiveTar($this->fileSystem
    ->getTempDirectory() . '/config.tar.gz', 'gz');

  // Add all contents of the export storage to the archive.
  foreach ($this->exportStorage
    ->listAll() as $name) {
    $archiver
      ->addString("{$name}.yml", Yaml::encode($this->exportStorage
      ->read($name)));
  }

  // Get all  data from the remaining collections.
  foreach ($this->exportStorage
    ->getAllCollectionNames() as $collection) {
    $collection_storage = $this->exportStorage
      ->createCollection($collection);
    foreach ($collection_storage
      ->listAll() as $name) {
      $archiver
        ->addString(str_replace('.', '/', $collection) . "/{$name}.yml", Yaml::encode($collection_storage
        ->read($name)));
    }
  }
  $request = new Request([
    'file' => 'config.tar.gz',
  ]);
  return $this->fileDownloadController
    ->download($request, 'temporary');
}