You are here

function drush_rules_delete in Rules 8.3

Same name and namespace in other branches
  1. 7.2 rules.drush.inc \drush_rules_delete()

Deletes a rule on the site.

File

./rules.drush.inc, line 267
Rules module integration with Drush 8 and earlier.

Code

function drush_rules_delete($rule) {

  // The $rule argument could refer to a Reaction Rule or a Rules Component.
  if (\Drupal::service('config.storage')
    ->exists('rules.reaction.' . $rule)) {
    $config = \Drupal::configFactory()
      ->getEditable('rules.reaction.' . $rule);
  }
  elseif (\Drupal::service('config.storage')
    ->exists('rules.component.' . $rule)) {
    $config = \Drupal::configFactory()
      ->getEditable('rules.component.' . $rule);
  }
  else {
    return drush_set_error('', dt('Could not find a Reaction Rule or a Rules Component named "@name".', [
      '@name' => $rule,
    ]));
  }
  if (drush_confirm(dt('Are you sure you want to delete the rule named "@name"? This action cannot be undone.', [
    '@name' => $rule,
  ]))) {
    $config
      ->delete();
    drush_log(dt('The rule "@name" has been deleted.', [
      '@name' => $rule,
    ]), 'success');
  }
  else {
    drush_user_abort();
  }
}