Skip to content

Commit

Permalink
Remove --skip-modules from 'cim' and 'cex' (#2684)
Browse files Browse the repository at this point in the history
Also remove all StorageFilter related code.
  • Loading branch information
bircher authored and weitzman committed Mar 21, 2017
1 parent d4a3872 commit e7f119e
Show file tree
Hide file tree
Showing 13 changed files with 10 additions and 523 deletions.
28 changes: 2 additions & 26 deletions docs/config-exporting.md
Expand Up @@ -33,29 +33,5 @@ you can use Drush configuration filters.

## 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.
76 changes: 0 additions & 76 deletions docs/config-filter.md

This file was deleted.

16 changes: 0 additions & 16 deletions drush.api.php
Expand Up @@ -42,22 +42,6 @@ function hook_drush_help_alter(&$command) {
}
}

/*
* 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".
*/
1 change: 0 additions & 1 deletion mkdocs.yml
Expand Up @@ -17,7 +17,6 @@ pages:
- Command Authoring: commands.md
- Bootstrap: bootstrap.md
- Context system: context.md
- Filtering Drupal configuration: config-filter.md
#use_directory_urls: false

markdown_extensions:
Expand Down
26 changes: 0 additions & 26 deletions src/Commands/config/ConfigCommands.php
Expand Up @@ -318,32 +318,6 @@ public static function configChangesTablePrint(array $config_changes) {
return $tbl;
}

/**
* @hook on-event config-storage-filters
*
* @param array $options Options that were passed by the user.
*
* @return \Drush\Config\StorageFilter[]
* An array of filters.
*/
function coreStorageFilters($options) {
$result = [];
$module_adjustments = $options['skip-modules'];
if (!empty($module_adjustments)) {
if (is_string($module_adjustments)) {
$module_adjustments = explode(',', $module_adjustments);
}
$result[] = new CoreExtensionFilter($module_adjustments);
}
return $result;
}

/**
* @hook options @optionset-storage-filters
* @option skip-modules A list of modules to ignore during import/export (e.g. to avoid disabling dev-only modules that are not enabled in the imported configuration).
*/
function optionsetStorageFilters() {}

/**
* @hook interact @interact-config-name
*/
Expand Down
30 changes: 2 additions & 28 deletions src/Commands/config/ConfigExportCommands.php
Expand Up @@ -2,29 +2,22 @@
namespace Drush\Commands\config;

use Consolidation\AnnotatedCommand\CommandData;
use Consolidation\AnnotatedCommand\Events\CustomEventAwareInterface;
use Drupal\Core\Config\StorageComparer;
use Drupal\Core\Config\FileStorage;
use Drush\Config\StorageWrapper;
use Drush\Commands\DrushCommands;

class ConfigExportCommands extends DrushCommands implements CustomEventAwareInterface {

use ConfigTrait;
class ConfigExportCommands extends DrushCommands {

/**
* Export Drupal configuration to a directory.
*
* @command config-export
* @interact-config-label
* @param string $label A config directory label (i.e. a key in $config_directories array in settings.php).
* @optionset-storage-filters
* @option add Run `git add -p` after exporting. This lets you choose which config changes to sync for commit.
* @option commit Run `git add -A` and `git commit` after exporting. This commits everything that was exported without prompting.
* @option message Commit comment for the exported configuration. Optional; may only be used with --commit.
* @option destination An arbitrary directory that should receive the exported files. An alternative to label argument.
* @usage 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.
* @usage drush config-export --destination
* Export configuration; Save files in a backup directory named config-export.
* @bootstrap DRUSH_BOOTSTRAP_DRUPAL_FULL
Expand Down Expand Up @@ -63,7 +56,6 @@ function processDestination($label, $options) {

public function doExport($options, $destination_dir) {
$commit = $options['commit'];
$storage_filters = $this->getStorageFilters($options);
if (count(glob($destination_dir . '/*')) > 0) {
// Retrieve a list of differences between the active and target configuration (if any).
if ($destination_dir == \config_get_config_directory(CONFIG_SYNC_DIRECTORY)) {
Expand All @@ -76,21 +68,6 @@ public function doExport($options, $destination_dir) {
$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()) {
$this->logger()->notice(dt('The active configuration is identical to the configuration in the export directory (!target).', array('!target' => $destination_dir)));
Expand Down Expand Up @@ -126,10 +103,7 @@ public function doExport($options, $destination_dir) {
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
28 changes: 6 additions & 22 deletions src/Commands/config/ConfigImportCommands.php
Expand Up @@ -3,31 +3,24 @@

use Consolidation\AnnotatedCommand\CommandError;
use Consolidation\AnnotatedCommand\CommandData;
use Consolidation\AnnotatedCommand\Events\CustomEventAwareInterface;
use Drupal\config\StorageReplaceDataWrapper;
use Drupal\Core\Config\StorageComparer;
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\ConfigException;
use Drupal\Core\Config\FileStorage;
use Drush\Config\StorageWrapper;
use Drush\Commands\DrushCommands;

class ConfigImportCommands extends DrushCommands implements CustomEventAwareInterface {

use ConfigTrait;
class ConfigImportCommands extends DrushCommands {

/**
* Import config from a config directory.
*
* @command config-import
* @param $label A config directory label (i.e. a key in \$config_directories array in settings.php).
* @interact-config-label
* @optionset-storage-filters
* @option preview Format for displaying proposed changes. Recognized values: list, diff.
* @option source An arbitrary directory that holds the configuration files. An alternative to label argument
* @option partial 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).
* @usage 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.
* @bootstrap DRUSH_BOOTSTRAP_DRUPAL_FULL
* @aliases cim
* @complete \Drush\Commands\core\ConfigCommands::completeLabels
Expand All @@ -47,21 +40,12 @@ public function import($label = NULL, $options = ['preview' => 'list', 'source'
/** @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);
$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.
// Command files may provide filters by implementing our hook.
$storage_filters = $this->getStorageFilters($options);
if (!empty($storage_filters)) {
$source_storage = new StorageWrapper($source_storage, $storage_filters);
$source_storage = $replacement_storage;
}

/** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
Expand Down
22 changes: 0 additions & 22 deletions src/Commands/config/ConfigTrait.php

This file was deleted.

11 changes: 0 additions & 11 deletions src/Commands/core/DocsCommands.php
Expand Up @@ -67,17 +67,6 @@ public function configExport() {
self::printFile(DRUSH_BASE_PATH. '/docs/config-exporting.md');
}

/**
* Drupal configuration filter instructions for changing yml files during import/export.
*
* @command docs-config-filter
* @hidden
* @topic
*/
public function configFilter() {
self::printFile(DRUSH_BASE_PATH. '/docs/config-filter.md');
}

/**
* Site aliases overview on creating your own aliases for commonly used Drupal sites with examples from example.aliases.drushrc.php.
*
Expand Down

0 comments on commit e7f119e

Please sign in to comment.