function RulesCommands::revert
Reverts a rule to its original state on your site.
@command rules:revert @interact-rule-names @aliases rrev,rules-revert
@usage drush rules:revert test_rule Restores the module-provided Rule with machine id 'test_rule' to its original state. If the Rule hasn't been customized on the site, this has no effect.
Parameters
string $rule: Rule name (machine id) to revert.
Throws
\Exception
File
-
src/
Commands/ RulesCommands.php, line 315
Class
- RulesCommands
- Drush 9+ commands for the Rules module.
Namespace
Drupal\rules\CommandsCode
public function revert($rule) {
// @todo Implement this function.
// The $rule argument could refer to a Reaction Rule or a Rules Component.
$config = $this->configStorage
->read('rules.reaction.' . $rule);
if (empty($config)) {
$config = $this->configStorage
->read('rules.component.' . $rule);
if (empty($config)) {
// The @interact-rule-names hook returns fully-qualified names.
$config = $this->configStorage
->read($rule);
if (empty($config)) {
throw new \Exception(dt('Could not find a Reaction Rule or a Rules Component named @name', [
'@name' => $rule,
]));
}
}
}
if (($rule->status & ENTITY_OVERRIDDEN) == ENTITY_OVERRIDDEN) {
if ($this->confirm(dt('Are you sure you want to revert the rule named "@name"? This action cannot be undone.', [
'@name' => $rule,
]))) {
// $config->delete();
$this->logger
->success(dt('The rule @name has been reverted to its default state.', [
'@name' => $rule,
]));
}
}
else {
$this->logger
->warning(dt('The rule "@name" has not been overridden and can\'t be reverted.', [
'@name' => $rule,
]));
}
}