-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[Bug]: Static Page generation not working properly via cli #17570
Description
Pimcore version
v11.3.2
Steps to reproduce
How to reproduce
- create multiple documents in Pimcore and enable server side static rendering in each
- run
bin/console pimcore:maintenance --job=documents_static_page_generateorbin/console pimcore:documents:generate-static-pagesand have a look at the generated static files (located under /public/var/tmp/pages/{path-to-document})
Actual Behavior
Problems
Usage of the static page generation is not working properly, when done via maintenance StaticPageGenerationTask or GenerateStaticPagesCommand.
Issue 1: Resetting Services
Problem:
Many services do not operate statelessly. They employ a pattern similar to this:
public function getTitle(): string
{
if (!$this->title) {
$this->title = 'do something';
}
return $this->title;
}This pattern causes issues as seen in #16220, where the $returnedFiles variable stores the already returned files and does not reset when generating multiple static pages in one session.
Proposed Solution:
I can propose a solution by resetting all services using the service_resetter. Please refer to the following commit in my Pimcore fork: melissakittl@33c06e6
Issue 2: HTTPS Request Scheme for Static Pages
Problem:
When static pages are generated via the CLI, the request scheme defaults to http, because $_SERVER['HTTPS'] server variable isn't set in CLI, resulting in all links being generated with http even if the site actually operates under https. Consequently, the static pages cannot be used as intended because they do not contain the correct document links.

Possible Solution:
I don't have a solution at hand. Maybe it's possible to add a configuration for the used scheme in static page generation.
The alternative would be avoiding the generation of static pages through CLI (via StaticPageGenerationTask and GenerateStaticPagesCommand) and creating static pages on-demand when a page is accessed. The StaticPageGenerationTask could then be limited to deleting expired files without regenerating them, but the GenerateStaticPagesCommand would be obsolete.
Issue 3: Request Pathinfo
Problem 3.1:
At this line in the code https://github.com/pimcore/pimcore/blob/11.3/lib/Document/Renderer/DocumentRenderer.php#L102, a request with context is created in the catch block, because no current request exists in the CLI. However, this does not include a URI, which means the pathinfo is not set. If anywhere in the code the current request or main request from the request stack is used with pathinfo, it generates URLs like: http://testdomain.com/_fragment.

Proposed Solution:
The pathinfo could be set using the following commit from my pimcore fork: melissakittl@a6d54d9
Problem 3.2:
However, this new request should also be pushed onto the request stack, to be used as current / main request. If pushed, it must be popped off before processing the next document to avoid conflicts as there would already be an existing request in use.
Proposed Solution:
Unfortunately, I cannot offer a clean solution for this issue either.
As with Issue 2, my intention is to discontinue the generation of static pages through the CLI altogether.
Note:
It does not make sense to address Issues 1, 2 and 3.1 if the decision is made to avoid CLI generation as described in Issue 2.
Until these issues are fixed, my way to go will be, to disable the StaticPageGenerationTask and never run the GenerateStaticPagesCommand to be able to use static pages.
Expected Behavior
Static Pages generated via cli do not contain the correct content, due to explained reasons.