Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly execute kernel events for initialize.php #1410

Merged
merged 11 commits into from Apr 2, 2020

Conversation

aschempp
Copy link
Member

@aschempp aschempp commented Feb 26, 2020

Yet another fix for the legacy initialize.php

In isotope/core#2064 we are modifying the session to store a state. Unfortunately, the session is not stored in our current approach, because that's done inside a kernel.response listener.

This hacky approach fixes this. It catches all the output of the entry point script, generates a response from it and sends it to the client.

TODO:

  • Check if we need to handle HTTP/1.1 xxx status code headers

Copy link
Member

@qzminski qzminski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to handle the headers sent via header() method as well because of custom code that potentially doesn't use the Contao's exceptions and/or Controller::redirect() or Controller::reload() methods.

@aschempp
Copy link
Member Author

aschempp commented Feb 27, 2020

Unfortunately, tests seem to fail because of our special register_shutdown_function. I don't think we can test this component except in end-to-end tests 😞
We might wanna try that with https://github.com/symfony/panther but I guess that would only be for Contao 4.9+

@leofeyer
Copy link
Member

Frankly, I am not sure whether all these changes are correct. The InitializeController is getting more and more complex and I do not even know which problems are being fixed or if the changes are really fixing them.

The InitializeController was meant to provide a thin BC layer for legacy entry points which still include the system/initialize.php file. However, the idea was not to blow up the controller until it works perfectly with legacy entry points but to refactor the legacy entry points and eventually get rid of them. 🤷‍♂

Contao 3 has reached its ultimate EOL, therefore maybe it is time to release an Isotope version that only supports Contao 4?

@aschempp
Copy link
Member Author

Frankly, I am not sure whether all these changes are correct.

I can explain it to you, or we can just assume if they work in Isotope they should be correct 🤷‍♂
Btw. @qzminski is supposed to validate this as well, he as extensions with custom entry points too.

therefore maybe it is time to release an Isotope version that only supports Contao 4?

yes it is, but it's still a long way to go…

@leofeyer
Copy link
Member

Can you elaborate on the ob_start() and register_shutdown_function() usage? Why is it necessary to use such a hacky workaround?

Btw. @qzminski is supposed to validate this as well, he as extensions with custom entry points too.

What is the status on this one?

@aschempp
Copy link
Member Author

The problem is that we're currently not executing the kernel.response events. Because of that, the Contao session bags are not saved to the session, so any legacy code working with the legacy session will loose its data.

@leofeyer
Copy link
Member

This does not explain why we have to use register_shutdown_function() though, does it?

@qzminski
Copy link
Member

What is the status on this one?

I got an e-mail today that one of my legacy scripts that uses old initialize.php is being triggered as a download since version 4.9 but I will further investigate the case in the next days.

@aschempp
Copy link
Member Author

This does not explain why we have to use register_shutdown_function() though, does it?

well it does, if you know how it works inside-out 😂

  1. the entry point is executed
  2. the entry point loads initialize.php
  3. initialize.php creates a fake route to run kernel.request events
  4. the fake route render the InitializeController that returns a specific response
  5. if the initialize.php receives the correct response, it does nothing more, otherwise it exists (e.g. a kernel.request replaced the response)
  6. now the entry point script continues
  7. the entry point script runs whatever it has to run
  8. after the entry point script, the kernel.response event should be run, to save session etc. Obviously, running after the entry point script is rather tricky, that's why we use register_shutdown_function

@leofeyer
Copy link
Member

  1. Obviously, running after the entry point script is rather tricky, that's why we use register_shutdown_function

That makes sense. 👍

Then I guess we'll wait for @qzminski's investigations and merge this PR afterwards. The unit tests need to be fixed though. 🙈

@aschempp
Copy link
Member Author

I‘m pretty sure we can‘t fix the unit tests. We might add end-to-end tests for 4.9 🤷‍♂️

@leofeyer
Copy link
Member

Not fixing it is not an option obviously. We at least have to remove the failing tests to fix the CI chain.

@aschempp
Copy link
Member Author

Absolutely, thats what I mean. As this is for 4.4 I would suggest to just remove the tests and then try to add e2e tests when merged into 4.9

@aschempp
Copy link
Member Author

@qzminski found an issue with the Symfony response related to symfony/symfony#35709

Since we are now executing the kernel.response event ourselves, we don't want to run these listeners for the InitializeControllerResponse.

@qzminski please test this change in your local setup.

qzminski
qzminski previously approved these changes Apr 1, 2020
leofeyer
leofeyer previously approved these changes Apr 2, 2020
@leofeyer leofeyer merged commit e4c9ed8 into 4.4 Apr 2, 2020
@leofeyer leofeyer deleted the bugfix/initialize-response branch April 2, 2020 07:21
@fritzmg
Copy link
Contributor

fritzmg commented May 11, 2020

With these changes I get an empty response with custom entry points - though only within certain server environments. For example, the treepicker.php entry point of codefog/contao-widget_tree_picker returns an empty response on Hostingwerk (Apache profile). However, locally on my system (nginx) the response content is returned as expected.

@fritzmg
Copy link
Contributor

fritzmg commented May 11, 2020

@qzminski have you noticed anything like that yet?

@qzminski
Copy link
Member

@fritzmg kinda yes but it was fixed by @aschempp in ff09091, so the origin of your problem must be totally different. I don't know what could be wrong in your case, though 🤷🏻‍♂️

@fritzmg
Copy link
Contributor

fritzmg commented May 11, 2020

Hm, ok. I'll make a test installation on Hostingwerk, once Contao 4.4.49 is released.

@qzminski
Copy link
Member

By the way, shouldn't you use the new DCA picker providers feature instead of this legacy extension? Or is it tied down to some of mine open source extensions? 😅

@fritzmg
Copy link
Contributor

fritzmg commented May 11, 2020

By the way, shouldn't you use the new DCA picker providers feature instead of this legacy extension? Or is it tied down to some of mine open source extensions? 😅

Well, it's an installation that still uses codefog/contao-news_categories in Version 2.8 (and can't be easily updated to ^3.2 due to a lot of customization regarding the news categories). I take it codefog/contao-news_categories >=3.0 does not use codefog/contao-widget_tree_picker anymore?

@qzminski
Copy link
Member

Yep exactly, the new picker was introduced in v3.0 of codefog/contao-news_categories.

@fritzmg
Copy link
Contributor

fritzmg commented May 11, 2020

Ok thank you, good to know :)

@aschempp
Copy link
Member Author

See #1728

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants