Skip to content

fix(prefs): cast values to string before binary SQL storage#7

Merged
ralflang merged 2 commits into
FRAMEWORK_6_0from
fix/prefs_storage
Jun 18, 2026
Merged

fix(prefs): cast values to string before binary SQL storage#7
ralflang merged 2 commits into
FRAMEWORK_6_0from
fix/prefs_storage

Conversation

@TDannhauer

Copy link
Copy Markdown
Contributor

Summary

  • Cast preference values to strings with strval() before storing them as Horde_Db_Value_Binary in horde_prefs
  • Fixes checkbox and number preferences (e.g. IMP use_trash) that appeared to save successfully but reloaded with empty values
  • Root cause: integer scalars passed to the PDO blob layer were treated as non-strings and persisted as empty binary data

Problem

The preferences UI stores checkbox values via intval(), producing integer 0/1. Horde_Prefs_Storage_Sql passed those values directly to Horde_Db_Value_Binary. The PDO blob helper only serializes string data; integers were written as empty blobs.

Observed symptom in IMP:

  1. User enables “Move deleted messages to Trash”
  2. Horde shows “Your preferences have been updated.”
  3. After reload, the checkbox is unchecked and trash behavior is unchanged
  4. Database row exists but pref_value is empty

Solution

Normalize the value to a string before charset conversion and binary wrapping:

$value = strval(Horde_String::convertCharset($value, 'UTF-8', $charset));
$value = new Horde_Db_Value_Binary($value);

Preference storage is string-based by design; this keeps SQL storage aligned with that contract regardless of upstream scalar types.

Test plan

  • Save IMP preference use_trash as enabled for a test user
  • Confirm horde_prefs.pref_value contains 1 (not an empty blob)
  • Reload preferences UI and verify the checkbox stays checked
  • Verify trash mailbox selection appears after use_trash is enabled
  • Save a checkbox preference as disabled and confirm 0 is stored correctly
  • Regression: save a text/textarea preference and confirm unchanged behavior

Checkbox and number preferences are stored as integers by the UI layer.
Passing those scalars to Horde_Db_Value_Binary caused empty blobs to be
written to horde_prefs, so settings such as IMP use_trash looked saved but
reloaded as disabled.
@TDannhauer TDannhauer requested a review from ralflang June 17, 2026 12:28

@ralflang ralflang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should strval before Horde_String - saves a lot of headache.
Also an opportunity to switch to PSR-4 HordeString class.

ralflang pushed a commit that referenced this pull request Jun 18, 2026
Address review on PR #7:
- Move strval() inside convertCharset() so non-string scalars are normalized
  before charset conversion, not after
- Switch from legacy Horde_String to PSR-4 Horde\Util\HordeString
Address review on PR #7:
- Move strval() inside convertCharset() so non-string scalars are normalized
  before charset conversion, not after
- Switch from legacy Horde_String to PSR-4 Horde\Util\HordeString
@ralflang ralflang force-pushed the fix/prefs_storage branch from d4e89e9 to 8bd7f6d Compare June 18, 2026 03:55
@ralflang ralflang merged commit 7c30f80 into FRAMEWORK_6_0 Jun 18, 2026
0 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants