From d51a6a62628c0e6536affc7ca17a1b813a1942c0 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 1 Jul 2020 10:31:29 -0400 Subject: [PATCH] Fix version check for custom field serialize col --- CRM/Core/BAO/CustomField.php | 6 +++--- CRM/Core/BAO/Domain.php | 10 ++++++++++ api/v3/CustomField.php | 2 +- xml/schema/Core/CustomField.xml | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index 140f1e0a53..7c5084b68c 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -396,7 +396,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { // Temporary hack - in 5.27 a new field is added to civicrm_custom_field. There is a high // risk this function is called before the upgrade page can be reached and if // so it will potentially result in fatal error. - $serializeField = CRM_Core_BAO_Domain::isDBUpdateRequired() ? '' : "$cfTable.serialize,"; + $serializeField = CRM_Core_BAO_Domain::isDBVersionAtLeast('5.27.alpha1') ? '' : "$cfTable.serialize,"; $query = "SELECT $cfTable.id, $cfTable.label, $cgTable.title, @@ -498,7 +498,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $fields[$dao->id]['is_required'] = $dao->is_required; $fields[$dao->id]['table_name'] = $dao->table_name; $fields[$dao->id]['column_name'] = $dao->column_name; - $fields[$dao->id]['serialize'] = $dao->serialize; + $fields[$dao->id]['serialize'] = $serializeField ? $dao->serialize : (int) self::isSerialized($dao); $fields[$dao->id]['where'] = $dao->table_name . '.' . $dao->column_name; // Probably we should use a different fn to get the extends tables but this is a refactor so not changing that now. $fields[$dao->id]['extends_table'] = array_key_exists($dao->extends, CRM_Core_BAO_CustomQuery::$extendsMap) ? CRM_Core_BAO_CustomQuery::$extendsMap[$dao->extends] : ''; @@ -2548,7 +2548,7 @@ WHERE cf.id = %1 AND cg.is_multiple = 1"; if ($html_type === 'CheckBox' || strpos($html_type, 'Multi') !== FALSE) { return TRUE; } - // Otherwise this is the new standard as of 5.26 + // Otherwise this is the new standard as of 5.27 return is_object($field) ? !empty($field->serialize) : !empty($field['serialize']); } diff --git a/CRM/Core/BAO/Domain.php b/CRM/Core/BAO/Domain.php index acbb2a93fd..14e885a6e2 100644 --- a/CRM/Core/BAO/Domain.php +++ b/CRM/Core/BAO/Domain.php @@ -95,6 +95,16 @@ class CRM_Core_BAO_Domain extends CRM_Core_DAO_Domain { return version_compare($dbVersion, $codeVersion) < 0; } + /** + * Checks that the current DB schema is at least $min version + * + * @param string|number $min + * @return bool + */ + public static function isDBVersionAtLeast($min) { + return version_compare(self::version(), $min, '>='); + } + /** * Get the location values of a domain. * diff --git a/api/v3/CustomField.php b/api/v3/CustomField.php index d9f54afbc6..49cb0e45cd 100644 --- a/api/v3/CustomField.php +++ b/api/v3/CustomField.php @@ -122,7 +122,7 @@ function civicrm_api3_custom_field_delete($params) { * @return array */ function civicrm_api3_custom_field_get($params) { - if (!CRM_Core_BAO_Domain::isDBUpdateRequired() && ($params['legacy_html_type'] ?? TRUE) && !empty($params['return'])) { + if (!CRM_Core_BAO_Domain::isDBVersionAtLeast('5.27.alpha1') && ($params['legacy_html_type'] ?? TRUE) && !empty($params['return'])) { if (is_array($params['return'])) { $params['return'][] = 'serialize'; } diff --git a/xml/schema/Core/CustomField.xml b/xml/schema/Core/CustomField.xml index 0fc76b8dc1..2bfd28999a 100644 --- a/xml/schema/Core/CustomField.xml +++ b/xml/schema/Core/CustomField.xml @@ -290,7 +290,7 @@ CRM_Core_SelectValues::fieldSerialization - 5.26 + 5.27 filter -- 2.25.1