Problem/Motivation
When active configuration was stored in files very early access to $config_directories
was necessary. That's no longer the case. Let's move it to $settings so it is more injectable into services, have less globals, and at the same time clean up:
config_get_config_directory()
CONFIG_SYNC_DIRECTORY
Additionally whilst we clear this up we could take the opportunity to reduce the ability to set multiple directories to a single sync directory. The support for multiple directories stems from a early CMI development in which the active config was also read from files. Later it was decided to have the active config storage by default in the database for several good reasons (performance, security, etc). So Drupal core only uses one config directory for the synchronisation.
Proposed resolution
We've decided to support only the config sync directory - see #13.
Only support sync directory
- Use
$settings['config_sync_directory']
instead of$config_directories[CONFIG_SYNC_DIRECTORY]
in settings.php. - Deprecate
CONFIG_SYNC_DIRECTORY
- Deprecate
config_get_config_directory()
and recommendSettings::get('config_sync_directory')
instead. - Deprecate
drupal_install_config_directories()
Support multiple
Move global $config_directories to$settings['config_directories']
AddSettings::getConfigDirectory()
and deprecateconfig_get_config_directory()
MoveCONFIG_SYNC_DIRECTORY
to StorageInterface::SYNC_DIRECTORY
Remaining tasks
User interface changes
None
API changes
- Use
$settings['config_sync_directory']
instead of$config_directories[CONFIG_SYNC_DIRECTORY]
in settings.php. - Deprecate
CONFIG_SYNC_DIRECTORY
- Deprecate
config_get_config_directory()
and recommendSettings::get('config_sync_directory')
instead. - Deprecate
drupal_install_config_directories()
Data model changes
None
Release notes snippet
The configuration sync directory is now defined in $settings['config_sync_directory']
in settings.php.
The use of $config_directories
is deprecated in Drupal 8.8 and will be removed from Drupal 9. See https://www.drupal.org/node/3018145 for more information.
Comment | File | Size | Author |
---|---|---|---|
#59 | 2980712-2-59.patch | 65.58 KB | alexpott |
#59 | 53-59-interdiff.txt | 1.71 KB | alexpott |
#53 | 2980712-53.patch | 64.55 KB | bircher |
#53 | interdiff-2980712-48-53.txt | 1.5 KB | bircher |
#48 | 2980712-48.patch | 64.56 KB | yogeshmpawar |
Comments
Comment #2
moshe weitzman CreditAttribution: moshe weitzman as a volunteer commentedThis is a good cleanup IMO.
Comment #4
lpeabody CreditAttribution: lpeabody commentedJust going to throw this out there for those who use the platform, but in my experience Acquia Cloud Site Factory no longer provides a mechanism to detect what the installed site profile is at the settings.php file at run time. If this change was added I'm pretty sure this would hose a lot of ACSF subscriptions.
EDIT: I am in no way implying that Drupal should be built around ACSF ;)
Comment #5
alexpottHere's a attempt - I duplicated this issue at #3018015: Move the $config_directories to $settings so it can be accessed via the Settings singleton
Comment #6
andypostComment #7
alexpottSo #5 moves the
$config_directories
global to$settings['config_directories']
. If we are going to do this I think it is also worth discussing whether or not we make it$settings['config_sync_directory'}
and stop supporting multiple directories in core. I think this could make sense but it would be great to have more opinions. One advantage of the current situation is that you can write code that deals with config and it can scan all the config_directories and provide generic functionality. If we make it a single value and not an array then we lose that functionality.Comment #8
alexpottUpdated the IS to reflect the 2 solutions and the choice we should be making on this issue.
Comment #9
alexpottComment #11
alexpottComment #13
alexpottDiscussed the multiple config directories vs the single configuration sync directory with @bircher in Slack. Here's our discussion:
bircher [11:07 AM]
alexpott [11:09 AM]
bircher [11:17 AM]
alexpott [11:22 AM]
bircher [11:29 AM]
Comment #14
alexpottHere's a patch that only supports the sync directory and moves it to
$settings['config_sync_directory']
Comment #15
moshe weitzman CreditAttribution: moshe weitzman as a volunteer commentedI support the switch to one directory. Its much clearer for the common use case.
Comment #16
andypostComment #18
alexpott@andypost yep but I don't think a general refactor of Settings and how we do that means we should not try to centralise our current globals on it. Once everything is in Settings is becomes easier to consider how to fix all the global application settings in one go.
Comment #19
alexpottHere's some more work. We can deprecate some other methods that don't make much sense.
Comment #20
andypost@alexpott yep, totally agree - iterative approach makes the whole picture clear
Comment #21
alexpottI've reverted some changes to deprecated functions because if a function is deprecated then there is no point taking the risk to update the code. Also updated default.settings.php. This shows us that some people were at one point very very keen to keep active configuration in the filesystem. With this change that probably comes trickier but CONFIG_ACTIVE_DIRECTORY has been deprecated for a very long time.
Comment #23
alexpottComment #25
alexpottComment #26
alexpottComment #27
alexpottComment #28
alexpottWe can do a slightly better deprecation in Settings so it has less unrelated impact.
Comment #29
mpotter CreditAttribution: mpotter at Phase2 commentedHere is a reroll against latest 8.7.x. My Mac interdiff utility gives an error when trying to create it but I can't pin down why. But there were some changed in tests so #28 failed to apply. Also, calls to `file_prepare_directory()` were removed in core and replaced with `\Drupal::service('file_system')->prepareDirectory()` so I made that change to the new tests also.
Comment #31
bircherSo I tried re-rolling the patch from #28 and I ended up with a different diff to 8.7.x.
Attached is the interdiff from my re-roll of #28 to #29.
The additional file_system service usage makes sense so I incorporated them also in this patch.
Comment #32
bircherWhile re-rolling I noticed the following:
What does this mean?
Comment #33
alexpottNot sure about this @todo anymore either. Not sure why we'd both injecting anything here. So early in the installer. I guess the current HEAD behaviour here is that we would throw an exception if the directory was not configured. I guess we should continue to do that.
I guess the thing is before we would have thrown an exception if config_get_config_directory() was unable to determine a directory. Now we don't. Which makes things a bit more fragile because we're not throwing an early error.
Comment #35
bircherAttached a fixed reroll patch.
I removed the two todos because I checked and it is not necessary to do anything further.
I went through the list of code occurrences of
get('config_sync_directory'
to see where we use the new settings. And they are replacing where we currently directly access the global variable (so no exception) or they have the same outcome also without the exception.The only thing where we don't throw the exception is in
FileStorageFactory::getSync
so I added a patch that does that.Comment #36
bircheradding a test for the exception.
Comment #37
mpotter CreditAttribution: mpotter at Phase2 commentedDo we still need to reference drupal_install_config_directories() since it's being deprecated and the issue reference should cover it?
Is this the correct reference? Others here are for https://www.drupal.org/node/3018145
Do we still need to reference config_get_config_directory() here?
We reference 'config_sync_directory' a LOT now. Should this be a new constant? (We can't reuse CONFIG_SYNC_DIRECTORY though).
What do we mean by "or is not set up"? Could change to "In case the sync directory does not exist or is not defined in $settings['config_sync_directory']"
See above comment for improved exception message.
Previously we encapsulated this code into the drupal_install_config_directories() function. With that function deprecated, I still wonder about splitting this code into a helper function for readability. Perhaps a protected drupal_install_config_directory().
Is this related to the config_sync_directory change or some other bug fix?
This doesn't seem related to this issue. The check for $phase of "runtime" around this was removed and not sure how that's related to the config_sync_directory.
This is the same comment as for InstallerConfigDirectorySetNoDirectoryTest.php, so one of the comments is probably incorrect.
If changing the exception message above, change it here too.
Comment #39
bircherI had to re-roll the patch, so the interdiff is not really all that correct I think as I might have changed something inadvertently.
#37
1) yes, changed
2) true, changed
3) no, changed
4) I think it is fine, usually settings keys are referenced by their string values. Also we can add a constant in a followup if we really want to.
5) changed the string as suggested.
6) see 5
7) sure, added a method
8) I think this is related to the tests needing the settings now in places they didn't before, attached is a patch without that change.
9) I think this is related to the code later down the function needing the settings singleton set up, but attached is also a patch without that change.
10) They are almost the same test, and test almost the same thing, one is the new one and one is legacy functionality one. I removed the underscore since that makes one think about the variable.
11) see 5
Comment #40
bircher#37
8 & 9, so patches without that pass so this was unrelated improvements so attached is a patch without it.
Comment #41
alexpottWe need to update all the deprecations to 8.8.0 - and lets use the new format.
@deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use...
There's more than just this one... also the @trigger_error()'s use the same format.
Comment #42
bircherOf course! thanks for catching that, yes we are in 8.8 now.
Comment #44
yogeshmpawarComment #45
yogeshmpawarUpdated patch with an interdiff.
Comment #46
borisson_Most of this looks really good already, I found some nitpicks but haven't read everything yet.
I did not know this, but we have a precedent of doing this.
This should probably be protected instead of private?
80 cols.
I think this todo can be removed?
Comment #47
yogeshmpawarComment #48
yogeshmpawarComments addressed in #46 & added an interdiff as well.
Comment #49
borisson_As far as I understand it, this seems like a good way to deprecate the old way of doing things.
Comment #51
borisson_Back to rtbc, looks like that was a random fail.
Comment #52
catchThis exception message reads wrong to me - shouldn't it just say 'The config sync directory is not defined in $settings['config_sync_directory']'?
Comment #53
bircher#52 Oh of course!
Comment #54
bircherI added the Release notes snippet too so that it won't get held up by that in the end.
Comment #55
borisson_The exception was changed to @catch's suggestion, back to rtbc.
Comment #57
borisson_Retesting because the error message indicated that the failure probably had nothing to do with this patch.
Comment #58
borisson_I came back to check if the test was green after I put it on rtbc earlier this morning, I noticed that this is introducing 3 new CS errors, we should fix those as well, back to NW for that small change.
Comment #59
alexpottFixed up the coding standards
Comment #61
alexpottComment #63
catchCommitted 1a2babd and pushed to 8.8.x. Thanks!
Comment #64
xjmThis has been reported to be a disruptive change; can we get a release note? (Edit: And/or update the CR to clarify that there isn't actually a break and merely a deprecation, depending on what's actually the case here.)
Comment #65
bircherI added a sentence about the depreciation. Is that what you would expect? We could add a link to the chance notice.
Comment #66
bircherComment #67
xjmThanks @bircher. So based on that note, the old API will continue to work and there's no impact on existing sites? (Is the same also true of the related functions and constants?) If so (if there's no actual disruptions in D8) let's instead update the CR to clarify that for all of them. (Deprecation is mentioned for some but not all of the affected APIs.)
Comment #68
BerdirI think this is worth mentioning. The important change here isn't the API changes, those are mostly internal and probably almost nobody uses them except some config-related modules.
The change that affects every site is that site owners need to update their settings.php file and change the generated PHP code (or the one they adjusted themself) to something else. And that seems worth mentioning. It doesn't break D8 in any way, but users need to do this before updating to D9.
Comment #69
bircherYes everything continues to work for Drupal 8. This is a Drupal 9 thing which sites have a chance to adopt from 8.8.0 onwards. As Berdir correctly pointed out the deprecated functions are most likely not widely used but the change in settings.php affects everyone.
But since this is literally just a global php variable it is not complex to continue using it in custom code.
Comment #70
webchickJust a reminder that we're trying really hard to make Drupal 9 easy to upgrade to. We should try and minimize these kinds of "all site owners need to..." changes outside of major/critical issues, IMO. (Not arguing for rolling this back, per se, just a general plea to consider "downstream" impact of DX improvements in general, especially this late in D8's lifetime.)
Comment #71
moshe weitzman CreditAttribution: moshe weitzman as a volunteer commentedif not in a major version, when are we supposed to make a change like this? IMO we should be making more cleanups in Drupal 9, not less.
Comment #72
alexpottComment #73
bircherI understand that we want to limit the amount of deprecations for Drupal 9 to be easier to upgrade to. But at the same time this issue has caused confusion and false hope that CMI (1) was going to be more than it was because the current array came to be an array in early days of CMI and it just wasn't a priority to clean it up before 8.0.0. So people (me included) saw an array and automatically assumed that there should be more than one key when core only ever supported one.
On the bright side the work for updating it is in almost all cases a simple string replace away. And a site is not broken if it is not done, just the config import won't work and there is an insructive error message.
Comment #74
bircherI think the reason this was re-opened is addressed.