From 2a5c9b4d3d8c7ec41d930979cfe21921e5b4b4cf Mon Sep 17 00:00:00 2001 From: Coleman Watts <coleman@civicrm.org> Date: Fri, 8 Dec 2017 16:52:51 -0500 Subject: [PATCH] CRM-13123 - Add serialization metadata to schema --- CRM/Contact/DAO/Contact.php | 4 +- CRM/Contact/DAO/Group.php | 5 +- CRM/Contact/DAO/SavedSearch.php | 5 +- CRM/Contribute/DAO/ContributionPage.php | 11 +++- CRM/Core/CodeGen/Specification.php | 1 + CRM/Core/DAO.php | 68 +++++++++++++++++++++- CRM/Core/DAO/CustomGroup.php | 3 +- CRM/Core/DAO/Domain.php | 14 +---- CRM/Core/DAO/PrevNextCache.php | 3 +- CRM/Core/DAO/PrintLabel.php | 3 +- CRM/Core/DAO/Setting.php | 3 +- CRM/Core/DAO/UFGroup.php | 3 +- CRM/Core/DAO/UFJoin.php | 3 +- CRM/Event/DAO/Participant.php | 4 +- CRM/Financial/DAO/PaymentProcessor.php | 3 +- CRM/Member/DAO/MembershipBlock.php | 3 +- CRM/Pledge/DAO/PledgeBlock.php | 3 +- CRM/Queue/DAO/QueueItem.php | 9 +-- CRM/Report/DAO/ReportInstance.php | 3 +- tests/phpunit/CRM/Core/DAOTest.php | 41 +++++++++++++ xml/schema/Contact/Contact.xml | 3 + xml/schema/Contact/Group.xml | 3 + xml/schema/Contact/SavedSearch.xml | 3 + xml/schema/Contribute/ContributionPage.xml | 9 +++ xml/schema/Core/CustomGroup.xml | 1 + xml/schema/Core/Domain.xml | 12 +--- xml/schema/Core/PrevNextCache.xml | 1 + xml/schema/Core/PrintLabel.xml | 1 + xml/schema/Core/Setting.xml | 1 + xml/schema/Core/UFGroup.xml | 1 + xml/schema/Core/UFJoin.xml | 1 + xml/schema/Cxn/Cxn.xml | 1 + xml/schema/Event/Participant.xml | 3 + xml/schema/Financial/PaymentProcessor.xml | 1 + xml/schema/Member/MembershipBlock.xml | 1 + xml/schema/Pledge/PledgeBlock.xml | 1 + xml/schema/Queue/QueueItem.xml | 5 +- xml/schema/Report/ReportInstance.xml | 1 + xml/templates/dao.tpl | 5 +- 39 files changed, 202 insertions(+), 44 deletions(-) diff --git a/CRM/Contact/DAO/Contact.php b/CRM/Contact/DAO/Contact.php index 9c738c102f..837f0a3cd7 100644 --- a/CRM/Contact/DAO/Contact.php +++ b/CRM/Contact/DAO/Contact.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Contact/Contact.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:b1dbc34947126531f2fd11aaa30b14a5) + * (GenCodeChecksum:395cdbb5eaf3b1f74fb87f93269d8336) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -442,6 +442,7 @@ class CRM_Contact_DAO_Contact extends CRM_Core_DAO { 'entity' => 'Contact', 'bao' => 'CRM_Contact_BAO_Contact', 'localizable' => 0, + 'serialize' => self::SERIALIZE_SEPARATOR_BOOKEND, 'html' => array( 'type' => 'Select', ) , @@ -709,6 +710,7 @@ class CRM_Contact_DAO_Contact extends CRM_Core_DAO { 'entity' => 'Contact', 'bao' => 'CRM_Contact_BAO_Contact', 'localizable' => 0, + 'serialize' => self::SERIALIZE_SEPARATOR_BOOKEND, 'html' => array( 'type' => 'Select', ) , diff --git a/CRM/Contact/DAO/Group.php b/CRM/Contact/DAO/Group.php index f3a4ad3091..f77b220fc6 100644 --- a/CRM/Contact/DAO/Group.php +++ b/CRM/Contact/DAO/Group.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Contact/Group.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:4c9dfb678f18129fd9d667de3727dfeb) + * (GenCodeChecksum:848664fcd390bd178325b0d991c8e947) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -321,6 +321,7 @@ class CRM_Contact_DAO_Group extends CRM_Core_DAO { 'entity' => 'Group', 'bao' => 'CRM_Contact_BAO_Group', 'localizable' => 0, + 'serialize' => self::SERIALIZE_PHP, ) , 'where_tables' => array( 'name' => 'where_tables', @@ -331,6 +332,7 @@ class CRM_Contact_DAO_Group extends CRM_Core_DAO { 'entity' => 'Group', 'bao' => 'CRM_Contact_BAO_Group', 'localizable' => 0, + 'serialize' => self::SERIALIZE_PHP, ) , 'group_type' => array( 'name' => 'group_type', @@ -343,6 +345,7 @@ class CRM_Contact_DAO_Group extends CRM_Core_DAO { 'entity' => 'Group', 'bao' => 'CRM_Contact_BAO_Group', 'localizable' => 0, + 'serialize' => self::SERIALIZE_SEPARATOR_BOOKEND, 'pseudoconstant' => array( 'optionGroupName' => 'group_type', 'optionEditPath' => 'civicrm/admin/options/group_type', diff --git a/CRM/Contact/DAO/SavedSearch.php b/CRM/Contact/DAO/SavedSearch.php index f6d87c8da1..bfecfb6bbc 100644 --- a/CRM/Contact/DAO/SavedSearch.php +++ b/CRM/Contact/DAO/SavedSearch.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Contact/SavedSearch.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:8e799b35db1b6a38deee5a757d4183c0) + * (GenCodeChecksum:0341555885ddaf5dbc8e4d6cfe1d899c) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -146,6 +146,7 @@ class CRM_Contact_DAO_SavedSearch extends CRM_Core_DAO { 'entity' => 'SavedSearch', 'bao' => 'CRM_Contact_BAO_SavedSearch', 'localizable' => 0, + 'serialize' => self::SERIALIZE_PHP, ) , 'mapping_id' => array( 'name' => 'mapping_id', @@ -187,6 +188,7 @@ class CRM_Contact_DAO_SavedSearch extends CRM_Core_DAO { 'entity' => 'SavedSearch', 'bao' => 'CRM_Contact_BAO_SavedSearch', 'localizable' => 0, + 'serialize' => self::SERIALIZE_PHP, ) , 'where_tables' => array( 'name' => 'where_tables', @@ -197,6 +199,7 @@ class CRM_Contact_DAO_SavedSearch extends CRM_Core_DAO { 'entity' => 'SavedSearch', 'bao' => 'CRM_Contact_BAO_SavedSearch', 'localizable' => 0, + 'serialize' => self::SERIALIZE_PHP, ) , ); CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); diff --git a/CRM/Contribute/DAO/ContributionPage.php b/CRM/Contribute/DAO/ContributionPage.php index 27a9fa5c2c..d26a27bc0a 100644 --- a/CRM/Contribute/DAO/ContributionPage.php +++ b/CRM/Contribute/DAO/ContributionPage.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Contribute/ContributionPage.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:00d0eb39eb657241b67e9d5b12bc09d8) + * (GenCodeChecksum:2bc7d9380c552fe9995f8403f757cd09) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -481,6 +481,15 @@ class CRM_Contribute_DAO_ContributionPage extends CRM_Core_DAO { 'entity' => 'ContributionPage', 'bao' => 'CRM_Contribute_BAO_ContributionPage', 'localizable' => 0, + 'serialize' => self::SERIALIZE_SEPARATOR_TRIMMED, + 'html' => array( + 'type' => 'Select', + ) , + 'pseudoconstant' => array( + 'optionGroupName' => 'recur_frequency_units', + 'keyColumn' => 'name', + 'optionEditPath' => 'civicrm/admin/options/recur_frequency_units', + ) ) , 'is_recur_interval' => array( 'name' => 'is_recur_interval', diff --git a/CRM/Core/CodeGen/Specification.php b/CRM/Core/CodeGen/Specification.php index 7184d738d2..63119cf49e 100644 --- a/CRM/Core/CodeGen/Specification.php +++ b/CRM/Core/CodeGen/Specification.php @@ -361,6 +361,7 @@ class CRM_Core_CodeGen_Specification { $field['headerPattern'] = $this->value('headerPattern', $fieldXML); $field['dataPattern'] = $this->value('dataPattern', $fieldXML); $field['uniqueName'] = $this->value('uniqueName', $fieldXML); + $field['serialize'] = $this->value('serialize', $fieldXML); $field['html'] = $this->value('html', $fieldXML); if (!empty($field['html'])) { $validOptions = array( diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 503a896e76..a15abff357 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -64,7 +64,12 @@ class CRM_Core_DAO extends DB_DataObject { BULK_INSERT_COUNT = 200, BULK_INSERT_HIGH_COUNT = 200, QUERY_FORMAT_WILDCARD = 1, - QUERY_FORMAT_NO_QUOTES = 2; + QUERY_FORMAT_NO_QUOTES = 2, + SERIALIZE_SEPARATOR_BOOKEND = 1, + SERIALIZE_SEPARATOR_TRIMMED = 2, + SERIALIZE_COMMA = 3, + SERIALIZE_JSON = 4, + SERIALIZE_PHP = 5; /** * Define entities that shouldn't be created or deleted when creating/ deleting @@ -2593,4 +2598,65 @@ SELECT contact_id return TRUE; } + /** + * Transform an array to a serialized string for database storage. + * + * @param array|NULL $value + * @param $serializationType + * @return string|NULL + */ + public static function serializeField($value, $serializationType) { + if ($value === NULL) { + return NULL; + } + switch ($serializationType) { + case self::SERIALIZE_SEPARATOR_BOOKEND: + return $value === array() ? '' : CRM_Utils_Array::implodePadded($value); + + case self::SERIALIZE_SEPARATOR_TRIMMED: + return is_array($value) ? implode(self::VALUE_SEPARATOR, $value) : $value; + + case self::SERIALIZE_COMMA: + return is_array($value) ? implode(',', $value) : $value; + + case self::SERIALIZE_JSON: + return is_array($value) ? json_encode($value) : $value; + + case self::SERIALIZE_PHP: + return is_array($value) ? serialize($value) : $value; + } + } + + /** + * Transform a serialized string from the database into an array. + * + * @param string|null $value + * @param $serializationType + * @return array|null + */ + public static function unSerializeField($value, $serializationType) { + if ($value === NULL) { + return NULL; + } + if ($value === '') { + return array(); + } + switch ($serializationType) { + case self::SERIALIZE_SEPARATOR_BOOKEND: + return (array) CRM_Utils_Array::explodePadded($value); + + case self::SERIALIZE_SEPARATOR_TRIMMED: + return explode(self::VALUE_SEPARATOR, trim($value)); + + case self::SERIALIZE_COMMA: + return explode(',', trim(str_replace(', ', '', $value))); + + case self::SERIALIZE_JSON: + return strlen($value) ? json_decode($value, TRUE) : array(); + + case self::SERIALIZE_PHP: + return strlen($value) ? unserialize($value) : array(); + } + } + } diff --git a/CRM/Core/DAO/CustomGroup.php b/CRM/Core/DAO/CustomGroup.php index 1c45988a68..48f3b186fd 100644 --- a/CRM/Core/DAO/CustomGroup.php +++ b/CRM/Core/DAO/CustomGroup.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Core/CustomGroup.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:5b2dac3266e0184dc4eaa6de10c9d401) + * (GenCodeChecksum:4b960c311aed67174e9c55901ba3993b) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -276,6 +276,7 @@ class CRM_Core_DAO_CustomGroup extends CRM_Core_DAO { 'entity' => 'CustomGroup', 'bao' => 'CRM_Core_BAO_CustomGroup', 'localizable' => 0, + 'serialize' => self::SERIALIZE_SEPARATOR_BOOKEND, ) , 'style' => array( 'name' => 'style', diff --git a/CRM/Core/DAO/Domain.php b/CRM/Core/DAO/Domain.php index b59999af9f..9a7adf6461 100644 --- a/CRM/Core/DAO/Domain.php +++ b/CRM/Core/DAO/Domain.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Core/Domain.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:50edefeb24aa64d2125df018985cd701) + * (GenCodeChecksum:7bc078fa4adebf142c73c95fab321f25) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -173,15 +173,11 @@ class CRM_Core_DAO_Domain extends CRM_Core_DAO { 'type' => CRM_Utils_Type::T_TEXT, 'title' => ts('Domain Configuration') , 'description' => 'Backend configuration.', - 'rows' => 20, - 'cols' => 80, 'table_name' => 'civicrm_domain', 'entity' => 'Domain', 'bao' => 'CRM_Core_BAO_Domain', 'localizable' => 0, - 'html' => array( - 'type' => 'TextArea', - ) , + 'serialize' => self::SERIALIZE_PHP, ) , 'version' => array( 'name' => 'version', @@ -221,15 +217,11 @@ class CRM_Core_DAO_Domain extends CRM_Core_DAO { 'type' => CRM_Utils_Type::T_TEXT, 'title' => ts('Language Customizations') , 'description' => 'Locale specific string overrides', - 'rows' => 20, - 'cols' => 80, 'table_name' => 'civicrm_domain', 'entity' => 'Domain', 'bao' => 'CRM_Core_BAO_Domain', 'localizable' => 0, - 'html' => array( - 'type' => 'TextArea', - ) , + 'serialize' => self::SERIALIZE_PHP, ) , ); CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); diff --git a/CRM/Core/DAO/PrevNextCache.php b/CRM/Core/DAO/PrevNextCache.php index 7ff6035743..0c5af39cc5 100644 --- a/CRM/Core/DAO/PrevNextCache.php +++ b/CRM/Core/DAO/PrevNextCache.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Core/PrevNextCache.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:edf9dd4b38ca08a34dbc6990ac954af2) + * (GenCodeChecksum:cfce4435348e53ba9941ce5ed223c05b) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -170,6 +170,7 @@ class CRM_Core_DAO_PrevNextCache extends CRM_Core_DAO { 'entity' => 'PrevNextCache', 'bao' => 'CRM_Core_BAO_PrevNextCache', 'localizable' => 0, + 'serialize' => self::SERIALIZE_PHP, ) , 'is_selected' => array( 'name' => 'is_selected', diff --git a/CRM/Core/DAO/PrintLabel.php b/CRM/Core/DAO/PrintLabel.php index c2e379a788..59847d3704 100644 --- a/CRM/Core/DAO/PrintLabel.php +++ b/CRM/Core/DAO/PrintLabel.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Core/PrintLabel.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:af33d193b72fd8c8bf260c0625c7acf6) + * (GenCodeChecksum:60a1aaca1bbf19fe5b752afa03e8fd34) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -233,6 +233,7 @@ class CRM_Core_DAO_PrintLabel extends CRM_Core_DAO { 'entity' => 'PrintLabel', 'bao' => 'CRM_Core_DAO_PrintLabel', 'localizable' => 0, + 'serialize' => self::SERIALIZE_JSON, ) , 'is_default' => array( 'name' => 'is_default', diff --git a/CRM/Core/DAO/Setting.php b/CRM/Core/DAO/Setting.php index 7648107cb6..4449695e02 100644 --- a/CRM/Core/DAO/Setting.php +++ b/CRM/Core/DAO/Setting.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Core/Setting.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:a9b0b7aaf6ae42696ce402c1ff9acb89) + * (GenCodeChecksum:5aa73137509e3760555c0f3d1d746b05) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -166,6 +166,7 @@ class CRM_Core_DAO_Setting extends CRM_Core_DAO { 'entity' => 'Setting', 'bao' => 'CRM_Core_BAO_Setting', 'localizable' => 0, + 'serialize' => self::SERIALIZE_PHP, ) , 'domain_id' => array( 'name' => 'domain_id', diff --git a/CRM/Core/DAO/UFGroup.php b/CRM/Core/DAO/UFGroup.php index ced384ae31..e957729b3a 100644 --- a/CRM/Core/DAO/UFGroup.php +++ b/CRM/Core/DAO/UFGroup.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Core/UFGroup.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:d87b52f7baf5aa4e4ccaf26c6e7acabc) + * (GenCodeChecksum:2c943baba637124caec29c4aefeb9228) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -268,6 +268,7 @@ class CRM_Core_DAO_UFGroup extends CRM_Core_DAO { 'entity' => 'UFGroup', 'bao' => 'CRM_Core_BAO_UFGroup', 'localizable' => 0, + 'serialize' => self::SERIALIZE_SEPARATOR_TRIMMED, ) , 'title' => array( 'name' => 'title', diff --git a/CRM/Core/DAO/UFJoin.php b/CRM/Core/DAO/UFJoin.php index a85d2e6e5e..d28ebd7595 100644 --- a/CRM/Core/DAO/UFJoin.php +++ b/CRM/Core/DAO/UFJoin.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Core/UFJoin.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:fde4a7125f1dd6d9e5081b534f151db6) + * (GenCodeChecksum:141d4903e67ac8bce639e3db9c7ba875) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -229,6 +229,7 @@ class CRM_Core_DAO_UFJoin extends CRM_Core_DAO { 'entity' => 'UFJoin', 'bao' => 'CRM_Core_BAO_UFJoin', 'localizable' => 0, + 'serialize' => self::SERIALIZE_JSON, ) , ); CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); diff --git a/CRM/Event/DAO/Participant.php b/CRM/Event/DAO/Participant.php index 9142d60ba4..1bbcdaa842 100644 --- a/CRM/Event/DAO/Participant.php +++ b/CRM/Event/DAO/Participant.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Event/Participant.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:89138cc7e79eac37b1b499084956428f) + * (GenCodeChecksum:444d0ee69773ce242341f8544e192087) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -292,6 +292,7 @@ class CRM_Event_DAO_Participant extends CRM_Core_DAO { 'entity' => 'Participant', 'bao' => 'CRM_Event_BAO_Participant', 'localizable' => 0, + 'serialize' => self::SERIALIZE_SEPARATOR_TRIMMED, 'html' => array( 'type' => 'Select', ) , @@ -352,6 +353,7 @@ class CRM_Event_DAO_Participant extends CRM_Core_DAO { 'entity' => 'Participant', 'bao' => 'CRM_Event_BAO_Participant', 'localizable' => 0, + 'serialize' => self::SERIALIZE_SEPARATOR_BOOKEND, ) , 'participant_is_test' => array( 'name' => 'is_test', diff --git a/CRM/Financial/DAO/PaymentProcessor.php b/CRM/Financial/DAO/PaymentProcessor.php index c585f1945d..f554656440 100644 --- a/CRM/Financial/DAO/PaymentProcessor.php +++ b/CRM/Financial/DAO/PaymentProcessor.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Financial/PaymentProcessor.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:223b44e4b9e2994f724d2dbd79f575e4) + * (GenCodeChecksum:5a228384ec4b687a6961505b12d40512) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -482,6 +482,7 @@ class CRM_Financial_DAO_PaymentProcessor extends CRM_Core_DAO { 'entity' => 'PaymentProcessor', 'bao' => 'CRM_Financial_BAO_PaymentProcessor', 'localizable' => 0, + 'serialize' => self::SERIALIZE_JSON, ) , ); CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); diff --git a/CRM/Member/DAO/MembershipBlock.php b/CRM/Member/DAO/MembershipBlock.php index f20ca244a4..db4feda293 100644 --- a/CRM/Member/DAO/MembershipBlock.php +++ b/CRM/Member/DAO/MembershipBlock.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Member/MembershipBlock.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:3ee510fab11783acf6ee994f090436f6) + * (GenCodeChecksum:b99880f7b9c20c98f428dd694d8264ba) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -204,6 +204,7 @@ class CRM_Member_DAO_MembershipBlock extends CRM_Core_DAO { 'entity' => 'MembershipBlock', 'bao' => 'CRM_Member_BAO_MembershipBlock', 'localizable' => 0, + 'serialize' => self::SERIALIZE_PHP, ) , 'membership_type_default' => array( 'name' => 'membership_type_default', diff --git a/CRM/Pledge/DAO/PledgeBlock.php b/CRM/Pledge/DAO/PledgeBlock.php index a8b3fa8405..e6cfa9fdce 100644 --- a/CRM/Pledge/DAO/PledgeBlock.php +++ b/CRM/Pledge/DAO/PledgeBlock.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Pledge/PledgeBlock.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:27ee8365a58c51c15fcf0ae78b2f5f32) + * (GenCodeChecksum:630f1a7378136b8cc3edcd82a96279d6) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -190,6 +190,7 @@ class CRM_Pledge_DAO_PledgeBlock extends CRM_Core_DAO { 'entity' => 'PledgeBlock', 'bao' => 'CRM_Pledge_BAO_PledgeBlock', 'localizable' => 0, + 'serialize' => self::SERIALIZE_SEPARATOR_TRIMMED, ) , 'is_pledge_interval' => array( 'name' => 'is_pledge_interval', diff --git a/CRM/Queue/DAO/QueueItem.php b/CRM/Queue/DAO/QueueItem.php index 8f688be708..90889d85e0 100644 --- a/CRM/Queue/DAO/QueueItem.php +++ b/CRM/Queue/DAO/QueueItem.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Queue/QueueItem.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:6ca85e3a41502dda3e60a1c53a83c67f) + * (GenCodeChecksum:9049b4828c213985dea2180555f28568) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -79,7 +79,7 @@ class CRM_Queue_DAO_QueueItem extends CRM_Core_DAO { */ public $release_time; /** - * Serialized queue + * Serialized queue data * * @var text */ @@ -168,12 +168,13 @@ class CRM_Queue_DAO_QueueItem extends CRM_Core_DAO { 'data' => array( 'name' => 'data', 'type' => CRM_Utils_Type::T_TEXT, - 'title' => ts('Queue item datas') , - 'description' => 'Serialized queue', + 'title' => ts('Queue item data') , + 'description' => 'Serialized queue data', 'table_name' => 'civicrm_queue_item', 'entity' => 'QueueItem', 'bao' => 'CRM_Queue_BAO_QueueItem', 'localizable' => 0, + 'serialize' => self::SERIALIZE_PHP, ) , ); CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); diff --git a/CRM/Report/DAO/ReportInstance.php b/CRM/Report/DAO/ReportInstance.php index ee3f06b0f8..7ba08fad41 100644 --- a/CRM/Report/DAO/ReportInstance.php +++ b/CRM/Report/DAO/ReportInstance.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Report/ReportInstance.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:e28abdd2a3696c4a6072dfbfd4f54d68) + * (GenCodeChecksum:09ffdd1693f38f5790d4c9c00d3c5d2f) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -356,6 +356,7 @@ class CRM_Report_DAO_ReportInstance extends CRM_Core_DAO { 'entity' => 'ReportInstance', 'bao' => 'CRM_Report_BAO_ReportInstance', 'localizable' => 0, + 'serialize' => self::SERIALIZE_PHP, ) , 'is_active' => array( 'name' => 'is_active', diff --git a/tests/phpunit/CRM/Core/DAOTest.php b/tests/phpunit/CRM/Core/DAOTest.php index b381daf215..399ecb6e40 100644 --- a/tests/phpunit/CRM/Core/DAOTest.php +++ b/tests/phpunit/CRM/Core/DAOTest.php @@ -392,4 +392,45 @@ class CRM_Core_DAOTest extends CiviUnitTestCase { } } + /** + * @return array + */ + public function serializationMethods() { + $constants = array(); + $simpleData = array( + NULL, + array('Foo', 'Bar', '3', '4', '5'), + array(), + array('0'), + ); + $complexData = array( + array( + 'foo' => 'bar', + 'baz' => array('1', '2', '3', array('one', 'two')), + '3' => '0', + ), + ); + $daoInfo = new ReflectionClass('CRM_Core_DAO'); + foreach ($daoInfo->getConstants() as $constant => $val) { + if ($constant == 'SERIALIZE_JSON' || $constant == 'SERIALIZE_PHP') { + $constants[] = array($val, array_merge($simpleData, $complexData)); + } + elseif (strpos($constant, 'SERIALIZE_') === 0) { + $constants[] = array($val, $simpleData); + } + } + return $constants; + } + + /** + * @dataProvider serializationMethods + */ + public function testFieldSerialization($method, $sampleData) { + foreach ($sampleData as $value) { + $serialized = CRM_Core_DAO::serializeField($value, $method); + $newValue = CRM_Core_DAO::unSerializeField($serialized, $method); + $this->assertEquals($value, $newValue); + } + } + } diff --git a/xml/schema/Contact/Contact.xml b/xml/schema/Contact/Contact.xml index 76acad1d61..e6a596c670 100644 --- a/xml/schema/Contact/Contact.xml +++ b/xml/schema/Contact/Contact.xml @@ -64,6 +64,7 @@ <type>Select</type> <multiple>1</multiple> </html> + <serialize>SEPARATOR_BOOKEND</serialize> <add>1.5</add> </field> <index> @@ -288,7 +289,9 @@ </pseudoconstant> <html> <type>Select</type> + <multiple>1</multiple> </html> + <serialize>SEPARATOR_BOOKEND</serialize> </field> <index> <name>index_preferred_communication_method</name> diff --git a/xml/schema/Contact/Group.xml b/xml/schema/Contact/Group.xml index fb9c1bd671..68ad6eb3f4 100644 --- a/xml/schema/Contact/Group.xml +++ b/xml/schema/Contact/Group.xml @@ -104,6 +104,7 @@ <type>text</type> <title>Tables For Select Clause</title> <comment>the tables to be included in a select data</comment> + <serialize>PHP</serialize> <add>1.6</add> </field> <field> @@ -111,6 +112,7 @@ <type>text</type> <title>Tables For Where Clause</title> <comment>the tables to be included in the count statement</comment> + <serialize>PHP</serialize> <add>1.6</add> </field> <field> @@ -122,6 +124,7 @@ <pseudoconstant> <optionGroupName>group_type</optionGroupName> </pseudoconstant> + <serialize>SEPARATOR_BOOKEND</serialize> <add>1.9</add> </field> <field> diff --git a/xml/schema/Contact/SavedSearch.xml b/xml/schema/Contact/SavedSearch.xml index f35330c73c..4da3530787 100644 --- a/xml/schema/Contact/SavedSearch.xml +++ b/xml/schema/Contact/SavedSearch.xml @@ -33,6 +33,7 @@ <type>text</type> <import>true</import> <comment>Submitted form values for this search</comment> + <serialize>PHP</serialize> <add>1.1</add> </field> <field> @@ -75,6 +76,7 @@ <type>text</type> <title>Select Tables</title> <comment>the tables to be included in a select data</comment> + <serialize>PHP</serialize> <add>1.6</add> </field> <field> @@ -82,6 +84,7 @@ <type>text</type> <title>Where Tables</title> <comment>the tables to be included in the count statement</comment> + <serialize>PHP</serialize> <add>1.6</add> </field> </table> diff --git a/xml/schema/Contribute/ContributionPage.xml b/xml/schema/Contribute/ContributionPage.xml index 7c821d0177..ace8c0f500 100644 --- a/xml/schema/Contribute/ContributionPage.xml +++ b/xml/schema/Contribute/ContributionPage.xml @@ -129,6 +129,15 @@ <type>varchar</type> <length>128</length> <comment>Supported recurring frequency units.</comment> + <pseudoconstant> + <optionGroupName>recur_frequency_units</optionGroupName> + <keyColumn>name</keyColumn> + </pseudoconstant> + <html> + <type>Select</type> + <multiple>1</multiple> + </html> + <serialize>SEPARATOR_TRIMMED</serialize> <add>2.1</add> </field> <field> diff --git a/xml/schema/Core/CustomGroup.xml b/xml/schema/Core/CustomGroup.xml index a9bdbdba80..de3a4d70f1 100644 --- a/xml/schema/Core/CustomGroup.xml +++ b/xml/schema/Core/CustomGroup.xml @@ -69,6 +69,7 @@ <title>Custom Group Subtype</title> <length>255</length> <comment>linking custom group for dynamic object</comment> + <serialize>SEPARATOR_BOOKEND</serialize> <add>1.6</add> </field> <field> diff --git a/xml/schema/Core/Domain.xml b/xml/schema/Core/Domain.xml index c3a6020313..f947878559 100644 --- a/xml/schema/Core/Domain.xml +++ b/xml/schema/Core/Domain.xml @@ -91,11 +91,7 @@ <type>text</type> <title>Domain Configuration</title> <comment>Backend configuration.</comment> - <html> - <type>TextArea</type> - <rows>20</rows> - <cols>80</cols> - </html> + <serialize>PHP</serialize> <add>1.6</add> </field> <field> @@ -138,11 +134,7 @@ <type>text</type> <title>Language Customizations</title> <comment>Locale specific string overrides</comment> - <html> - <type>TextArea</type> - <rows>20</rows> - <cols>80</cols> - </html> + <serialize>PHP</serialize> <add>3.2</add> </field> </table> diff --git a/xml/schema/Core/PrevNextCache.xml b/xml/schema/Core/PrevNextCache.xml index 7c74a19cee..5fda09bd84 100644 --- a/xml/schema/Core/PrevNextCache.xml +++ b/xml/schema/Core/PrevNextCache.xml @@ -54,6 +54,7 @@ <title>Prev Next Data</title> <type>longtext</type> <comment>cached snapshot of the serialized data</comment> + <serialize>PHP</serialize> <add>3.4</add> </field> <field> diff --git a/xml/schema/Core/PrintLabel.xml b/xml/schema/Core/PrintLabel.xml index b5e2ee0ec5..06b1684163 100644 --- a/xml/schema/Core/PrintLabel.xml +++ b/xml/schema/Core/PrintLabel.xml @@ -71,6 +71,7 @@ <type>longtext</type> <comment>contains json encode configurations options</comment> <add>4.4</add> + <serialize>JSON</serialize> </field> <field> <name>is_default</name> diff --git a/xml/schema/Core/Setting.xml b/xml/schema/Core/Setting.xml index d2865d352b..0a5263fab7 100644 --- a/xml/schema/Core/Setting.xml +++ b/xml/schema/Core/Setting.xml @@ -46,6 +46,7 @@ <name>value</name> <type>text</type> <comment>data associated with this group / name combo</comment> + <serialize>PHP</serialize> <add>4.1</add> </field> <field> diff --git a/xml/schema/Core/UFGroup.xml b/xml/schema/Core/UFGroup.xml index 9e2f6faf4d..69784bf224 100644 --- a/xml/schema/Core/UFGroup.xml +++ b/xml/schema/Core/UFGroup.xml @@ -34,6 +34,7 @@ <length>255</length> <import>true</import> <comment>This column will store a comma separated list of the type(s) of profile fields.</comment> + <serialize>SEPARATOR_TRIMMED</serialize> <add>2.1</add> </field> <field> diff --git a/xml/schema/Core/UFJoin.xml b/xml/schema/Core/UFJoin.xml index 54b291fd08..368a3e0c0a 100644 --- a/xml/schema/Core/UFJoin.xml +++ b/xml/schema/Core/UFJoin.xml @@ -101,6 +101,7 @@ <title>Profile Use Data</title> <type>longtext</type> <comment>Json serialized array of data used by the ufjoin.module</comment> + <serialize>JSON</serialize> <add>4.5</add> </field> </table> diff --git a/xml/schema/Cxn/Cxn.xml b/xml/schema/Cxn/Cxn.xml index c432f0915f..f8d7ee2c22 100644 --- a/xml/schema/Cxn/Cxn.xml +++ b/xml/schema/Cxn/Cxn.xml @@ -72,6 +72,7 @@ <name>options</name> <type>text</type> <comment>Options for the service (JSON)</comment> + <serialize>JSON</serialize> <add>4.6</add> </field> diff --git a/xml/schema/Event/Participant.xml b/xml/schema/Event/Participant.xml index b35eb253b8..5d341014f2 100644 --- a/xml/schema/Event/Participant.xml +++ b/xml/schema/Event/Participant.xml @@ -95,7 +95,9 @@ </pseudoconstant> <html> <type>Select</type> + <multiple>1</multiple> </html> + <serialize>SEPARATOR_TRIMMED</serialize> <headerPattern>/(participant.)?(role)$/i</headerPattern> <import>true</import> <type>varchar</type> @@ -142,6 +144,7 @@ <headerPattern>/^(f(ee\s)?level)$/i</headerPattern> <type>text</type> <import>true</import> + <serialize>SEPARATOR_BOOKEND</serialize> <comment>Populate with the label (text) associated with a fee level for paid events with multiple levels. Note that we store the label value and not the key </comment> diff --git a/xml/schema/Financial/PaymentProcessor.xml b/xml/schema/Financial/PaymentProcessor.xml index 05e94fca44..0538fcc698 100644 --- a/xml/schema/Financial/PaymentProcessor.xml +++ b/xml/schema/Financial/PaymentProcessor.xml @@ -238,6 +238,7 @@ <type>text</type> <default>NULL</default> <comment>array of accepted credit card types</comment> + <serialize>JSON</serialize> <add>4.7</add> </field> </table> diff --git a/xml/schema/Member/MembershipBlock.xml b/xml/schema/Member/MembershipBlock.xml index b78cea9cd5..89503bb66b 100644 --- a/xml/schema/Member/MembershipBlock.xml +++ b/xml/schema/Member/MembershipBlock.xml @@ -47,6 +47,7 @@ <type>varchar</type> <length>1024</length> <comment>Membership types to be exposed by this block</comment> + <serialize>PHP</serialize> <add>1.5</add> <!-- changed from varchar 255 to 1024 in 4.6 beta 2 --> <change>4.6</change> diff --git a/xml/schema/Pledge/PledgeBlock.xml b/xml/schema/Pledge/PledgeBlock.xml index 5467caed27..6dd3b8a659 100644 --- a/xml/schema/Pledge/PledgeBlock.xml +++ b/xml/schema/Pledge/PledgeBlock.xml @@ -50,6 +50,7 @@ <type>varchar</type> <length>128</length> <comment>Delimited list of supported frequency units</comment> + <serialize>SEPARATOR_TRIMMED</serialize> <add>2.1</add> </field> <field> diff --git a/xml/schema/Queue/QueueItem.xml b/xml/schema/Queue/QueueItem.xml index cbbb20de3e..e67bca990a 100644 --- a/xml/schema/Queue/QueueItem.xml +++ b/xml/schema/Queue/QueueItem.xml @@ -62,9 +62,10 @@ <field> <name>data</name> - <title>Queue item datas</title> + <title>Queue item data</title> <type>text</type> - <comment>Serialized queue</comment> + <comment>Serialized queue data</comment> + <serialize>PHP</serialize> </field> <index> <name>index_queueids</name> diff --git a/xml/schema/Report/ReportInstance.xml b/xml/schema/Report/ReportInstance.xml index 6b556a445a..9961b9028e 100644 --- a/xml/schema/Report/ReportInstance.xml +++ b/xml/schema/Report/ReportInstance.xml @@ -121,6 +121,7 @@ <type>text</type> <import>true</import> <comment>Submitted form values for this report</comment> + <serialize>PHP</serialize> <add>2.2</add> </field> <field> diff --git a/xml/templates/dao.tpl b/xml/templates/dao.tpl index 4ba882ad1e..4d7174d7ed 100644 --- a/xml/templates/dao.tpl +++ b/xml/templates/dao.tpl @@ -170,7 +170,10 @@ class {$table.className} extends CRM_Core_DAO {ldelim} {if $field.FKClassName} 'FKClassName' => '{$field.FKClassName}', -{/if} {* field.FKClassName *} +{/if} +{if $field.serialize} + 'serialize' => self::SERIALIZE_{$field.serialize|strtoupper}, +{/if} {if $field.html} {assign var=htmlOptions value=$field.html} 'html' => array( -- 2.25.1