forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigExportCommand.php
More file actions
79 lines (67 loc) · 2.72 KB
/
Copy pathConfigExportCommand.php
File metadata and controls
79 lines (67 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* @file
* Contains \Drupal\AppConsole\Command\ConfigExportCommand.
*/
namespace Drupal\AppConsole\Command;
use Drupal\Core\Archiver\ArchiveTar;
use Drupal\Component\Serialization\Yaml;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ConfigExportCommand extends ContainerAwareCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('config:export')
->setDescription($this->trans('commands.config.export.description'))
->addArgument('directory', InputArgument::OPTIONAL,
$this->trans('commands.config.export.arguments.directory'));
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$messageHelper = $this->getHelperSet()->get('message');
$directory = $input->getArgument('directory');
if (!$directory) {
$config = $this->getConfigFactory()->get('system.file');
$directory = $config->get('path.temporary') ?: file_directory_temp();
$directory .= '/' . CONFIG_STAGING_DIRECTORY;
}
if (!is_dir($directory)) {
mkdir($directory, 0777, true);
}
$config_export_file = $directory . '/config.tar.gz';
file_unmanaged_delete($config_export_file);
try {
$archiver = new ArchiveTar($config_export_file, 'gz');
$this->configManager = $this->getConfigManager();
// 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()));
}
$this->targetStorage = $this->getConfigStorage();
// 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)));
}
}
} catch (\Exception $e) {
$output->writeln('[+] <error>' . $e->getMessage() . '</error>');
return;
}
$messageHelper->addSuccessMessage(
sprintf($this->trans('commands.config.export.messages.directory'), $config_export_file)
);
}
}