Skip to content

Update of settings by Eloquent doesn't insert new values or delete rows with new values #10562

Open

Description

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:

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

Bug:3:CriticalA bug that prevents a substantial minority of users from using the software.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions