Details
-
Type: Improvement
-
Status: Done/Fixed
-
Priority: Major
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.4.0
-
Fix Version/s: 4.7.30
-
Component/s: None
-
Labels:
-
Versioning Impact:Patch (backwards-compatible bug fixes)
Description
Currently there are 3 methods of storing serialized data in the db:
- A simple list separated by CRM_Core_DAO::VALUE_SEPARATOR
- An array serialized with php serialize()
- A JSON string
No metadata currently exists in our xml/daos about this, so serialization during data storage and retrieval is implemented ad-hoc usually at the BAO level. This has resulted in massive code duplication (there are 469 uses of CRM_Core_DAO::VALUE_SEPARATOR in our codebase) and quite a bit of inconsistency. For example, calling the contact API, there are 2 serialized fields: contact_sub_type and preferred_communication_method. The former accepts a string or an array as input, and always returns an array. The latter only accepts a string as input (and it performs no validation to ensure the input has been serialized properly), but returns an array.
3 steps to fixing this situation:
1) Add Metadata:
We should add metadata to tell our DAOs that serialized fields have a php datatype of array or object, not string. And we should specify the method of serialization.
2) Handle input:
To minimize breakage and refactoring needed, DAOs will accept input either in serialized or unserialized form. Data that's already serialized will pass-through. Data that isn't will be serialized.
3) Handle output:
Ideally DAOs will always output arrays and objects when fetching serialized fields. Currently however they almost always output raw serialized strings. Since it would break lots of tests and functionality to fix this right now, we may need to somehow roll it in incrementally and or defer this step to a later date.
Attachments
Issue Links
- supplements
-
CRM-12548 API not saving preferred_communication_method
- Done/Fixed
- links to