public function ConfigPartialExportCommands::configPartialExport in Config Partial Export 8
Command description here.
@option changelist Shows the list of changed active config. @option show-destinations Choose from a list of config destinations. *
@usage drush config-partial-export webform.webform.* Export all webform config. @usage drush cpex webform.webform.* Export all webform config.
@command config-partial-export @aliases cpex
Parameters
$config: Configuration keys, comma separated.
$label: A config destination label (i.e. a key in $config_directories array in settings.php). Defaults to 'sync'.
array $options: An associative array of options whose values come from cli, aliases, config, etc.
File
- src/
Commands/ ConfigPartialExportCommands.php, line 94
Class
- ConfigPartialExportCommands
- Defines Drush commands for the Search API.
Namespace
Drupal\config_partial_export\CommandsCode
public function configPartialExport($config = '', $label = '', $options = [
'changelist' => '',
'show-destinations' => [
'description',
],
]) {
$changelist = $this
->getConfig()
->get('changelist', 0);
if ($changelist) {
$changes = $this
->_config_partial_export_get_changes();
if (!empty($changes)) {
$this
->output()
->writeln(dt("Your configuration has changed:"));
foreach ($changes as $key => $values) {
$this
->output()
->writeln($key);
foreach ($values as $value) {
$this
->output()
->writeln('- ' . $value);
}
}
}
return TRUE;
}
global $config_directories;
$choices = drush_map_assoc(array_keys($config_directories));
unset($choices[CONFIG_ACTIVE_DIRECTORY]);
// Throw a warning if someone wants to show destinations but supplied one.
if (!empty($label) and $this
->getConfig()
->get('show-destinations')) {
$this
->logger()
->error('Error, supplied both a destination and the list. Using the supplied destination and ignoring the list');
}
elseif ($this
->getConfig()
->get('show-destinations')) {
$label = $this
->_choice($choices, 'Choose a destination.');
if (empty($label)) {
return $this
->_user_abort();
}
}
// Check to see if destination is still undefined, set it to default.
if (empty($label)) {
$label = CONFIG_SYNC_DIRECTORY;
}
// Check if label doesn't exist.
if (!in_array($label, $choices)) {
$msg = dt('Error !target not found as a configuration target.', [
'!target' => $label,
]);
return drush_set_error('NO_CONFIG_DEST', $msg);
}
$destination_dir = config_get_config_directory($label);
$destination_storage = new FileStorage($destination_dir);
$config_keys = explode(",", $config);
foreach ($config_keys as $config_key) {
// Look for a wildcard character.
if (strpos($config_key, '*') !== FALSE) {
$wildcard_keys = $this
->_config_partial_export_get_wildcard_keys($config_key, $this->configStorage);
foreach ($wildcard_keys as $wildcard_key) {
$this
->_config_partial_export_write_config($wildcard_key, $this->configStorage, $destination_storage, $destination_dir);
}
}
else {
$this
->_config_partial_export_write_config($config_key, $this->configStorage, $destination_storage, $destination_dir);
}
}
return TRUE;
}