OJS 3.4 compatibility issue

I have installed the OJS 3.4 on the server, but when I tried to install a plugin, I got this error:

PHP Fatal error:  Uncaught Error: Class "AppLocale" not found in /app/plugins/generic/My_plugin/MyPlugin.inc.php:105

this is the line 105 in my MyPlugin.inc.php:

AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON,  LOCALE_COMPONENT_PKP_MANAGER);

the plugin works fine with OJS 3.X versions
This error suggests that the code in the My_plugin is trying to use a class named “AppLocale,” but it cannot find this class.
how should I modify the plugin code to make it works fine with OJS 3.3 and 3.4 versions

I can see in the AppLocale class in OJS 3.4 this:

@deprecated The class \APP\i18n\AppLocale has been replaced by PKP\facades\Locale

but in Local class, there are no LOCALE_COMPONENT_APP_COMMON and LOCALE_COMPONENT_APP_MANAGER constant

I have tried to use in /app/plugins/generic/My_plugin/MyPlugin.inc.php:

use PKP\facades\Locale;
use PKP\i18n\PKPLocale;

                Locale::requireComponents(PKPLocale::LOCALE_COMPONENT_APP_COMMON, PKPLocale::LOCALE_COMPONENT_APP_MANAGER);

but I got this error:

 NOTICE: PHP message: PHP Fatal error:  Uncaught Error: Undefined constant PKP\i18n\PKPLocale::LOCALE_COMPONENT_APP_COMMON in /app/plugins/generic/My_plugin/MyPlugin.inc.php:114

Hi @Mohammed_Amin,

Which plugin are you trying to install? Depending on the plugin it may/may not be compatible with OJS 3.4.

-Roger
PKP Team

Plugins you have developed for 3.3 will need changes when upgrading to a new major version release (like 3.4).

The 3.4 Release Notebook describes some of these changes.

Additional details are linked to in GitHub.

1 Like

A custom made plugin
the main issue now is how to import constants LOCALE_COMPONENT_APP_COMMON, LOCALE_COMPONENT_PKP_MANAGER in the new structure, also I’m not familiar with the PHP

Hey @jonasraoni
I made sure that the strict = off in the config.inc.php

However, when I removed the line 105:

AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON, LOCALE_COMPONENT_PKP_MANAGER);

I got this error:

 NOTICE: PHP message: PHP Fatal error:  Uncaught  --> Smarty: undefined extension class 'Smarty_Internal_Method_Register_Function' <--
ojs14_1       |   thrown in /app/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_internal_undefined.php on line 62

according to what explained here, when I replaced the line 105:

AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON, LOCALE_COMPONENT_PKP_MANAGER);

by:

PKP\facades\Locale::swap(new CustomLocaleClass())

I got this error:

 NOTICE: PHP message: PHP Fatal error:  Uncaught  --> Smarty: undefined extension class 'Smarty_Internal_Method_Register_Function' <--
ojs14_1       |   thrown in /app/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_internal_undefined.php on line 62

Hi @Mohammed_Amin,

You shouldn’t need to replace the underlying implementation with PKP\facades\Locale::swap(new CustomLocaleClass()), only if you have a very unexpected edge case that requires modifying the behavior of the Locale class :slight_smile:

The error:

PHP Fatal error:  Uncaught  --> Smarty: undefined extension class 'Smarty_Internal_Method_Register_Function' <--
ojs14_1       |   thrown in /app/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_internal_undefined.php on line 62

Refers to something else. Looks like you’re using methods from the Smarty library that don’t exist anymore, see this link for an example: https://stackoverflow.com/questions/59143845/smarty-undefined-extension-class-smarty-internal-method-get-template-vars


As a second note, the locale folders have been renamed recently (e.g. en_US became en), you must ensure your plugin is following the same pattern, or the localized text will not be loaded.

In case you don’t have a PHP debugger to help you to find what’s wrong, take a look at this function, which should give you some clues about where the problem is: https://www.php.net/manual/en/function.debug-print-backtrace.php

Best,
Jonas Raoni

Yes, the issue was related to the register_function method from TemplateManager which is deleted in 3.4
here is my old code:

$templateMgr = TemplateManager::getManager($request);
$templateMgr->register_function('plugin_url', [$this, 'smartyPluginUrl']);

and this is the updated one:

$templateMgr = TemplateManager::getManager($request);
$templateMgr->registerPlugin('function', 'plugin_url', [$this, 'smartyPluginUrl']);

Thank you @jonasraoni, all in order now

1 Like