Skip to content
New issue

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

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

Already on GitHub? # to your account

[Configuration] Fix saving of values when no previous value present #7507

Merged
merged 1 commit into from
Jul 21, 2021

Conversation

driusan
Copy link
Collaborator

@driusan driusan commented Jul 14, 2021

When there is a value in ConfigSettings but not Config, the value does
not get saved to the database but silently discarded. This is caused by
the save logic assuming that the ID always exists to update. However,
other logic in the configuration saving deletes from the Config table
if the value is "". This means that once a config option is set to the
empty string it can never be saved again. (This can also happen for
new ConfigSettings.)

Since the name used for the text field in the HTML is the Config table ID
(which doesn't exist) and not the ConfigSetting ID to support ConfigSetting
options that allow multiple entries, the name of the ID is "0" in the form
and can not be converted to a ConfigSetting to change the statement from an
update to an insertOnDuplicateUpdate. AllowMultiple settings, on the other
hand use "add-ConfigSettingID" or "remove-ConfigSettingID" as their name.

This modifies the template to use add-ConfigSettingID when the ConfigID is
"0" in order to have it inserted if it does not exist, regardless of the
AllowMultiple setting for the ConfigSetting.

When there is a value in ConfigSettings but not Config, the value does
not get saved to the database but silently discarded. This is caused by
the save logic assuming that the ID always exists to update. However,
other logic in the configuration saving deletes from the Config table
if the value is "". This means that once a config option is set to the
empty string it can never be saved again. (This can also happen for
new ConfigSettings.)

Since the name used for the text field in the HTML is the Config table ID
(which doesn't exist) and not the ConfigSetting ID to support ConfigSetting
options that allow multiple entries, the name of the ID is "0" in the form
and can not be converted to a ConfigSetting to change the statement from an
update to an insertOnDuplicateUpdate. AllowMultiple settings, on the other
hand use "add-ConfigSettingID" or "remove-ConfigSettingID" as their name.

This modifies the template to use add-ConfigSettingID when the ConfigID is
"0" in order to have it inserted if it does not exist, regardless of the
AllowMultiple setting for the ConfigSetting.
@driusan
Copy link
Collaborator Author

driusan commented Jul 14, 2021

The actual problem is here: https://github.com/aces/Loris/blob/main/modules/configuration/ajax/process.php#L36-L68

But since the name of the HTML element is the Config ID, without changing the smarty template all the backend knows is that it's trying to update ID "0" and there's no way to map that to a ConfigID (which doesn't exist.)

@driusan driusan mentioned this pull request Jul 20, 2021
@driusan driusan merged commit f4d97cd into aces:23.0-release Jul 21, 2021
@driusan driusan added this to the 23.0.5 milestone Aug 16, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants