Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple config:delete objects in same call #5317

Merged
merged 1 commit into from
Nov 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/Drupal/Commands/config/ConfigCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Drush\Exec\ExecTrait;
use Drush\SiteAlias\SiteAliasManagerAwareInterface;
use Drush\Utils\FsUtils;
use Drush\Utils\StringUtils;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
Expand Down Expand Up @@ -249,29 +250,33 @@ public function edit($config_name, $options = []): void
}

/**
* Delete a configuration key, or a whole object.
* Delete a configuration key, or a whole object(s).
*
* @command config:delete
* @validate-config-name
* @interact-config-name
* @param $config_name The config object name, for example "system.site".
* @param $key A config key to clear, for example "page.front".
* @usage drush config:delete system.site
* Delete the the system.site config object.
* @param $config_name The config object name(s). Delimit multiple with commas.
* @param $key A config key to clear, May not be used with multiple config names.
* @usage drush config:delete system.site,system.rss
* Delete the system.site and system.rss config objects.
* @usage drush config:delete system.site page.front
* Delete the 'page.front' key from the system.site object.
* @aliases cdel,config-delete
*/
public function delete($config_name, $key = null): void
{
$config = $this->getConfigFactory()->getEditable($config_name);
if ($key) {
$config = $this->getConfigFactory()->getEditable($config_name);
if ($config->get($key) === null) {
throw new \Exception(dt('Configuration key !key not found.', ['!key' => $key]));
}
$config->clear($key)->save();
} else {
$config->delete();
$names = StringUtils::csvToArray($config_name);
foreach ($names as $name) {
$config = $this->getConfigFactory()->getEditable($name);
$config->delete();
}
}
}

Expand Down Expand Up @@ -504,10 +509,13 @@ public function validateConfigName(CommandData $commandData)
{
$arg_name = $commandData->annotationData()->get('validate-config-name', null) ?: 'config_name';
$config_name = $commandData->input()->getArgument($arg_name);
$config = \Drupal::config($config_name);
if ($config->isNew()) {
$msg = dt('Config !name does not exist', ['!name' => $config_name]);
return new CommandError($msg);
$names = StringUtils::csvToArray($config_name);
foreach ($names as $name) {
$config = \Drupal::config($name);
if ($config->isNew()) {
$msg = dt('Config !name does not exist', ['!name' => $name]);
return new CommandError($msg);
}
}
}

Expand Down