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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.