From 05fcfbb7ec2f4101352bc06d4ab9118c4dca5db9 Mon Sep 17 00:00:00 2001 From: Rom1-B Date: Fri, 10 Jan 2025 10:34:18 +0100 Subject: [PATCH 1/7] fix: PHP error - Call to a member function addTranslationFile() on null --- src/Plugin.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Plugin.php b/src/Plugin.php index 41135dcc3f8..6c9c6a04cf4 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -39,6 +39,7 @@ use Glpi\Application\View\TemplateRenderer; use Glpi\Cache\CacheManager; +use Glpi\Cache\I18nCache; use Glpi\Dashboard\Grid; use Glpi\Marketplace\Controller as MarketplaceController; use Glpi\Marketplace\View as MarketplaceView; @@ -476,6 +477,14 @@ public static function loadLang($plugin_key, $forcelang = '', $coretrytoload = ' } } + $i18n_cache = !defined('TU_USER') ? new I18nCache((new CacheManager())->getTranslationsCacheInstance()) : null; + $TRANSLATE = new class ($i18n_cache) extends Laminas\I18n\Translator\Translator { + public function __construct(?I18nCache $cache) + { + $this->cache = $cache; + } + }; + if ($mofile !== false) { $TRANSLATE->addTranslationFile( 'gettext', From f09eef425c7d804a5624ac59940b11a6c9193d6a Mon Sep 17 00:00:00 2001 From: Rom1-B Date: Fri, 10 Jan 2025 12:38:05 +0100 Subject: [PATCH 2/7] fix --- .phpstan-baseline.php | 6 ++++++ src/Plugin.php | 2 ++ 2 files changed, 8 insertions(+) diff --git a/.phpstan-baseline.php b/.phpstan-baseline.php index 088966eddce..41163d177de 100644 --- a/.phpstan-baseline.php +++ b/.phpstan-baseline.php @@ -4681,6 +4681,12 @@ 'count' => 2, 'path' => __DIR__ . '/src/Plugin.php', ]; +$ignoreErrors[] = [ + 'message' => '#^Property Laminas\\\\I18n\\\\Translator\\\\Translator\\:\\:\\$cache \\(Laminas\\\\Cache\\\\Storage\\\\StorageInterface\\|null\\) does not accept Glpi\\\\Cache\\\\I18nCache\\|null\\.$#', + 'identifier' => 'assign.propertyType', + 'count' => 1, + 'path' => __DIR__ . '/src/Plugin.php', +]; $ignoreErrors[] = [ 'message' => '#^Call to function method_exists\\(\\) with \\$this\\(Printer\\) and \'prepareGroupFields\' will always evaluate to true\\.$#', 'identifier' => 'function.alreadyNarrowedType', diff --git a/src/Plugin.php b/src/Plugin.php index 6c9c6a04cf4..4cbdf638a4b 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -485,6 +485,8 @@ public function __construct(?I18nCache $cache) } }; + $TRANSLATE->setLocale($trytoload); + if ($mofile !== false) { $TRANSLATE->addTranslationFile( 'gettext', From bc79f503140a22c8720472cd511fa671cd02f187 Mon Sep 17 00:00:00 2001 From: Rom1-B Date: Fri, 10 Jan 2025 14:28:41 +0100 Subject: [PATCH 3/7] fix tests --- .phpstan-baseline.php | 6 ------ src/Plugin.php | 19 ++++++++++--------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/.phpstan-baseline.php b/.phpstan-baseline.php index 41163d177de..088966eddce 100644 --- a/.phpstan-baseline.php +++ b/.phpstan-baseline.php @@ -4681,12 +4681,6 @@ 'count' => 2, 'path' => __DIR__ . '/src/Plugin.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Property Laminas\\\\I18n\\\\Translator\\\\Translator\\:\\:\\$cache \\(Laminas\\\\Cache\\\\Storage\\\\StorageInterface\\|null\\) does not accept Glpi\\\\Cache\\\\I18nCache\\|null\\.$#', - 'identifier' => 'assign.propertyType', - 'count' => 1, - 'path' => __DIR__ . '/src/Plugin.php', -]; $ignoreErrors[] = [ 'message' => '#^Call to function method_exists\\(\\) with \\$this\\(Printer\\) and \'prepareGroupFields\' will always evaluate to true\\.$#', 'identifier' => 'function.alreadyNarrowedType', diff --git a/src/Plugin.php b/src/Plugin.php index 4cbdf638a4b..6aceabc6b14 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -477,15 +477,16 @@ public static function loadLang($plugin_key, $forcelang = '', $coretrytoload = ' } } - $i18n_cache = !defined('TU_USER') ? new I18nCache((new CacheManager())->getTranslationsCacheInstance()) : null; - $TRANSLATE = new class ($i18n_cache) extends Laminas\I18n\Translator\Translator { - public function __construct(?I18nCache $cache) - { - $this->cache = $cache; - } - }; - - $TRANSLATE->setLocale($trytoload); + 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); + } if ($mofile !== false) { $TRANSLATE->addTranslationFile( From a4d99adb2bc1ab7d191c6d554fb67b31a0fa411a Mon Sep 17 00:00:00 2001 From: Rom1-B Date: Fri, 10 Jan 2025 14:34:57 +0100 Subject: [PATCH 4/7] adrien --- src/Glpi/Kernel/ListenersPriority.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Glpi/Kernel/ListenersPriority.php b/src/Glpi/Kernel/ListenersPriority.php index 08b036052c0..e33b4f793c8 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 = [ From 72a0bcb601e215129ec863b1894295599970168e Mon Sep 17 00:00:00 2001 From: Rom1-B Date: Fri, 10 Jan 2025 15:36:05 +0100 Subject: [PATCH 5/7] adrien2 --- src/Plugin.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index 6aceabc6b14..41135dcc3f8 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -39,7 +39,6 @@ use Glpi\Application\View\TemplateRenderer; use Glpi\Cache\CacheManager; -use Glpi\Cache\I18nCache; use Glpi\Dashboard\Grid; use Glpi\Marketplace\Controller as MarketplaceController; use Glpi\Marketplace\View as MarketplaceView; @@ -477,17 +476,6 @@ public static function loadLang($plugin_key, $forcelang = '', $coretrytoload = ' } } - 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); - } - if ($mofile !== false) { $TRANSLATE->addTranslationFile( 'gettext', From 6c031b7f12100f3d2a5f53267ff39e423c6aadba Mon Sep 17 00:00:00 2001 From: AdrienClairembault Date: Fri, 10 Jan 2025 15:58:16 +0100 Subject: [PATCH 6/7] Add locales to `tester` plugin --- tests/fixtures/plugins/tester/locales/en_GB.mo | 0 tests/fixtures/plugins/tester/locales/fr_FR.mo | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fixtures/plugins/tester/locales/en_GB.mo create mode 100644 tests/fixtures/plugins/tester/locales/fr_FR.mo diff --git a/tests/fixtures/plugins/tester/locales/en_GB.mo b/tests/fixtures/plugins/tester/locales/en_GB.mo new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/fixtures/plugins/tester/locales/fr_FR.mo b/tests/fixtures/plugins/tester/locales/fr_FR.mo new file mode 100644 index 00000000000..e69de29bb2d From 4e266e6977a83bdea495c9afdadd1f8c31b8322c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Mon, 13 Jan 2025 08:35:57 +0100 Subject: [PATCH 7/7] Update src/Glpi/Kernel/ListenersPriority.php --- src/Glpi/Kernel/ListenersPriority.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Glpi/Kernel/ListenersPriority.php b/src/Glpi/Kernel/ListenersPriority.php index e33b4f793c8..91798f9e45d 100644 --- a/src/Glpi/Kernel/ListenersPriority.php +++ b/src/Glpi/Kernel/ListenersPriority.php @@ -45,10 +45,10 @@ final class ListenersPriority KernelListener\InitializeDbConnection::class => 180, 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 => 150, + KernelListener\CustomObjectsAutoloaderRegistration::class => 140, + KernelListener\InitializePlugins::class => 130, + KernelListener\CustomObjectsBootstrap::class => 120, ]; public const REQUEST_LISTENERS_PRIORITIES = [