Issue #2148199 by cilefen, attila.fekete, mtift | alexpott: Use snapshot to warn users if the configuration has changed since last import.
parent
86922ace3f
commit
fcc5b6237e
|
@ -37,18 +37,25 @@ class ConfigSync extends FormBase {
|
||||||
protected $lock;
|
protected $lock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The source configuration object.
|
* The staging configuration object.
|
||||||
*
|
*
|
||||||
* @var \Drupal\Core\Config\StorageInterface
|
* @var \Drupal\Core\Config\StorageInterface
|
||||||
*/
|
*/
|
||||||
protected $sourceStorage;
|
protected $stagingStorage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The target configuration object.
|
* The active configuration object.
|
||||||
*
|
*
|
||||||
* @var \Drupal\Core\Config\StorageInterface
|
* @var \Drupal\Core\Config\StorageInterface
|
||||||
*/
|
*/
|
||||||
protected $targetStorage;
|
protected $activeStorage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The snapshot configuration object.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Config\StorageInterface
|
||||||
|
*/
|
||||||
|
protected $snapshotStorage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event dispatcher.
|
* Event dispatcher.
|
||||||
|
@ -95,10 +102,12 @@ class ConfigSync extends FormBase {
|
||||||
/**
|
/**
|
||||||
* Constructs the object.
|
* Constructs the object.
|
||||||
*
|
*
|
||||||
* @param \Drupal\Core\Config\StorageInterface $sourceStorage
|
* @param \Drupal\Core\Config\StorageInterface $staging_storage
|
||||||
* The source storage object.
|
* The source storage.
|
||||||
* @param \Drupal\Core\Config\StorageInterface $targetStorage
|
* @param \Drupal\Core\Config\StorageInterface $active_storage
|
||||||
* The target storage manager.
|
* The target storage.
|
||||||
|
* @param \Drupal\Core\Config\StorageInterface $snapshot_storage
|
||||||
|
* The snapshot storage.
|
||||||
* @param \Drupal\Core\Lock\LockBackendInterface $lock
|
* @param \Drupal\Core\Lock\LockBackendInterface $lock
|
||||||
* The lock object.
|
* The lock object.
|
||||||
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
|
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
|
||||||
|
@ -114,9 +123,10 @@ class ConfigSync extends FormBase {
|
||||||
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
|
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
|
||||||
* The theme handler
|
* The theme handler
|
||||||
*/
|
*/
|
||||||
public function __construct(StorageInterface $sourceStorage, StorageInterface $targetStorage, LockBackendInterface $lock, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, UrlGeneratorInterface $url_generator, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) {
|
public function __construct(StorageInterface $staging_storage, StorageInterface $active_storage, StorageInterface $snapshot_storage, LockBackendInterface $lock, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, UrlGeneratorInterface $url_generator, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) {
|
||||||
$this->sourceStorage = $sourceStorage;
|
$this->stagingStorage = $staging_storage;
|
||||||
$this->targetStorage = $targetStorage;
|
$this->activeStorage = $active_storage;
|
||||||
|
$this->snapshotStorage = $snapshot_storage;
|
||||||
$this->lock = $lock;
|
$this->lock = $lock;
|
||||||
$this->eventDispatcher = $event_dispatcher;
|
$this->eventDispatcher = $event_dispatcher;
|
||||||
$this->configManager = $config_manager;
|
$this->configManager = $config_manager;
|
||||||
|
@ -133,6 +143,7 @@ class ConfigSync extends FormBase {
|
||||||
return new static(
|
return new static(
|
||||||
$container->get('config.storage.staging'),
|
$container->get('config.storage.staging'),
|
||||||
$container->get('config.storage'),
|
$container->get('config.storage'),
|
||||||
|
$container->get('config.storage.snapshot'),
|
||||||
$container->get('lock'),
|
$container->get('lock'),
|
||||||
$container->get('event_dispatcher'),
|
$container->get('event_dispatcher'),
|
||||||
$container->get('config.manager'),
|
$container->get('config.manager'),
|
||||||
|
@ -154,14 +165,35 @@ class ConfigSync extends FormBase {
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||||
|
$snapshot_comparer = new StorageComparer($this->activeStorage, $this->snapshotStorage, $this->configManager);
|
||||||
|
if (empty($form_state['input']) && $snapshot_comparer->createChangelist()->hasChanges()) {
|
||||||
|
$change_list = array();
|
||||||
|
foreach ($snapshot_comparer->getAllCollectionNames() as $collection) {
|
||||||
|
foreach ($snapshot_comparer->getChangelist(NULL, $collection) as $config_names) {
|
||||||
|
if (empty($config_names)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
foreach ($config_names as $config_name) {
|
||||||
|
$change_list[] = $config_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort($change_list);
|
||||||
|
$change_list_render = array(
|
||||||
|
'#theme' => 'item_list',
|
||||||
|
'#items' => $change_list,
|
||||||
|
);
|
||||||
|
$change_list_html = drupal_render($change_list_render);
|
||||||
|
drupal_set_message($this->t('Your current configuration has changed. Changes to these configuration items will be lost on the next synchronization: !changes', array('!changes' => $change_list_html)), 'warning');
|
||||||
|
}
|
||||||
$form['actions'] = array('#type' => 'actions');
|
$form['actions'] = array('#type' => 'actions');
|
||||||
$form['actions']['submit'] = array(
|
$form['actions']['submit'] = array(
|
||||||
'#type' => 'submit',
|
'#type' => 'submit',
|
||||||
'#value' => $this->t('Import all'),
|
'#value' => $this->t('Import all'),
|
||||||
);
|
);
|
||||||
|
|
||||||
$source_list = $this->sourceStorage->listAll();
|
$source_list = $this->stagingStorage->listAll();
|
||||||
$storage_comparer = new StorageComparer($this->sourceStorage, $this->targetStorage, $this->configManager);
|
$storage_comparer = new StorageComparer($this->stagingStorage, $this->activeStorage, $this->configManager);
|
||||||
if (empty($source_list) || !$storage_comparer->createChangelist()->hasChanges()) {
|
if (empty($source_list) || !$storage_comparer->createChangelist()->hasChanges()) {
|
||||||
$form['no_changes'] = array(
|
$form['no_changes'] = array(
|
||||||
'#type' => 'table',
|
'#type' => 'table',
|
||||||
|
|
|
@ -121,6 +121,12 @@ class ConfigExportImportUITest extends WebTestBase {
|
||||||
|
|
||||||
$this->drupalGet('node/add');
|
$this->drupalGet('node/add');
|
||||||
$this->assertFieldByName("{$this->fieldName}[0][value]", '', 'Widget is displayed');
|
$this->assertFieldByName("{$this->fieldName}[0][value]", '', 'Widget is displayed');
|
||||||
|
|
||||||
|
\Drupal::config('system.site')
|
||||||
|
->set('slogan', $this->originalSlogan)
|
||||||
|
->save();
|
||||||
|
$this->drupalGet('admin/config/development/configuration');
|
||||||
|
$this->assertText('Your current configuration has changed. Changes to these configuration items will be lost on the next synchronization: system.site');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue