-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix: PHP error - Call to a member function addTranslationFile() on null #18699
base: main
Are you sure you want to change the base?
Conversation
.phpstan-baseline.php
Outdated
@@ -4681,6 +4681,12 @@ | |||
'count' => 2, | |||
'path' => __DIR__ . '/src/Plugin.php', | |||
]; | |||
$ignoreErrors[] = [ |
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.
baseline is only present so we do not have to fax all existing issues; we should not add new ones.
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.
The code is a copy/paste from what's in src/Session.php, which is also in the baseline, that's why I tried to ignore it in the same way, to see if it's accepted, but apparently not 😢
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.
I was not aware we already have an occurrence of that... But, the fact a code already exists does not mean it's correct :D
Keep in mind we'll have to fix phpstan issues one day.
Seems like this affects existing test (no idea if tests were wrong before - I did not check). I'm not sure to understand the fix anyway; but I do no know this part really well. |
It seems plugins are loaded before the session language is set, I guess the |
Can you try something like this ? diff --git a/src/Glpi/Kernel/ListenersPriority.php b/src/Glpi/Kernel/ListenersPriority.php
index 08b036052c..e33b4f793c 100644
--- a/src/Glpi/Kernel/ListenersPriority.php
+++ b/src/Glpi/Kernel/ListenersPriority.php
@@ -46,9 +46,9 @@ final class ListenersPriority
KernelListener\InitializeCache::class => 170,
KernelListener\LoadLegacyConfiguration::class => 160,
KernelListener\CustomObjectsAutoloaderRegistration::class => 150,
+ KernelListener\LoadLanguage::class => 145,
KernelListener\InitializePlugins::class => 140,
KernelListener\CustomObjectsBootstrap::class => 130,
- KernelListener\LoadLanguage::class => 120,
];
public const REQUEST_LISTENERS_PRIORITIES = [ |
And if it works, we can probably add some kind of test to make sure it stays working. |
src/Plugin.php
Outdated
if (!defined('TU_USER')) { | ||
$i18n_cache = new I18nCache((new CacheManager())->getTranslationsCacheInstance()); | ||
$TRANSLATE = new class ($i18n_cache) extends Laminas\I18n\Translator\Translator { | ||
public function __construct(?I18nCache $cache) | ||
{ | ||
$this->cache = $cache; | ||
} | ||
}; | ||
$TRANSLATE->setLocale($coretrytoload); | ||
} | ||
|
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.
If the listener change is effective, this can be removed.
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.
Without this code, the initial error comes back.
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.
It works on my side, but only after deleting the cache.
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.
Yes for me too by emptying the folder _cache
Checklist before requesting a review
Please delete options that are not relevant.
Description
Prevent error message :
Screenshots (if appropriate):