You are here

public function SecurityReview::cleanStorage in Security Review 8

Deletes orphaned check data.

File

src/SecurityReview.php, line 261

Class

SecurityReview
A class containing static methods regarding the module's configuration.

Namespace

Drupal\security_review

Code

public function cleanStorage() {

  /** @var \Drupal\security_review\Checklist $checklist */
  $checklist = \Drupal::service('security_review.checklist');

  // Get list of check configuration names.
  $orphaned = $this->configFactory
    ->listAll('security_review.check.');

  // Remove items that are used by the checks.
  foreach ($checklist
    ->getChecks() as $check) {
    $key = array_search('security_review.check.' . $check
      ->id(), $orphaned);
    if ($key !== FALSE) {
      unset($orphaned[$key]);
    }
  }

  // Delete orphaned configuration data.
  foreach ($orphaned as $config_name) {
    $config = $this->configFactory
      ->getEditable($config_name);
    $config
      ->delete();
  }
}