Commit 79659dcd authored by catch's avatar catch

Issue #2056445 by alexpott, Marcus Maihoff, rahul.shinde: Ensure that all...

Issue #2056445 by alexpott, Marcus Maihoff, rahul.shinde: Ensure that all config can not be deleted using the config importer.
parent 09ff81ae
......@@ -90,10 +90,10 @@ function testEmptyImportFails() {
try {
$this->container->get('config.storage.staging')->deleteAll();
$this->configImporter->reset()->import();
$this->assertFalse(FALSE, "ConfigImporterException not thrown, we didn't stop an empty import.");
$this->fail('ConfigImporterException thrown, successfully stopping an empty import.');
}
catch (ConfigImporterException $e) {
$this->assertTrue(TRUE, 'ConfigImporterException thrown, successfully stopping an empty import.');
$this->pass('ConfigImporterException thrown, successfully stopping an empty import.');
}
}
......
<?php
/**
* @file
* Contains \Drupal\system\SystemConfigSubscriber.
......@@ -6,10 +7,8 @@
namespace Drupal\system;
use Drupal\Core\Config\Config;
use Drupal\Core\Config\ConfigImporterEvent;
use Drupal\Core\Config\ConfigImporterException;
use Drupal\Core\Config\ConfigEvent;
use Drupal\Core\Config\StorageDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
......@@ -19,18 +18,26 @@
class SystemConfigSubscriber implements EventSubscriberInterface {
/**
* Implements EventSubscriberInterface::getSubscribedEvents().
* {@inheritdoc}
*/
static function getSubscribedEvents() {
$events['config.importer.validate'][] = array('onConfigImporterValidate', 20);
return $events;
}
/**
* Checks that the import source storage is not empty.
*
* @param ConfigImporterEvent $event
* The config import event.
*
* @throws \Drupal\Core\Config\ConfigImporterException
* Exception thrown if the source storage is empty.
*/
public function onConfigImporterValidate(ConfigImporterEvent $event) {
$importer = $event->getConfigImporter();
$importList = $importer->getStorageComparer()->getSourceStorage()->listAll();
if (empty($importerList)) {
throw new ConfigImporterException("This import will delete all your active configuration, I'm bailing out now.");
$importList = $event->getConfigImporter()->getStorageComparer()->getSourceStorage()->listAll();
if (empty($importList)) {
throw new ConfigImporterException('This import is empty and if applied would delete all of your configuration, so has been rejected.');
}
}
}
......
......@@ -20,3 +20,7 @@ services:
arguments: ['@batch.storage']
tags:
- { name: theme_negotiator, priority: 1000 }
system.config_subscriber:
class: Drupal\system\SystemConfigSubscriber
tags:
- { name: event_subscriber }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment