Created
February 21, 2015 17:02
-
-
Save jmolivas/0798868633ea8f3841df to your computer and use it in GitHub Desktop.
Drupal Console ConfigExportCommand class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Contains \Drupal\AppConsole\Command\ConfigExportCommand. | |
*/ | |
namespace Drupal\AppConsole\Command; | |
use Symfony\Component\Console\Input\InputArgument; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use Drupal\Core\Config\FileStorage; | |
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) | |
{ | |
$directory = $input->getArgument('directory'); | |
if (!$directory) { | |
$config = $this->getConfigFactory()->get('system.file'); | |
$directory = $config->get('path.temporary') ?:'/tmp'; | |
} | |
$directory .= '/' . CONFIG_STAGING_DIRECTORY; | |
$source_storage = $this->getConfigStorage(); | |
$destination_storage = new FileStorage($directory); | |
foreach ($source_storage->listAll() as $name) { | |
$destination_storage->write($name, $source_storage->read($name)); | |
} | |
$collectionNames = $this->getConfigStorage()->getAllCollectionNames(); | |
foreach ($collectionNames as $collection) { | |
$source_storage = $source_storage->createCollection($collection); | |
$destination_storage = $destination_storage->createCollection($collection); | |
foreach ($source_storage->listAll() as $name) { | |
$destination_storage->write($name, $source_storage->read($name)); | |
} | |
} | |
$this->showMessage($output, 'commands.config.export.messages.directory : ' . $directory); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment