ConfigController::downloadExport

public ConfigController::downloadExport()

Downloads a tarball of the site configuration.

File

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

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');
}
doc_Drupal
2016-10-29 08:52:16
Comments
Leave a Comment

Please login to continue.