From d67d221a9c8ac3a4957d2dd0378868119a6b9943 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sun, 5 Jun 2016 23:28:34 +1000 Subject: [PATCH] Further work on soft fail when option value value field doesn't match given data type --- CRM/Admin/Form/Options.php | 13 +++++++++++++ CRM/Core/BAO/OptionValue.php | 9 --------- CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl | 4 ++++ CRM/Utils/Type.php | 8 ++++---- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/CRM/Admin/Form/Options.php b/CRM/Admin/Form/Options.php index d157a48634..6d82d38c07 100644 --- a/CRM/Admin/Form/Options.php +++ b/CRM/Admin/Form/Options.php @@ -376,6 +376,19 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form { } } + $optionGroup = civicrm_api3('OptionGroup', 'get', array( + 'sequential' => 1, + 'name' => $self->_gName, + )); + $dataType = CRM_Core_BAO_OptionGroup::getDataType($optionGroup['id']); + if ($dataType) { + $validate = CRM_Utils_Type::validate($fields['value'], $dataType, FALSE); + if (!$validate) { + CRM_Core_Session::setStatus( + ts('Data Type of the value field for this option value does not match ' . $dataType), + ts('Value field Data Type mismatch')); + } + } return $errors; } diff --git a/CRM/Core/BAO/OptionValue.php b/CRM/Core/BAO/OptionValue.php index 9041298c6c..a529d1b18d 100644 --- a/CRM/Core/BAO/OptionValue.php +++ b/CRM/Core/BAO/OptionValue.php @@ -57,15 +57,6 @@ class CRM_Core_BAO_OptionValue extends CRM_Core_DAO_OptionValue { if (!empty($params['id'])) { $ids = array('optionValue' => $params['id']); } - $dataType = CRM_Core_BAO_OptionGroup::getDataType($params['option_group_id']); - if ($dataType) { - $validate = CRM_Utils_Type::validate($params['value'], $dataType, FALSE); - if(!$validate) { - CRM_Core_Session::setStatus( - ts('Data Type of the value field for this option value does not match ' . $dataType), - ts('Value field Data Type mismatch')); - } - } return CRM_Core_BAO_OptionValue::add($params, $ids); } diff --git a/CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl index 3be47b33cb..d625ae874b 100644 --- a/CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.7.9.mysql.tpl @@ -62,3 +62,7 @@ INSERT INTO `civicrm_option_value` (`option_group_id`, {localize field='label'}label{/localize}, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, {localize field='description'}`description`{/localize}, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `visibility_id`) VALUES (@option_group_id_act, {localize}'{ts escape="sql"}Close Accounting Period{/ts}'{/localize}, @option_group_id_act_val+1, 'Close Accounting Period', NULL, 0, 0, @option_group_id_act_wt+1, {localize}'Close Accounting Period'{/localize}, 0, 1, 1, 2, NULL); + +--CRM- +ALTER TABLE civicrm_option_group +ADD `data_type` varchar(128) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Data Type of Option Group.'; diff --git a/CRM/Utils/Type.php b/CRM/Utils/Type.php index e346af5ee2..9244e8c0dd 100644 --- a/CRM/Utils/Type.php +++ b/CRM/Utils/Type.php @@ -463,12 +463,12 @@ class CRM_Utils_Type { */ public static function dataTypes() { $types = array( - 'integer', + 'Integer', 'String', - 'date', - 'time', + 'Date', + 'Time', 'Timestamp', - 'money', + 'Money', 'Email', ); return array_combine($types, $types); -- 2.25.1