Skip to content

Commit

Permalink
Remove --skip-modules from cim and cex. (Backport #2684) (#2686)
Browse files Browse the repository at this point in the history
  • Loading branch information
bircher authored and weitzman committed Mar 24, 2017
1 parent c6191e7 commit 68fb476
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 481 deletions.
82 changes: 14 additions & 68 deletions commands/core/config.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,8 @@ function config_drush_command() {
'example-value' => 'branchname',
),
'destination' => 'An arbitrary directory that should receive the exported files. An alternative to label argument.',
'skip-modules' => 'A list of modules to ignore during export (e.g. to avoid listing dev-only modules in exported configuration).',
),
'examples' => array(
'drush config-export --skip-modules=devel' => 'Export configuration; do not include the devel module in the exported configuration, regardless of whether or not it is enabled in the site.',
'drush config-export --destination' => 'Export configuration; Save files in a backup directory named config-export.',
),
);
Expand All @@ -133,11 +131,10 @@ function config_drush_command() {
'partial' => array(
'description' => 'Allows for partial config imports from the source directory. Only updates and new configs will be processed with this flag (missing configs will not be deleted).',
),
'skip-modules' => 'A list of modules to ignore during import (e.g. to avoid disabling dev-only modules that are not enabled in the imported configuration).',
),
'core' => array('8+'),
'examples' => array(
'drush config-import --skip-modules=devel' => 'Import configuration; do not enable or disable the devel module, regardless of whether or not it appears in the imported list of enabled modules.',
'drush config-import --partial' => 'Import configuration; do not remove missing configuration.',
),
'aliases' => array('cim'),
);
Expand Down Expand Up @@ -458,7 +455,6 @@ function drush_config_export($destination = NULL) {
function _drush_config_export($destination, $destination_dir, $branch) {
$commit = drush_get_option('commit');
$comment = drush_get_option('message', 'Exported configuration.');
$storage_filters = drush_config_get_storage_filters();
if (count(glob($destination_dir . '/*')) > 0) {
// Retrieve a list of differences between the active and target configuration (if any).
if ($destination == CONFIG_SYNC_DIRECTORY) {
Expand All @@ -471,21 +467,6 @@ function _drush_config_export($destination, $destination_dir, $branch) {
$active_storage = \Drupal::service('config.storage');
$comparison_source = $active_storage;

// If the output is being filtered, then write a temporary copy before doing
// any comparison.
if (!empty($storage_filters)) {
$tmpdir = drush_tempdir();
drush_copy_dir($destination_dir, $tmpdir, FILE_EXISTS_OVERWRITE);
$comparison_source = new FileStorage($tmpdir);
$comparison_source_filtered = new StorageWrapper($comparison_source, $storage_filters);
foreach ($active_storage->listAll() as $name) {
// Copy active storage to our temporary active store.
if ($existing = $active_storage->read($name)) {
$comparison_source_filtered->write($name, $existing);
}
}
}

$config_comparer = new StorageComparer($comparison_source, $target_storage, \Drupal::service('config.manager'));
if (!$config_comparer->createChangelist()->hasChanges()) {
return drush_log(dt('The active configuration is identical to the configuration in the export directory (!target).', array('!target' => $destination_dir)), LogLevel::OK);
Expand Down Expand Up @@ -521,10 +502,7 @@ function _drush_config_export($destination, $destination_dir, $branch) {
else {
$destination_storage = new FileStorage($destination_dir);
}
// If there are any filters, then attach them to the destination storage
if (!empty($storage_filters)) {
$destination_storage = new StorageWrapper($destination_storage, $storage_filters);
}

foreach ($source_storage->listAll() as $name) {
$destination_storage->write($name, $source_storage->read($name));
}
Expand Down Expand Up @@ -599,28 +577,6 @@ function drush_config_import_validate() {
}
}

/**
* Return storage filters to alter config import and export.
*/
function drush_config_get_storage_filters() {
return drush_command_invoke_all('drush_storage_filters');
}

/**
* Implements hook_drush_storage_filters().
*/
function config_drush_storage_filters() {
$result = array();
$module_adjustments = drush_get_option('skip-modules');
if (!empty($module_adjustments)) {
if (is_string($module_adjustments)) {
$module_adjustments = explode(',', $module_adjustments);
}
$result[] = new CoreExtensionFilter($module_adjustments);
}
return $result;
}

/**
* Command callback. Import from specified config directory (defaults to sync).
*/
Expand All @@ -646,39 +602,29 @@ function drush_config_import($source = NULL) {
$source_dir = config_get_config_directory($source);
}

if ($source == CONFIG_SYNC_DIRECTORY) {
$source_storage = \Drupal::service('config.storage.sync');
}
else {
$source_storage = new FileStorage($source_dir);
}

// Determine $source_storage in partial and non-partial cases.
/** @var \Drupal\Core\Config\StorageInterface $active_storage */
$active_storage = \Drupal::service('config.storage');
if (drush_get_option('partial')) {
$source_storage = new StorageReplaceDataWrapper($active_storage);
$file_storage = new FileStorage($source_dir);
foreach ($file_storage->listAll() as $name) {
$data = $file_storage->read($name);
$source_storage->replaceData($name, $data);
}
}
else {
if ($source == CONFIG_SYNC_DIRECTORY) {
$source_storage = \Drupal::service('config.storage.sync');
}
else {
$source_storage = new FileStorage($source_dir);
$replacement_storage = new StorageReplaceDataWrapper($active_storage);
foreach ($source_storage->listAll() as $name) {
$data = $source_storage->read($name);
$replacement_storage->replaceData($name, $data);
}
}

// If our configuration storage is being filtered, then attach all filters
// to the source storage object. We will use the filtered values uniformly
// for comparison, full imports, and partial imports.
$storage_filters = drush_config_get_storage_filters();
if (!empty($storage_filters)) {
$source_storage = new StorageWrapper($source_storage, $storage_filters);
$source_storage = $replacement_storage;
}

/** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
$config_manager = \Drupal::service('config.manager');
$storage_comparer = new StorageComparer($source_storage, $active_storage, $config_manager);


if (!$storage_comparer->createChangelist()->hasChanges()) {
return drush_log(dt('There are no changes to import.'), LogLevel::OK);
}
Expand Down
8 changes: 0 additions & 8 deletions commands/core/docs.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ function docs_drush_command() {
'callback' => 'drush_print_file',
'callback arguments' => array($docs_dir . '/examples/example.drushrc.php'),
);
$items['docs-config-filter'] = array(
'description' => 'Drupal Configuration Filtering with custom storage filters.',
'hidden' => TRUE,
'topic' => TRUE,
'bootstrap' => DRUSH_BOOTSTRAP_NONE,
'callback' => 'drush_print_file',
'callback arguments' => array($docs_dir . '/docs/config-filter.md'),
);
$items['docs-config-exporting'] = array(
'description' => 'Drupal configuration export instructions, including customizing configuration by environment.',
'hidden' => TRUE,
Expand Down
30 changes: 3 additions & 27 deletions docs/config-exporting.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,9 @@ a Drush feature. It should be the preferred method for changing
configuration values on a per-environment basis; however, it does not
work for some things, such as enabling and disabling modules. For
configuration changes not handled by the configuration override system,
you can use Drush configuration filters.
you can use configuration filters of the Config Filter module.

## Ignoring Development Modules

If you have a certain list of modules that should only be enabled on
the development or staging server, then this may be done with the
built-in `--skip-modules` option in the config-export and config-import
commands.

For example, if you want to enable the 'devel' module on development
systems, but not on production server, you could define the following
configuration settings in your drushrc.php file:
```
# $command_specific['config-export']['skip-modules'] = array('devel');
# $command_specific['config-import']['skip-modules'] = array('devel');
```
You may then use `drush pm-enable` to enable the devel module on the
development machine, and subsequent imports of the configuration data
will not cause it to be disabled again. Similarly, if you make changes
to configuration on the development environment and export them, then
the devel module will not be listed in the exports.

## More Complex Adjustments

Drush allows more complex changes to the configuration data to be made
via the configuration filter mechanism. In order to do this, you must
write some code inside a Drush extension.

See [Drupal Configuration Filtering](config-filter.md) for more information
on how to do this.
Use the [Config Split](https://www.drupal.org/project/config_split) module to
split off development configuration in a dedicated config directory.
66 changes: 0 additions & 66 deletions docs/config-filter.md

This file was deleted.

16 changes: 0 additions & 16 deletions drush.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,22 +420,6 @@ function hook_drush_invoke_alter($modules, $hook) {
}
}

/*
* Storage filters alter the .yml files on disk after a config-export or before
* a config-import. See `drush topic docs-config-filter` and config_drush_storage_filters().
*/
function hook_drush_storage_filters() {
$result = array();
$module_adjustments = drush_get_option('skip-modules');
if (!empty($module_adjustments)) {
if (is_string($module_adjustments)) {
$module_adjustments = explode(',', $module_adjustments);
}
$result[] = new CoreExtensionFilter($module_adjustments);
}
return $result;
}

/**
* @} End of "addtogroup hooks".
*/
81 changes: 0 additions & 81 deletions lib/Drush/Config/CoreExtensionFilter.php

This file was deleted.

Loading

0 comments on commit 68fb476

Please sign in to comment.