function ConfigController::downloadExport

Same name in other branches
  1. 9 core/modules/config/src/Controller/ConfigController.php \Drupal\config\Controller\ConfigController::downloadExport()
  2. 8.9.x core/modules/config/src/Controller/ConfigController.php \Drupal\config\Controller\ConfigController::downloadExport()
  3. 10 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 133

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) {
        // 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');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.