Error after upgrade OJS and PHP - DataObject->setData('biography', '', 'pt_BR')

Hi,

After upgrading an OJS instace from 3.3.0.10 (php 7.4) to 3.3.0.14 (php 8.0), I got an error 500 on load page.

Log error (php 8.0):

[05-Apr-2023 13:38:10 America/Los_Angeles] PHP Fatal error:  Uncaught TypeError: Cannot access offset of type string on string in ./lib/pkp/classes/core/DataObject.inc.php:133
Stack trace:
#0 ./lib/pkp/classes/db/DAO.inc.php(496): DataObject->setData('biography', '', 'pt_BR')
#1 ./lib/pkp/classes/user/UserDAO.inc.php(239): DAO->getDataObjectSettings('user_settings', 'user_id', 1, Object(User))
#2 ./lib/pkp/classes/user/UserDAO.inc.php(51): UserDAO->_returnUserFromRowWithData(Array)
#3 ./lib/pkp/classes/session/Session.inc.php(81): UserDAO->getById(1)
#4 ./lib/pkp/classes/session/SessionDAO.inc.php(40): Session->setUserId(1)
#5 ./lib/pkp/classes/session/SessionManager.inc.php(170): SessionDAO->getSession('b9e954dfde4515a...')
#6 [internal function]: SessionManager->read('b9e954dfde4515a...')
#7 ./lib/pkp/classes/session/SessionManager.inc.php(60): session_start()
#8 ./lib/pkp/classes/session/SessionManager.inc.php(131): SessionManager->__construct(Object(SessionDAO), Object(Request))
#9 ./lib/pkp/classes/i18n/PKPLocale.inc.php(131): SessionManager::getManager()
#10 ./lib/pkp/classes/i18n/PKPLocale.inc.php(290): PKPLocale::getLocale()
#11 ./lib/pkp/classes/core/Dispatcher.inc.php(116): PKPLocale::initialize(Object(Request))
#12 ./lib/pkp/classes/core/PKPApplication.inc.php(362): Dispatcher->dispatch(Object(Request))
#13 ./index.php(68): PKPApplication->execute()
#14 {main}
  thrown in ./lib/pkp/classes/core/DataObject.inc.php on line 133

Before update (php 7.4), php error register a several number of warnings like these:

[05-Apr-2023 18:06:23 America/Los_Angeles] PHP Warning:  Illegal string offset 'pt_BR' in ./lib/pkp/classes/core/DataObject.inc.php on line 133
[05-Apr-2023 18:06:23 America/Los_Angeles] PHP Warning:  Cannot assign an empty string to a string offset in ./lib/pkp/classes/core/DataObject.inc.php on line 133
[05-Apr-2023 18:06:23 America/Los_Angeles] PHP Warning:  Illegal string offset 'pt_BR' in ./lib/pkp/classes/core/DataObject.inc.php on line 133
[05-Apr-2023 18:06:23 America/Los_Angeles] PHP Warning:  Cannot assign an empty string to a string offset in ./lib/pkp/classes/core/DataObject.inc.php on line 133
[05-Apr-2023 18:06:44 America/Los_Angeles] PHP Warning:  Illegal string offset 'pt_BR' in ./lib/pkp/classes/core/DataObject.inc.php on line 133
[05-Apr-2023 18:06:44 America/Los_Angeles] PHP Warning:  Cannot assign an empty string to a string offset in ./lib/pkp/classes/core/DataObject.inc.php on line 133
[05-Apr-2023 18:07:24 America/Los_Angeles] PHP Warning:  Illegal string offset 'pt_BR' in ./lib/pkp/classes/core/DataObject.inc.php on line 133
[05-Apr-2023 18:07:24 America/Los_Angeles] PHP Warning:  Cannot assign an empty string to a string offset in ./lib/pkp/classes/core/DataObject.inc.php on line 133
[05-Apr-2023 18:07:25 America/Los_Angeles] PHP Warning:  Illegal string offset 'pt_BR' in ./lib/pkp/classes/core/DataObject.inc.php on line 133
[05-Apr-2023 18:07:25 America/Los_Angeles] PHP Warning:  Cannot assign an empty string to a string offset in ./lib/pkp/classes/core/DataObject.inc.php on line 133
[05-Apr-2023 18:09:10 America/Los_Angeles] PHP Warning:  Illegal string offset 'pt_BR' in ./lib/pkp/classes/core/DataObject.inc.php on line 133
[05-Apr-2023 18:09:10 America/Los_Angeles] PHP Warning:  Cannot assign an empty string to a string offset in ./lib/pkp/classes/core/DataObject.inc.php on line 133
[05-Apr-2023 18:09:10 America/Los_Angeles] PHP Warning:  Illegal string offset 'pt_BR' in ./lib/pkp/classes/core/DataObject.inc.php on line 133
[05-Apr-2023 18:09:10 America/Los_Angeles] PHP Warning:  Cannot assign an empty string to a string offset in ./lib/pkp/classes/core/DataObject.inc.php on line 133

I don’t have enough knowledge to find a relation about these logs, but I belive that exist something related to locales to be corrected on database.

Anyone could give me a light?

@NateWr @asmecher could you look, pls?

On this post Illegal string offset 'en_US' - #8 by darkswitch is informed that after php upgrade (8.0) warnings are solved, but now I got an error that seems to be related.

Looking hard for a solution without success :confused:

Hi @geniusdesign,

You probably have invalid entries in your user_settings table:

SELECT * FROM user_settings WHERE setting_name = 'biography' AND (locale IS NULL OR locale = '');

If this SQL query returns any results, you’ll need to fix them. There should be a locale for every biography entry, indicating what language the biography is in.

Regards,
Alec Smecher
Public Knowledge Project Team

Ty @asmecher ! Indeed, there is a lot of lines empty on locale column. This is an old database, created from OJS 2 and it seems that oldest entries has locale value empty.

If I delete some of these empty locale value rows, can it compromise database?

Hi @geniusdesign,

Deleting those won’t cause problems, though you might also consider updating the locale column to e.g. en_US for English content. That’ll probably involve resolving some collisions, so it might be trickier.

As always when working with the database directly, take a good backup first!

Regards,
Alec Smecher
Public Knowledge Project Team

Ty for the tips, @asmecher !

I tried to set a locale value (pt_BR in my case) to all empty fields on locale column, but it got some duplicated rows. And ‘biography’ wont be the unic setting_name with this issue, but exist many others. So I consider to drop all rows with locale and setting_value empty.

user_setting table cannot has any row with locale column empty, correct?

Hi @geniusdesign,

Be careful about setting values in all rows – some will have an empty locale column, others will not, depending on what the setting_name is.

Regards,
Alec Smecher
Public Knowledge Project Team

This topic was automatically closed after 9 days. New replies are no longer allowed.