Describe the bug
Hi
I encounteer caching problems in a specific case with locales, causung an unhandled exception.
If I upgrade a plugin, and the new version replaces a simple localized string with a localized array (singular / pluaral), then the cache in GLPI is not updated and when the lcoale is used a fatal error occurs
Page(s) URL
If applicable, page(s) URL where the bug happens.
To reproduce
Steps to reproduce the behavior:
Expected behavior
No crash, and proper display of the locale.
Logs
PHP Fatal error: Uncaught Zend\\I18n\\Exception\\OutOfBoundsException: Provided index 1 does not exist in plural array in /home/dethegeek/public_html/glpi-94/vendor/zendframework/zend-i18n/src/Translator/Translator.php:415\nStack trace:
#0 /home/dethegeek/public_html/glpi-94/inc/autoload.function.php(172): Zend\\I18n\\Translator\\Translator->translatePlural('Access type', 'Access types', 2, 'formcreator')
#1 /home/dethegeek/public_html/glpi-94/plugins/formcreator/inc/form_profile.class.php(44): _n('Access type', 'Access types', 2, 'formcreator')
#2 /home/dethegeek/public_html/glpi-94/plugins/formcreator/inc/form_profile.class.php(48): PluginFormcreatorForm_Profile::getTypeName(2)
#3 /home/dethegeek/public_html/glpi-94/inc/commonglpi.class.php(210): PluginFormcreatorForm_Profile->getTabNameForItem(Object(PluginFormcreatorForm), 0)
#4 /home/dethegeek/public_html/glpi-94/plugins/formcreator/inc/form.class.php(738): CommonGLPI->addStandardTab('PluginFormcreat...', Array, Array)
#5 /home/dethegeek/public_html/glpi-94/inc/commonglpi.class in /home/dethegeek/public_html/glpi-94/vendor/zendframework/zend-i18n/src/Translator/Translator.php on line 415, referer: http://localhost/~dethegeek/glpi-94/plugins/formcreator/front/form.form.php?id=3
Careful check on .pot, .po and .mo file, and rebuild when necessary was not enough to solve the bug. I had to delete the cache files in GLPI.
I think that GLPI should invalidate locales cache, if possible for the plugin's domain only, after call of Plugin::install().
Moreover, some plugins have a CLI installer. We may need to document that install or upgrade should / must be run via Plugin::install() method, tu ensure invalidation of the cache.
@btry
Can you test #5672 ? It should do the trick.
Regards
@cedric-anne
it works for me, but I think this fix will decrease performance when GLPI generates notifications. I think we should locate the magic elsewhere (see my comment in the PR)
I changed the fix. I clean translation cache on plugin update (but I have to clean it for everyone).
Cleaning the whole translation cache when a plugin is installed seems not a problem, as it should be a rare operation.
Most helpful comment
I changed the fix. I clean translation cache on plugin update (but I have to clean it for everyone).
Cleaning the whole translation cache when a plugin is installed seems not a problem, as it should be a rare operation.