You are here

public function ConfigController::downloadExport in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 95
Contains \Drupal\config\Controller\ConfigController.

Class

ConfigController
Returns responses for config module routes.

Namespace

Drupal\config\Controller

Code

public function downloadExport() {
  file_unmanaged_delete(file_directory_temp() . '/config.tar.gz');
  $archiver = new ArchiveTar(file_directory_temp() . '/config.tar.gz', 'gz');

  // Get raw configuration data without overrides.
  foreach ($this->configManager
    ->getConfigFactory()
    ->listAll() as $name) {
    $archiver
      ->addString("{$name}.yml", Yaml::encode($this->configManager
      ->getConfigFactory()
      ->get($name)
      ->getRawData()));
  }

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