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

app/AppKernel: store logs in _PS_ROOT_DIR_, not _PS_CORE_DIR_ #31720

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

MaxKellermann
Copy link

@MaxKellermann MaxKellermann commented Mar 10, 2023

_PS_CORE_DIR_ (i.e. dirname(__DIR__), where the source code lives) is potentially read-only, while _PS_ROOT_DIR_ should contain site-specific writable files.

Questions Answers
Branch? develop (see above)
Description? See above.
Type? bug fix
Category? CO
BC breaks? no
Deprecations? no
How to test? Install with different "core"/"root" directory, check where logs get written to
Fixed ticket? n/a
Related PRs n/a
Sponsor company IONOS SE

`_PS_CORE_DIR_` (i.e. `dirname(__DIR__)`, where the source code lives)
is potentially read-only, while `_PS_ROOT_DIR_` should contain
site-specific writable files.
@MaxKellermann MaxKellermann requested a review from a team as a code owner March 10, 2023 12:57
@prestonBot
Copy link
Collaborator

Hello @MaxKellermann!

This is your first pull request on the PrestaShop project. Thank you, and welcome to this Open Source community!

@prestonBot
Copy link
Collaborator

Hi, thanks for this contribution!

I found some issues with the Pull Request description:

  • The category should be one of these: BO, CO, FO, IN, LO, ME, PM, TE or WS (Read explanation)
  • Your pull request does not seem to fix any issue, consider creating one (see note below) and linking it by writing Fixes #1234.

Would you mind having a look at it? This will help us understand how interesting your contribution is, thank you very much!

About linked issues

Please consider opening an issue before submitting a Pull Request:

  • If it's a bug fix, it helps maintainers verify that the bug is effectively due to a defect in the code, and that it hasn't been fixed already.
  • It can help trigger a discussion about the best implementation path before a single line of code is written.
  • It may lead the Core Product team to mark that issue as a priority, further attracting the maintainers' attention.

(Note: this is an automated message, but answering it will reach a real human)

@prestonBot prestonBot added the Bug fix Type: Bug fix label Mar 10, 2023
@@ -146,7 +146,7 @@ public function getCacheDir()
*/
public function getLogDir()
{
return dirname(__DIR__) . '/var/logs';
return _PS_ROOT_DIR_ . '/var/logs';
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, it shouldn't be based on these const which we should get rid of piece by piece but rather something more "Symfony friendly" like:

Suggested change
return _PS_ROOT_DIR_ . '/var/logs';
return $this->getProjectDir() . '/var/logs';

And since it's actually what the method from the parent does this method should be removed

Copy link
Author

Choose a reason for hiding this comment

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

No... getProjectDir() is relative to the source code:

public function getProjectDir()
{
return realpath(__DIR__ . '/..');
}

This would not change anything about this problem I'm trying to address - only add runtime overhead for the realpath() call.

Copy link
Contributor

Choose a reason for hiding this comment

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

But I still don't understand your need actually, currently the logs are store in /var/logs (relatively to the project root folder), just like cache files are stored in /var/cache The folders in /var are indeed supposed to be writable for the software to work

I don't think we can easily change the value of _PS_ROOT_DIR_ just to change the location of logs, because it is used in many other places and doesn't only impact the log folders. If this is really needed it would make more sense to think of a way to change this folder in another way but not relying on _PS_ROOT_DIR_ or _PS_CORE_DIR_ 🤔

Copy link
Author

Choose a reason for hiding this comment

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

In my setup, the (global) directory where the PrestaShop sources are installed is mounted read-only; not only that, PHP processes have no write permissions there, even if it was mounted read-write.
Each PrestaShop instance then has a separate directory which is writable; there, uploads, logs, cached and other files shall be stored.
The idea is to have only one shared PrestaShop source tree for all instances which is never to be modified (until a new version gets installed).

Copy link
Member

Choose a reason for hiding this comment

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

Using environment variables for this directory should be the answer here IMO. I think relying to a legacy prestashop constant is not here the way to go. That would require to have to think about a future proof solution to handle this, and not for this use case only.

WDYT ?

Copy link
Author

Choose a reason for hiding this comment

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

OK, which one shall I use? Is there documentation?
I didn't see any documentation on _PS_ROOT_DIR_ and _PS_CORE_DIR_ (and therefore didn't know it's "legacy") - from the code I figured (guessed) the the former is for instance-specific (writable) data, and the latter is for the (read-only) sources, but it's very inconsistent.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, but there is no documentation on this distinction read/write from previous teams, so it can be risky to assume this actually. Especially since _PS_ROOT_DIR_ and _PS_CORE_DIR_ have actually the same value, so nothing seems to indicate a difference in permissions

Copy link
Author

Choose a reason for hiding this comment

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

Please help me understand what that means:

Yeah, but there is no documentation on this distinction read/write from previous teams, so it can be risky to assume this actually.

Does this mean that separation between sources and data is not possible with PrestaShop, and every PrestaShop instance must have a full copy of the source tree (38.055 files, 407 MB) intertwined with the data tree?

Especially since _PS_ROOT_DIR_ and _PS_CORE_DIR_ have actually the same value, so nothing seems to indicate a difference in permissions

If they are designed to have the same value, what was the reason two variables were introduced and not one?

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

Successfully merging this pull request may close these issues.

None yet

4 participants