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.
Problem/Motivation
The minimal drupal_container() disregards container_bundles overrides, is a maintenance nightmare and makes services not available properly in the installer and the update.
Proposed resolution
This patch converts the installer to use the kernel as early as possible and adds a kernel to every full bootstrap.
Remaining tasks
File issues for installer and the update to make sure they do not call not working services.
Related issues
- #1806334: Replace the node listing at /node with a view
- #1798732: Convert install_task, install_time and install_current_batch to use the state system
API changes
TBD.
Comment | File | Size | Author |
---|---|---|---|
#55 | 1849004_55.patch | 26.98 KB | chx |
#53 | 1849004_53.patch | 26.92 KB | chx |
#46 | 1849004_46.patch | 26.55 KB | chx |
#46 | interdiff.txt | 3.15 KB | chx |
#38 | container-1849004-38.patch | 25.29 KB | xjm |
Comments
Comment #1
chx CreditAttribution: chx commentedComment #2
xjmComment #4
chx CreditAttribution: chx commentedThis quite likely fixes all the language problems which come from language not using the DIC. (Also I removed some cruft from earlier fixes)
I attached the stack trace to the offending function hoping someone will fix language and we can eventually get rid of this bootstrapping
Comment #6
chx CreditAttribution: chx commentedOne by one, the falling tests fell to the power of the Kernel...
We should switch from bundles to YAML files btw to discourage people from calling code left and right in bundles.
Comment #7
aspilicious CreditAttribution: aspilicious commentedI'm going to try to run a manual upgrade. I'm curious if this fixes some of the weird things I have been seeing.
Comment #8
aspilicious CreditAttribution: aspilicious commentedChx! You made my day. This removes all kinds of nasty stuff that happened during an upgrade. For the first time in weeks I was able to perform a smooth upgrade.
Tempted to mark this rtbc but I'm going to wait so others can have a look.
Comment #9
Crell CreditAttribution: Crell commentedIt looks like this makes all Drupal instances use the same kernel, whereas #1530756: [meta] Use a proper kernel for the installer is trying to give each front-end its own kernel. I'm not sure how well that works.
If we were to use the same kernel class, shouldn't we then have an alternate environment, "install", instead of "prod"? (Symfony full stack has prod, dev, and "test".) That would allow us to use different containers in different situations but with the same kernel, but allow them to overlap as needed.
Which, thinking about it, maybe that's all we need...?
Comment #10
chx CreditAttribution: chx commentedChanged to 'install' and removed that pesky BOOTSTRAP_CODE in DrupalKernel which was only necessary for some file writing operations. Wrote more drupal_container doxygen.
Comment #12
sunThis does not look bad, but I have a couple of larger concerns with regard to some of the changes:
As mentioned over in #1848998: Problems with update_module_enable(), I don't think we can boot a regular kernel in update.php.
At minimum, that kernel should probably use 'update' as environment identifier. But what's far more concerning is that update.php may very well not be able to boot a kernel with regular services + bundles at all, since service definitions/storages/schemata/namespaces/bundles/etc might have changed.
I actually think it would be better to leave the update.php changes out of this patch.
This will boot two kernels in the later installer steps, one with 'install' and one with 'prod' environment — I don't see why that is needed?
What would make sense to me in terms of separate environments/kernels is to have an 'installer' environment kernel for the first/initial installer steps that are operating in a crippled environment.
Lastly, I'm not really fond of introducing a new, magic global $kernel state variable. This makes the bootstrap harder to follow and can easily have unintended consequences.
These changes reveal that PhpStorage\FileStorage is not properly decoupled from Drupal yet, so it shouldn't actually be in Drupal\Component or have an appropriate class extension/override in Drupal\Core.
Let's make sure to create a dedicated issue for that.
Essentially what I mentioned above already, there's no guarantee that this call to
drupal_bootstrap()
will not bootstrap a new kernel - which would inherently mean a new service container with a new HttpKernel.D'oh. :)
It might make sense to split this fix out into a separate issue ;)
Comment #13
Letharion CreditAttribution: Letharion commentedCreated #1849636: Refer to the forum container as 'forum container', not just 'container', in forum tests to break out the forum variable rename part.
Comment #14
chx CreditAttribution: chx commentedWe have a much better mechanism in drupal_bootstrap now that makes sure to only instantiate a container if one is not available yet.
We need update.php changes otherwise this won't pass. Should we find that update.php breaks with regular services we can break out the overrides however the reason I asked for YAML above for the service container is to make sure people dont break things during registration. Of course YAML would have performance problems when not using compiled containers -- like testing -- so let's leave that for later.
For php storage, one of the decoupling is done the other has a todo.
I am not breaking out the forum fix in a separate fix not when the taxonomy item now for more than a week blocks the efq relationships patch. I will not have this patch held up infinitely by a separate issue.
Comment #15
chx CreditAttribution: chx commentedComment #16
chx CreditAttribution: chx commented#1849570: Remove file.inc ties and fix unlink while at it in MTimeProtectedFastFileStorage
Comment #17
chx CreditAttribution: chx commentedSorry forgot to attach an interdiff.
Comment #18
chx CreditAttribution: chx commentedAnd while I know that the ternary does not copy objects themselves it certainly copies the object handler and drupal_container is called enough that I care.
Comment #19
chx CreditAttribution: chx commentedAnd, I found more code to be nuked in DrupalKernel this time. Since TestBase::setup/tearDown already takes care of saving and restoring the container, well that was not needed. Simplified drupal_container() even further. (We are at 61 LoC removed at this point.)
For simpler reviews, the interdiff to #10 the last reviewed is also attached.
Comment #20
chx CreditAttribution: chx commentedThis round is katbailey's request, just moving the bootstrap call into index.php.
Comment #21
chx CreditAttribution: chx commentedAdded a $kernel->boot , it is not even worth an interdiff.
Comment #22
katbailey CreditAttribution: katbailey commentedThat won't work, it needs to happen after the container has been built - why can't we leave it inside the kernel's boot() method?
Comment #23
katbailey CreditAttribution: katbailey commented#22 was in response to #20, not #21 - I still don't understand why it couldn't have been left where it was :-/
Comment #24
chx CreditAttribution: chx commentedBecause we really dont want the kernel to elevate bootstrap given that oftentimes that simply doesn't work... install, update, etc. We need to make the services available even if some of them are not correct. It's not ideal but I have no better idea.
Comment #25
chx CreditAttribution: chx commentedQuite probably (in a followup, I think) we want install and update override / nuke the 'unsafe' ones in respeective overrides.
Comment #26
katbailey CreditAttribution: katbailey commentedOK, chx explained to me in IRC that we sometimes want a kernel but do not want to bootstrap all the way, so I'm ok with the separate call to $kernel->boot() as a way around this. And it does in fact make things more consistent - seeing as we call boot() separately everywhere else we instantiate a kernel.
Comment #27
chx CreditAttribution: chx commentedWhat kat didn't post here but she did in IRC: "I think I am deliriously happy with the rest of it :-D "
Comment #28
chx CreditAttribution: chx commentedIn case you are wondering how #20 can pass, that's somewhat easy -- _drupal_bootstrap_kernel creates a kernel, puts a container into drupal_container() which soon gets overridden by the boot() called from $kernel->handle() ... so while it passed, it's a time waster.
#21 is correct.
Comment #28.0
chx CreditAttribution: chx commentedUpdated issue summary.
Comment #29
sunNote that #1798732: Convert install_task, install_time and install_current_batch to use the state system is much more pressing right now, because it unblocks a range of other features, whereas this patch does not.
Regardless of that, here's another review:
Note that all of the kernel instantiations are not respecting the constructor docs of DrupalKernel, which say that TRUE should be passed for the second $debug argument.
Thanks for trying to decouple the PhpStorage, but I don't think this change is correct — at least I can't see the relationship from
file_save_htaccess()
to MTimeProtectedFastFileStorage. The former is used for many other functionality that isn't related to PhpStorage.We should create an issue to convert file.inc into a FileSystem component, so this dependency can be properly resolved.
I think that both of these should specify 'prod' as environment. The fact that they are instantiated from install.php is not relevant - instead, what matters is that these kernels are used to install a production environment, so whatever meaning the environment identifier has or will have, it should trigger the same effects that would be triggered for the prod environment.
Under which circumstances would there be no keyvalue service? This looks odd to me, so we should make sure to document it in a comprehensible way (or remove it if it's not needed).
These changes look uncomfortable to me. It looks like the container can no longer be trusted.
I don't understand why the patch is catering for a possibly non-existing keyvalue service, but not any other service. I.e., IF the container is not reliable anymore, then there is also no guarantee that there is e.g. a database service in it, which in turn would have serious consequences.
Comment #30
chx CreditAttribution: chx commented> Note that all of the kernel instantiations are not respecting the constructor docs of DrupalKernel, which say that TRUE should be passed for the second $debug argument.
Sure, we can fix that... but index.php doesn't do that. So, separate issue.
> We should create an issue to convert file.inc into a FileSystem component, so this dependency can be properly resolved.
Note that file.inc needs to cope with wrappers while this can not cope with Drupal wrappers because the modules providing the wrappers are not loaded. So, FileSystem would not be a component not without converting every wrapper first into an annotated class. It's far, far beyond the scope of this issue.
> I think that both of these should specify 'prod' as environment.
Please, check with #9, Crell asked for 'install'.
> Under which circumstances would there be no keyvalue service?
> I don't understand why the patch is catering for a possibly non-existing keyvalue service
TestBase::setUp puts a completely empty container in drupal_container() which is somewhat the mirror of the empty environment being set up. Unit tests need not to waste time with getting a container set up for them. Drupal Unit Tests might just get away with a simple container holding the absolute bare minimum. So, the reason keyvalue is special cased in tearDown because state() attempts to use it and for unit tests it is not there and it'd blow up. It is special cased for Drupal Unit Tests in containerBuild becauise when a kernel is overridden then there's no need to re-register the keyvalue service but when a test is happy with the superminimal container put together in containerBuild it seems to need a keyvalue storage still -- that's why a memory service was added in the first place. Previously drupal_container() made sure there was a keyvalue service, Drupal Unit Tests still need it, so I added it.
Comment #31
xjmComment #32
Anonymous (not verified) CreditAttribution: Anonymous commenteda little off topic, but i agree with sun on this question - 'env' means something about prod, test, dev, staging etc. it does not mean 'type of front controller/kernel'. an app can ship with mulitple front controllers, all of which will should be tunable based on the different environments.
i may work with a Symfonian who conflated different front controllers and different envs, and i'd hate to see that confusion in Drupal 8.
(i looked at the installer kernel patch, but i don't understand it, as the InstallerKernel extends Symfony\Component\HttpKernel\HttpKernel, where as the Drupal kernel extends Symfony\Component\HttpKernel\Kernel, and i don't know why.)
Comment #33
sunI wasn't able to review the latest patch and read latest comments yet, sorry.
However, before we further continue to implant "the kernel" each and everywhere and dock our entire architecture onto it, I think that the comment in #1849700-11: DrupalKernel's container.modules param should contain module filenames, not full namespace paths could use a serious and well-founded answer.
Comment #34
chx CreditAttribution: chx commentedI think that sums it up.
Comment #35
chx CreditAttribution: chx commented#1850438: Establish DrupalKernel argument good practices is filed.
Comment #36
Letharion CreditAttribution: Letharion commented#1849636: Refer to the forum container as 'forum container', not just 'container', in forum tests is now commited.
Comment #37
chx CreditAttribution: chx commentedComment #38
xjmRebased and fixed a merge conflict.
Comment #39
katbailey CreditAttribution: katbailey commentedWhile I do side with sun and beejeebus on 'prod' versus 'install' for the $env parameter, it's not something I feel strongly about. I think all of the other concerns raised here have been adequately addressed, so I reckon this is good to go.
Comment #40
xjmThis resolves a critical bug. In HEAD, the plugin manager explodes the upgrade path, and it's consequently impossible to run
update.php
with Views installed. This patch fixes that.Comment #41
xjmIs @katbailey's (and @sun's and @beejeebus') concern regarding
$env
covered by #1850438: Establish DrupalKernel argument good practices?Comment #42
katbailey CreditAttribution: katbailey commentedOh, yes indeed it is. I should not have brought it up again - forget I said anything about that ;-)
Comment #43
webchickbootstrap.inc scares me. :) I'm hoping it scares catch less. :D
Comment #44
sunThe $rebuild argument seems to be obsolete.
Any particular reason for why this defaults to FALSE instead of NULL?
The only caller that checks the value seems to be
_drupal_bootstrap_kernel()
, and it does not perform a strict type comparison, so FALSE == NULL.This still looks incorrect to me. My earlier comment wasn't really meant to say that we need to fix the coupling of PhpStorage in this issue/patch. I'd rather prefer to go back to the previous/original change, and decouple/fix PhpStorage properly in a separate issue.
I do not see an indication in this issue that all possible situations/permutations of the interactive installer have been manually tested. However, that is required for larger installer bootstrap changes like this.
Can we add a comment here that explains the conditional registration? (it's not easy to follow and understand why it is done)
This should be obsolete. #347988: Move $user->data into own table performed the necessary changes to
prepareEnvironment()
already.Comment #45
chx CreditAttribution: chx commentedComment #46
chx CreditAttribution: chx commented> The $rebuild argument seems to be obsolete.
And I removed it before but it got lost in a commit conflict so now I tag it to avoid those.
> Any particular reason for why this defaults to FALSE instead of NULL?
Yes, I like FALSE better than NULL. It doesn't matter so I reverted.
> My earlier comment wasn't really meant to say that we need to fix the coupling of PhpStorage in this issue/patch. I'd rather prefer to go back to the previous/original change, and decouple/fix PhpStorage properly in a separate issue.
There's a separate issue but I already got burned in this issue by needless issue splitting so no, I won't revert this. Once this in and not the other way around we can debate how this happens in #1849570: Remove file.inc ties and fix unlink while at it in MTimeProtectedFastFileStorage . Critical issues first, minor ones second.
> I do not see an indication in this issue that all possible situations/permutations of the interactive installer have been manually tested.
And yet they were, I regularly install with or without settings.php etc.
> Can we add a comment here that explains the conditional registration? (it's not easy to follow and understand why it is done)
Added a "few" words.
> performed the necessary changes to prepareEnvironment() already.
And did it wrong, fixed it (again). Assigning a NULL is needless and we seemingly agreed we prefer if to ?:
Putting it back to RTBC cos all issues are either addressed or have a followup filed for them.
Comment #47
webchickDon't RTBC your own patch, please.
Comment #48
aspilicious CreditAttribution: aspilicious commentedI can confirm the patch does its job on various situations. I updated and installed several times with the previously rtbc patch.
Comment #49
sunSorry, but no. There's no reason to universally disallow or not use ternary operators anymore.
I can't see what's wrong with the existing code. It is simple and consistent. Can we just leave those lines alone?
Why do we check
drupal_container()
here, instead of$this->container
?Comment #50
David_Rothstein CreditAttribution: David_Rothstein commentedMinor point:
Is that code comment and @see really correct after the corresponding code change?
Looks to me like it needs to refer to the writing of a valid settings.php in install_settings_form_submit() instead.
Comment #53
chx CreditAttribution: chx commented> Sorry, but no. There's no reason to universally disallow or not use ternary operators anymore.
Fine, but see the first half of my argument: Assigning a NULL is needless. If in the future there is some other original value to this key then we override that with garbage. Right now, as it stands, in PHP 5.4, assigning to a non-declared object property actually is slower than a declared property so this can even be seen as a micro-optimization. It's (not significantly) more performant now and less buggy later should we define the var and give it some initial value.
> Why do we check drupal_container() here, instead of $this->container?
Hrm, I see #30 did not elaborate on this enough "the reason keyvalue is special cased in tearDown because state() attempts to use it and for unit tests it is not there and it'd blow up". Well, this check is just before that state() call and the container might be completely empty -- for unit tests it is -- and so state() might blow up. There's no guarantee that this->container and drupal_container always align.
> Is that code comment and @see really correct after the corresponding code change?
> Looks to me like it needs to refer to the writing of a valid settings.php in install_settings_form_submit() instead.
Added more comments.
Comment #54
catchI only have minor comments, looks pretty close to RTBC to me.
I dread to think what's happened to page caching performance in the past year, but it's not introduced by this patch.
This hunk is great!
Only seems to?
Oh is this why?
Comment #55
chx CreditAttribution: chx commented> I dread to think what's happened to page caching performance in the past year, but it's not introduced by this patch.
Certainly not, because this patch affects the bootstrap with 1 call to a function which returns a static stored NULL and an if.
> Only seems to?
> Oh is this why?
No, it's not the mail, it's module_enable for example blows up immediately if there's no K-V service due to our use of state. And anything else that goes for state(). Added comments saying so.
Comment #56
katbailey CreditAttribution: katbailey commentedThis will make my work on the ExtensionHandler patch so much easier - let's get it in! :-)
Comment #57
catchAlright. Committed/pushed to 8.x.
Comment #58
Sutharsan CreditAttribution: Sutharsan commentedI've created #1864292: Installation in non-English language fails which is probably a bug introduced by this patch. Any help is appreciated.
Comment #60
chx CreditAttribution: chx commentedRemoving Avoid commit conflicts tag
Comment #60.0
chx CreditAttribution: chx commentedUpdated issue summary.