Add serialize column to civicrm_custom_field
authorColeman Watts <coleman@civicrm.org>
Thu, 2 Apr 2020 21:37:59 +0000 (17:37 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 14 May 2020 00:03:19 +0000 (20:03 -0400)
CRM/Core/DAO/CustomField.php
CRM/Core/SelectValues.php
CRM/Upgrade/Incremental/php/FiveTwentySeven.php
CRM/Upgrade/Incremental/sql/5.27.alpha1.mysql.tpl
xml/schema/Core/CustomField.xml

index 7b8ded42abbfa91cb479cb2d422d345a29f5f985..5c5e9a1036ed3234c76b5fdda16b04d637d937e7 100644 (file)
@@ -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,
index 6b451af1ebde9bf00baeec118eeb34d13ae187a8..13800cc69cef55529762ede303cc0303bb52a9df 100644 (file)
@@ -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',
+    ];
+  }
+
 }
index b4f153b3cae641de9c50ce074cdfbef6f2d939f3..b78bbb34225ac51dc0ab6f2fbe3245dfa83d097b 100644 (file)
@@ -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);
+  }
 
 }
index 0621e8fb194aaf06c2c85fd1d10d6ffaf27315cd..9f3c4621460908a1262e1a0f14b9f44722376c8b 100644 (file)
@@ -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.';
index 0db65072278a4ceee2e3ebe86aba76c2326fa530..0fc76b8dc1f38994fc23cc1948ebabfbb84346bd 100644 (file)
     <add>5.6</add>
     <onDelete>SET NULL</onDelete>
   </foreignKey>
+  <field>
+    <name>serialize</name>
+    <type>int unsigned</type>
+    <title>Serialize</title>
+    <length>255</length>
+    <comment>Serialization method - a non-null value indicates a multi-valued field.</comment>
+    <pseudoconstant>
+      <callback>CRM_Core_SelectValues::fieldSerialization</callback>
+    </pseudoconstant>
+    <add>5.26</add>
+  </field>
   <field>
     <name>filter</name>
     <type>varchar</type>