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

Don't cache absolute paths of templates #5826

Closed
rabauss opened this issue Feb 27, 2023 · 11 comments · May be fixed by #6991
Closed

Don't cache absolute paths of templates #5826

rabauss opened this issue Feb 27, 2023 · 11 comments · May be fixed by #6991
Assignees
Labels
Milestone

Comments

@rabauss
Copy link
Contributor

rabauss commented Feb 27, 2023

Affected version(s)

4.13+

Description

In chrooted environments like on plesk hosting you may have a changing kernel.project_dir via cli and web server, e.g. via cli /httpdocs/ and via web server /var/www/vhosts/mydomain.com/httpdocs/

This is especially a problem on cache:warmup, since some paths to templates are written absolutely by contao to the cache directory, e.g. for the cache key contao.twig.template_hierarchy something like that

'be_main' => [
        '/httpdocs/vendor/contao/core-bundle/src/Resources/contao/templates/backend/be_main.html5' => '@Contao_ContaoCoreBundle/be_main.html5',
    ],

Afterwards you can see an error in the back end because via web server the "wrong" absolute path is not resolvable.

Uncaught PHP Exception Twig\Error\LoaderError: "Template "@Contao_ContaoCoreBundle/be_main.html5" is not defined ... 
at vendor/twig/twig/src/Loader/ChainLoader.php line 99

One solution would be for contao to write relative paths to the cache folder instead of absolute paths - especially for templates!

see also: https://contao.slack.com/archives/CK4J0KNDB/p1677063729691519

@ausi
Copy link
Member

ausi commented Feb 28, 2023

We had a similar issue in contao/image and switched to using relative paths AFAIR, contao/image#32

@aschempp
Copy link
Member

aschempp commented Mar 8, 2023

the cache in Symfony must never contain absolute paths, so that's clearly a bug.

@aschempp aschempp added this to the 4.13 milestone Mar 8, 2023
@leofeyer
Copy link
Member

leofeyer commented Mar 8, 2023

the cache in Symfony must never contain absolute paths

That does not seem true. Try searching for /Users/aschempp in the var/cache folder – there were plenty of hits on my system.

@leofeyer
Copy link
Member

leofeyer commented Mar 8, 2023

But we indeed dump relative paths when generating the template cache:

$mapper[$file->getBasename('.html5')] = Path::makeRelative($file->getPath(), $this->projectDir);

@m-vo Can you fix this please?

@m-vo
Copy link
Member

m-vo commented Mar 8, 2023

I can if it helps in certain setups. But I am not yet convinced this is a bug tbh. The issue only shows if the web process and the CLI resolve absolute paths differently, which sounds like a very strange setup to me, no?

@Toflar
Copy link
Member

Toflar commented Mar 8, 2023

twigphp/Twig#3218 😂

@Toflar
Copy link
Member

Toflar commented Mar 8, 2023

So I guess it's not worth fixing as any other Twig template wouldn't work either?

@leofeyer leofeyer added the up for discussion Issues and PRs which will be discussed in our monthly Mumble calls. label Mar 9, 2023
@leofeyer
Copy link
Member

leofeyer commented Mar 9, 2023

As discussed in the Contao call, twigphp/Twig#3218 needs to be fixed before it makes sense to adjust our code.

@leofeyer leofeyer removed the up for discussion Issues and PRs which will be discussed in our monthly Mumble calls. label Mar 9, 2023
@stale
Copy link

stale bot commented May 9, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 9, 2023
@leofeyer leofeyer removed the stale label May 9, 2023
@stale
Copy link

stale bot commented Sep 17, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 17, 2023
@ausi ausi removed the stale label Sep 18, 2023
Copy link

stale bot commented Dec 15, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 15, 2023
@m-vo m-vo removed the stale label Dec 16, 2023
@m-vo m-vo self-assigned this Dec 16, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants