SystemConfigSubscriber.php 1.24 KB
Newer Older
1
<?php
2

3 4 5 6 7 8 9 10
/**
 * @file
 * Contains \Drupal\system\SystemConfigSubscriber.
 */

namespace Drupal\system;

use Drupal\Core\Config\ConfigImporterEvent;
11 12
use Drupal\Core\Config\ConfigImportValidateEventSubscriberBase;
use Drupal\Core\Config\StorageDispatcher;
13 14 15 16

/**
 * System Config subscriber.
 */
17
class SystemConfigSubscriber extends ConfigImportValidateEventSubscriberBase {
18 19

  /**
20 21 22 23 24
   * Checks that the configuration synchronization is valid.
   *
   * This event listener implements two checks:
   *   - prevents deleting all configuration.
   *   - checks that the system.site:uuid's in the source and target match.
25 26 27 28
   *
   * @param ConfigImporterEvent $event
   *   The config import event.
   */
29
  public function onConfigImporterValidate(ConfigImporterEvent $event) {
30 31
    $importList = $event->getConfigImporter()->getStorageComparer()->getSourceStorage()->listAll();
    if (empty($importList)) {
32 33 34 35
      $event->getConfigImporter()->logError($this->t('This import is empty and if applied would delete all of your configuration, so has been rejected.'));
    }
    if (!$event->getConfigImporter()->getStorageComparer()->validateSiteUuid()) {
      $event->getConfigImporter()->logError($this->t('Site UUID in source storage does not match the target storage.'));
36 37 38
    }
  }
}