Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/config/src/Controller/ConfigController.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
5 use Drupal\Core\Archiver\ArchiveTar; | 5 use Drupal\Core\Archiver\ArchiveTar; |
6 use Drupal\Core\Config\ConfigManagerInterface; | 6 use Drupal\Core\Config\ConfigManagerInterface; |
7 use Drupal\Core\Config\StorageInterface; | 7 use Drupal\Core\Config\StorageInterface; |
8 use Drupal\Core\DependencyInjection\ContainerInjectionInterface; | 8 use Drupal\Core\DependencyInjection\ContainerInjectionInterface; |
9 use Drupal\Core\Diff\DiffFormatter; | 9 use Drupal\Core\Diff\DiffFormatter; |
10 use Drupal\Core\File\Exception\FileException; | |
11 use Drupal\Core\File\FileSystemInterface; | |
10 use Drupal\Core\Serialization\Yaml; | 12 use Drupal\Core\Serialization\Yaml; |
11 use Drupal\Core\Url; | 13 use Drupal\Core\Url; |
12 use Drupal\system\FileDownloadController; | 14 use Drupal\system\FileDownloadController; |
13 use Symfony\Component\DependencyInjection\ContainerInterface; | 15 use Symfony\Component\DependencyInjection\ContainerInterface; |
14 use Symfony\Component\HttpFoundation\Request; | 16 use Symfony\Component\HttpFoundation\Request; |
52 * @var \Drupal\Core\Diff\DiffFormatter | 54 * @var \Drupal\Core\Diff\DiffFormatter |
53 */ | 55 */ |
54 protected $diffFormatter; | 56 protected $diffFormatter; |
55 | 57 |
56 /** | 58 /** |
59 * The file system. | |
60 * | |
61 * @var \Drupal\Core\File\FileSystemInterface | |
62 */ | |
63 protected $fileSystem; | |
64 | |
65 /** | |
57 * {@inheritdoc} | 66 * {@inheritdoc} |
58 */ | 67 */ |
59 public static function create(ContainerInterface $container) { | 68 public static function create(ContainerInterface $container) { |
60 return new static( | 69 return new static( |
61 $container->get('config.storage'), | 70 $container->get('config.storage'), |
62 $container->get('config.storage.sync'), | 71 $container->get('config.storage.sync'), |
63 $container->get('config.manager'), | 72 $container->get('config.manager'), |
64 new FileDownloadController(), | 73 new FileDownloadController(), |
65 $container->get('diff.formatter') | 74 $container->get('diff.formatter'), |
75 $container->get('file_system') | |
66 ); | 76 ); |
67 } | 77 } |
68 | 78 |
69 /** | 79 /** |
70 * Constructs a ConfigController object. | 80 * Constructs a ConfigController object. |
71 * | 81 * |
72 * @param \Drupal\Core\Config\StorageInterface $target_storage | 82 * @param \Drupal\Core\Config\StorageInterface $target_storage |
73 * The target storage. | 83 * The target storage. |
74 * @param \Drupal\Core\Config\StorageInterface $source_storage | 84 * @param \Drupal\Core\Config\StorageInterface $source_storage |
75 * The source storage | 85 * The source storage. |
86 * @param \Drupal\Core\Config\ConfigManagerInterface $config_manager | |
87 * The config manager. | |
76 * @param \Drupal\system\FileDownloadController $file_download_controller | 88 * @param \Drupal\system\FileDownloadController $file_download_controller |
77 * The file download controller. | 89 * The file download controller. |
90 * @param \Drupal\Core\Diff\DiffFormatter $diff_formatter | |
91 * The diff formatter. | |
92 * @param \Drupal\Core\File\FileSystemInterface $file_system | |
93 * The file system. | |
78 */ | 94 */ |
79 public function __construct(StorageInterface $target_storage, StorageInterface $source_storage, ConfigManagerInterface $config_manager, FileDownloadController $file_download_controller, DiffFormatter $diff_formatter) { | 95 public function __construct(StorageInterface $target_storage, StorageInterface $source_storage, ConfigManagerInterface $config_manager, FileDownloadController $file_download_controller, DiffFormatter $diff_formatter, FileSystemInterface $file_system) { |
80 $this->targetStorage = $target_storage; | 96 $this->targetStorage = $target_storage; |
81 $this->sourceStorage = $source_storage; | 97 $this->sourceStorage = $source_storage; |
82 $this->configManager = $config_manager; | 98 $this->configManager = $config_manager; |
83 $this->fileDownloadController = $file_download_controller; | 99 $this->fileDownloadController = $file_download_controller; |
84 $this->diffFormatter = $diff_formatter; | 100 $this->diffFormatter = $diff_formatter; |
101 $this->fileSystem = $file_system; | |
85 } | 102 } |
86 | 103 |
87 /** | 104 /** |
88 * Downloads a tarball of the site configuration. | 105 * Downloads a tarball of the site configuration. |
89 */ | 106 */ |
90 public function downloadExport() { | 107 public function downloadExport() { |
91 file_unmanaged_delete(file_directory_temp() . '/config.tar.gz'); | 108 try { |
109 $this->fileSystem->delete(file_directory_temp() . '/config.tar.gz'); | |
110 } | |
111 catch (FileException $e) { | |
112 // Ignore failed deletes. | |
113 } | |
92 | 114 |
93 $archiver = new ArchiveTar(file_directory_temp() . '/config.tar.gz', 'gz'); | 115 $archiver = new ArchiveTar(file_directory_temp() . '/config.tar.gz', 'gz'); |
94 // Get raw configuration data without overrides. | 116 // Get raw configuration data without overrides. |
95 foreach ($this->configManager->getConfigFactory()->listAll() as $name) { | 117 foreach ($this->configManager->getConfigFactory()->listAll() as $name) { |
96 $archiver->addString("$name.yml", Yaml::encode($this->configManager->getConfigFactory()->get($name)->getRawData())); | 118 $archiver->addString("$name.yml", Yaml::encode($this->configManager->getConfigFactory()->get($name)->getRawData())); |