Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Vitaliy-1 opened this issue Oct 24, 2024 · 1 comment
Assignees
Labels
Bug:3:Critical A bug that prevents a substantial minority of users from using the software.
Milestone

Comments

@Vitaliy-1
Copy link
Collaborator

Vitaliy-1 commented 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:

@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

@Vitaliy-1 Vitaliy-1 added the Bug:3:Critical A bug that prevents a substantial minority of users from using the software. label Oct 24, 2024
@Vitaliy-1 Vitaliy-1 added this to the 3.5 Internal milestone Oct 24, 2024
@Vitaliy-1
Copy link
Collaborator Author

PR pkp-lib: #10542
tests: pkp/ojs#4496

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug:3:Critical A bug that prevents a substantial minority of users from using the software.
Projects
None yet
Development

No branches or pull requests

2 participants