Skip to content

Commit

Permalink
Fixes #1460 Allow for Delayed Configuration Overrides. (#1471)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Green <chrisgreen@arizona.edu>
  • Loading branch information
2 people authored and joeparsons committed Apr 15, 2022
1 parent c842d61 commit 279317a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
5 changes: 4 additions & 1 deletion modules/custom/az_core/src/AZConfigOverride.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,14 @@ public function importOverrides(array $modules) {
$module_keys = array_flip($modules);
$extensions = array_intersect_key($module_list, $module_keys);

// Previously enabled extensions.
$old_extensions = array_diff_key($module_list, $module_keys);

// Ask the override provider for direct overrides available.
foreach ($providers as $provider) {
// Only query config for the Quickstart provider.
if ($provider instanceof QuickstartConfigProvider) {
$overrides = $provider->getOverrideConfig($extensions);
$overrides = $provider->getOverrideConfig($extensions, $old_extensions);

// Edit active configuration for each explicit override.
foreach ($overrides as $name => $data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,66 @@ public function addConfigToCreate(array &$config_to_create, StorageInterface $st
*
* @param \Drupal\Core\Extension\Extension[] $extensions
* An associative array of Extension objects, keyed by extension name.
* @param \Drupal\Core\Extension\Extension[] $old_extensions
* Already loaded Extension objects, keyed by extension name.
*
* @return array
* A list of the configuration data keyed by configuration object name.
*/
public function getOverrideConfig(array $extensions = []) {
public function getOverrideConfig(array $extensions = [], array $old_extensions = []) {

// Find the direct overrides for use at module install time.
$storage = $this->getExtensionInstallStorage(static::ID);
$config_names = $this->listConfig($storage, $extensions);
$data = $storage->readMultiple($config_names);

// Get active configuration to check dependencies with.
$existing_config = $this->getActiveStorages()->listAll();
$all_config = $this->getActiveStorages()->readMultiple($existing_config) + $data;
$enabled_extensions = $this->getEnabledExtensions();

// Get the install configuration present for the specified modules.
// We need to check if an already-enabled module contained passive override.
$install_storage = $this->getExtensionInstallStorage(InstallStorage::CONFIG_INSTALL_DIRECTORY);
$install_config_names = $this->listConfig($install_storage, $extensions);

// Now compare to quickstart config of already-loaded modules;
// We are checking to see if an already loaded module contained a change
// that couldn't be loaded previously for dependency reasons.
$override_storage = $this->getExtensionInstallStorage(static::ID);
$override_config_names = $this->listConfig($override_storage, $old_extensions);
$intersect = array_intersect($override_config_names, $install_config_names);
$overrides = $storage->readMultiple($intersect);

// Merge passive overrides, eg. overrides to a new module from a module that
// had already been loaded.
$data = array_merge($data, $overrides);

// Add default config hash to overrides.
foreach ($data as $name => &$value) {
$value = $this->addDefaultConfigHash($value);
if (!$this->validateDependencies($name, $data, $enabled_extensions, $all_config)) {
// Couldn't validate dependency.
unset($data[$name]);
}
}
return $data;
}

/**
* {@inheritdoc}
*/
protected function validateDependencies($config_name, array $data, array $enabled_extensions, array $all_config) {

// Parent version does not account for simple config module dependencies.
if (!isset($data['dependencies'])) {
// Simple config or a config entity without dependencies.
list($provider) = explode('.', $config_name, 2);
return in_array($provider, $enabled_extensions, TRUE);
}
return parent::validateDependencies($config_name, $data, $enabled_extensions, $all_config);
}

/**
* {@inheritdoc}
*/
Expand Down
12 changes: 12 additions & 0 deletions modules/custom/az_security/az_security.install
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,15 @@
* @file
* Install, update and uninstall functions for az_security module.
*/

/**
* Delete seckit settings if they were mistakenly installed.
*/
function az_security_update_920101() {
$module_handler = \Drupal::service('module_handler');
if (!$module_handler->moduleExists('seckit')) {
// Remove seckit settings if they were installed too early.
$config_factory = \Drupal::service('config.factory');
$config_factory->getEditable('seckit.settings')->delete();
}
}

0 comments on commit 279317a

Please sign in to comment.