From 2bcfa9ee452dcdc8b6b4b640349797df9328fea6 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 2 Apr 2020 17:37:59 -0400 Subject: [PATCH] Add serialize column to civicrm_custom_field --- CRM/Core/DAO/CustomField.php | 23 ++++++++++++++- CRM/Core/SelectValues.php | 10 +++++++ .../Incremental/php/FiveTwentySeven.php | 28 ++++++++----------- .../Incremental/sql/5.27.alpha1.mysql.tpl | 3 ++ xml/schema/Core/CustomField.xml | 11 ++++++++ 5 files changed, 58 insertions(+), 17 deletions(-) diff --git a/CRM/Core/DAO/CustomField.php b/CRM/Core/DAO/CustomField.php index 7b8ded42ab..5c5e9a1036 100644 --- a/CRM/Core/DAO/CustomField.php +++ b/CRM/Core/DAO/CustomField.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/CustomField.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:492b1be45dc41c15b35371410a074393) + * (GenCodeChecksum:0b21a2a1f1cba7a76fd8830db1626513) */ /** @@ -224,6 +224,13 @@ class CRM_Core_DAO_CustomField extends CRM_Core_DAO { */ public $option_group_id; + /** + * Serialization method - a non-null value indicates a multi-valued field. + * + * @var int + */ + public $serialize; + /** * Stores Contact Get API params contact reference custom fields. May be used for other filters in the future. * @@ -640,6 +647,20 @@ class CRM_Core_DAO_CustomField extends CRM_Core_DAO { 'labelColumn' => 'title', ], ], + 'serialize' => [ + 'name' => 'serialize', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('Serialize'), + 'description' => ts('Serialization method - a non-null value indicates a multi-valued field.'), + 'where' => 'civicrm_custom_field.serialize', + 'table_name' => 'civicrm_custom_field', + 'entity' => 'CustomField', + 'bao' => 'CRM_Core_BAO_CustomField', + 'localizable' => 0, + 'pseudoconstant' => [ + 'callback' => 'CRM_Core_SelectValues::fieldSerialization', + ], + ], 'filter' => [ 'name' => 'filter', 'type' => CRM_Utils_Type::T_STRING, diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index 6b451af1eb..13800cc69c 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -1179,4 +1179,14 @@ class CRM_Core_SelectValues { return $ret; } + public static function fieldSerialization() { + return [ + CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND => 'separator_bookend', + CRM_Core_DAO::SERIALIZE_SEPARATOR_TRIMMED => 'separator_trimmed', + CRM_Core_DAO::SERIALIZE_JSON => 'json', + CRM_Core_DAO::SERIALIZE_PHP => 'php', + CRM_Core_DAO::SERIALIZE_COMMA => 'comma', + ]; + } + } diff --git a/CRM/Upgrade/Incremental/php/FiveTwentySeven.php b/CRM/Upgrade/Incremental/php/FiveTwentySeven.php index b4f153b3ca..b78bbb3422 100644 --- a/CRM/Upgrade/Incremental/php/FiveTwentySeven.php +++ b/CRM/Upgrade/Incremental/php/FiveTwentySeven.php @@ -52,21 +52,17 @@ class CRM_Upgrade_Incremental_php_FiveTwentySeven extends CRM_Upgrade_Incrementa * (change the x in the function name): */ - // /** - // * Upgrade function. - // * - // * @param string $rev - // */ - // public function upgrade_5_0_x($rev) { - // $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); - // $this->addTask('Do the foo change', 'taskFoo', ...); - // // Additional tasks here... - // // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex. - // // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable. - // } - - // public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) { - // return TRUE; - // } + /** + * Upgrade function. + * + * @param string $rev + */ + public function upgrade_5_27_alpha1($rev) { + // Add column before running sql which populates the column's values + $this->addTask('Add serialize column to civicrm_custom_field', 'addColumn', + 'civicrm_custom_field', 'serialize', "int unsigned DEFAULT NULL COMMENT 'Serialization method - a non-null value indicates a multi-valued field.'" + ); + $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); + } } diff --git a/CRM/Upgrade/Incremental/sql/5.27.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.27.alpha1.mysql.tpl index 0621e8fb19..9f3c462146 100644 --- a/CRM/Upgrade/Incremental/sql/5.27.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.27.alpha1.mysql.tpl @@ -1,3 +1,6 @@ {* file to handle db changes in 5.27.alpha1 during upgrade *} +UPDATE civicrm_custom_field SET serialize = 1, html_type = REPLACE(html_type, 'Multi-', '') +WHERE html_type LIKE 'Multi-%' OR html_type = 'CheckBox'; + ALTER TABLE `civicrm_contribution_recur` CHANGE `amount` `amount` DECIMAL( 20,2 ) COMMENT 'Amount to be collected (including any sales tax) by payment processor each recurrence.'; diff --git a/xml/schema/Core/CustomField.xml b/xml/schema/Core/CustomField.xml index 0db6507227..0fc76b8dc1 100644 --- a/xml/schema/Core/CustomField.xml +++ b/xml/schema/Core/CustomField.xml @@ -281,6 +281,17 @@ 5.6 SET NULL + + serialize + int unsigned + Serialize + 255 + Serialization method - a non-null value indicates a multi-valued field. + + CRM_Core_SelectValues::fieldSerialization + + 5.26 + filter varchar -- 2.25.1