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
AppKernel is now able to detect the admin folder #35417
AppKernel is now able to detect the admin folder #35417
Conversation
…DIR is not defined, the admin dir path is now set in the prestashop.admin_dir parameter that must be favored from now on in DI
a5d3e9e
to
919bc3c
Compare
foreach ($finder as $adminIndexFile) { | ||
$adminDir = $adminIndexFile->getPath(); | ||
// Container freshness depends on this file existence | ||
$container->addResource(new FileExistenceResource($adminIndexFile->getRealPath())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, I didn't know about this FileExistenceResource
feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep me neither, just found out about it!
Less coupling to legacy constants, nice ! |
@jolelievre I guess this can be merged as long as CI and ui tests are fine ? there's only one UI test failing, but it doesn't look like it's related to your PR |
@FabienPapet yep, step by step 😅 |
// Define parameter for admin folder path | ||
if (defined('PS_ADMIN_DIR') && is_dir(PS_ADMIN_DIR)) { | ||
$adminDir = PS_ADMIN_DIR; | ||
} elseif (defined('_PS_ADMIN_DIR_') && is_dir(_PS_ADMIN_DIR_)) { | ||
$adminDir = _PS_ADMIN_DIR_; | ||
} else { | ||
// Look for potential admin folders, condition to meet: | ||
// - first level folders in the project folder | ||
// - contains a PHP file that define the const PS_ADMIN_DIR or _PS_ADMIN_DIR_ | ||
// - the first folder found is used (alphabetical order, but files named index.php have the highest priority) | ||
$finder = new Symfony\Component\Finder\Finder(); | ||
$finder->files() | ||
->name('*.php') | ||
->contains('/define\([\'\"](_)?PS_ADMIN_DIR(_)?[\'\"]/') | ||
->depth('== 1') | ||
->sort(function (SplFileInfo $a, SplFileInfo $b): int { | ||
// Prioritize files named index.php | ||
if ($a->getFilename() === 'index.php') { | ||
return -1; | ||
} | ||
|
||
return strcmp($a->getRealPath(), $b->getRealPath()); | ||
}) | ||
->in($this->getProjectDir()) | ||
; | ||
foreach ($finder as $adminIndexFile) { | ||
$adminDir = $adminIndexFile->getPath(); | ||
// Container freshness depends on this file existence | ||
$container->addResource(new FileExistenceResource($adminIndexFile->getRealPath())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice @jolelievre, thanks :)
I think we should put this in a dedicated function or class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's room for a small refacto indeed, I guess it will have to be done in a dedicated PR then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jolelievre
Thank you for your PR, I tested it and it seems to works as you can see :
Link to the auto test : https://github.com/jolelievre/ga.tests.ui.pr/actions/runs/7962314884
Because the auto test is 🟢 and the PR seems to works as expected, It's QA ✔️
Thank you
prestashop.admin_dir
parameter that must be favored from now on in DISteps to reproduce
Alternative:
You can use
./bin/console debug:container --parameters
and check thatprestashop.admin_dir
andprestashop.admin_folder_name
are correctly updated when the admin folder is renamed In dev environment it should be automatic thanks to the resource checking, but in prod you probably have to clean the cache after every modification