Description
openedon Oct 24, 2024
Describe the bug
The current implementation of the update statement in the extended Eloquent isn't suitable for the settings data model. Considering the example:
UPDATE announcement_settings SET setting_value =
CASE WHEN setting_name='title' AND locale='en' THEN 'English Title' WHEN setting_name='title' AND locale='fr_CA' THEN 'French TItle' ELSE setting_value END
WHERE announcement_id = 16;
It doesn't allow to remove null values of already existing settings. Considering the example, if we already have a database record:
announcement_setting_id | announcement_id | locale | setting_name | setting_value |
---|---|---|---|---|
1 | 1 | en | title | Title in English |
2 | 1 | fr_FR | title | Title in French |
Then, trying to update with
$announcement->title = [
'fr_FR' => Title in French modified
];
$announcement->save();
won't remove the title in English:
announcement_setting_id | announcement_id | locale | setting_name | setting_value |
---|---|---|---|---|
1 | 1 | en | title | Title in English |
2 | 1 | fr_FR | title | Title in French modified |
update - The EntityDAO behaviour is to remove values explicitly set to null
, e.g.
$announcement->update(
'title' => [
'en' => null,
'fr_FR' => 'Title in French modified'
],
)
Also, we need to insert new settings during update.
We have two places in the code, where the logic is implemented:
- Old DAO:
Line 432 in b4bb499
- EntityDAO:
pkp-lib/classes/core/EntityDAO.php
Line 190 in b4bb499
@touhidurabir's proposal: https://github.com/pkp/pkp-lib/pull/10324/files#diff-4dcc09fe73d537128c17c4bbb260ad4ba24ccc0ecb8cdc7d0b47ebc7986e2cedR79-R129
What application are you using?
OJS, OMP or OPS main branch