Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Globals should be replaced by the Drupal\Component\Utility\Settings
singleton.
This patch will convert all usages of the global $databases;
.
Comment | File | Size | Author |
---|---|---|---|
#21 | 18-20-interdiff.txt | 10.86 KB | alexpott |
#21 | 1951216.database-settings.20.patch | 17.6 KB | alexpott |
#18 | drupal-1951216-18.patch | 16.25 KB | dawehner |
#18 | interdiff.txt | 3.52 KB | dawehner |
#13 | interdiff.txt | 2.8 KB | dawehner |
Comments
Comment #1
alexpottPatch attach removes
global $databases;
...Drush site install breaks :( ... attached a patch that fixes this :)
Comment #3
alexpottOk messed up in
_drupal_initialize_db_test_prefix()
... new patch to address... also forget to include default.settings.phpComment #5
alexpottNeither Drupal\system\Tests\Theme\ThemeTest or Drupal\update\Tests\UpdateUploadTest fail locally... assume something has gone wrong with the bot's file system... pressing the retest button :)
Comment #6
alexpott#3: 1951216.database-settings.3.patch queued for re-testing.
Comment #7
dawehnerShouldn't there be some code which uses drupal_rewrite_settings() to replace existing settings for the upgrade?
Ups, two semicolons.
Comment #8
Dave ReidDo we also need to discuss the security implications of having the database settings (which includes passwords) moved to a different place?
Comment #9
moshe weitzman CreditAttribution: moshe weitzman commentedThis looks good - just have to address #7.
Comment #10
dawehnerWell ... we certainly don't have the perfect test coverage.
I'm totally not sure about the changes in drupal_rewrite_settings(). Note: This doesn't work yet.
Comment #11
dawehnerLet's better wait on #1949724: Allow simpletest child sites to additionally load a test-specific settings.php to allow testing anonymous and configless updates
Comment #12
Crell CreditAttribution: Crell commentedAs long as we're doing this (which I support), we should pull this hard dependency out entirely. Pass the settings array into parseConnectionInfo(), and have code elsewhere that grabs it from settings and passes it in.
Comment #13
dawehner#1811730: Refactor Database to rely on the DIC solely seems to be a really related issue, especially because it does the same as this issue but way more.
This approach feels not perfect for now, but it allows you to refactor (maybe in that linked issue) way more.
Comment #15
Crell CreditAttribution: Crell commentedUnfortunately chx tried to get #1811730: Refactor Database to rely on the DIC solely to work, and we kept running into issues that we likely cannot resolve any time soon. So let's at least do the minimum we are able to here, and maybe save the other issue for later.
Why is this a separate method from parseConnectionInfo()?
Comment #16
dawehnerWell, basically the problem was that Database::parseConnectionInfo() is called all over the place in the Database class, it didn't saw a better way to do it.
Comment #17
Crell CreditAttribution: Crell commentedHm. Mostly it's called for lazy-init purposes. I'd be fine with dropping the lazy init and expecting parseConnectionInfo() to always be called before the class is useful. We actually have a couple of different ways to add connection information to the system; I'm fine with "it's your job to make sure there's something there before you call it, yo!"
Comment #18
dawehnerAfter starting to work on that I realize that we would require the DB to open a connection via the container:
Is there a way to get the settings service, call get() on there and pass that into a function call of parseConnectionInfo() in order to
bootstrap that before getConnection() can return the connection?
So i'm wondering whether we should really try to limit the scope of the issue and do the injection later?
Comment #19
BerdirWe already failed twice with putting the database in the container, so +1 for limiting the scope of this issue as much as possible.
Comment #20
Crell CreditAttribution: Crell commentedAgreed with Berdir. Let's not deal with the Container in this issue.
This is the wrong exception to trow. With this change, "parsing" isn't a thing. There's parseConnectionInfo() which sets a bunch of connections at once, and there's addConnectionInfo(). You could use either one and it would work, so parseConnectionInfo() isn't required at all. What you want to throw is ConnectionNotDefinedException, which is already listed.
Basically, all we need to do here is assume that a dev has setup a connection info one way or another before calling getConnection(). If he didn't he gets an exception, which is already covered by openConnection().
Comment #21
alexpottSpent a morning fighting with the d7 to d8 upgrade path - we have some serious issues at the moment.
The patch returns to just converting
global $databases
toSettings
. So just doing the minimum.The patch attached will work if settings.php is writable. If not... we are going to bomb out - the question is how. Current HEAD will WSOD because drupal_install_config_directories will fail to rewrite the settings. Which throw an exception and drupal's current error handler relies on the container and config! Having a write protected settings file at the start of the update process is a reasonable assumption since Drupal warns you all the time about this!
So the patch attached addresses this by admitting that if we want something on the screen and we don't have a db (or have a D7 db) and don't have config directories and don't have a container then we might as well forget about the maintenance theme and drupal's existing error handler.
If your settings.php is unwritable and it tries to write during update_prepare_d8_bootstrap() and you are updating from D7 to D8 with this patch you'll see the following actually helpful message.
Comment #22
alexpottComment #23
gddWell UPGRADE.txt specifically says to make your settings.php writable, so we don't need to worry about the situation where it isn't thankfully.
Don't we have some kind of check_requirements() thing we do before upgrading just like we do before installing? That sure would be helpful for this kind of thing.
Comment #24
alexpottYes we do... but the patch in #21 removes it because we were never going to get to the requirement checking because
drupal_install_config_directories()
will fail to rewrite the settings before the requirement is checked!Basically a D7 database and sites/files with a Drupal 8 codebase is a broken Drupal :)
Comment #25
jibran#21: 1951216.database-settings.20.patch queued for re-testing.
Comment #27
sunI wasn't aware of this issue and worked on + completed a much simpler patch in #2176621: Remove global $databases
Actually, I disagree with the concrete proposal here, for two discrete reasons:
It's perfectly fine if a module adds a custom connection on-demand, or, considering the testing framework, to swap out connections.
Doing so will only mean that the two stores can get out of sync.
Anyway, I suggest to do #2176621 first, and if deems to be a good idea, we can still come back to this.
Comment #28
alexpottI agree - marking this as won't fix in favour of #2176621: Remove global $databases