From 4b5ff63cf1c63d940d744a6034871fb334f0c2cb Mon Sep 17 00:00:00 2001 From: kurund Date: Mon, 10 Feb 2014 10:52:32 -0800 Subject: [PATCH] CRM-14181, remove special handing for enums ---------------------------------------- * CRM-14181: migrate enums to varchar in schema for all tables http://issues.civicrm.org/jira/browse/CRM-14181 --- CRM/Contact/Form/Search/Builder.php | 2 +- CRM/Core/CodeGen/Specification.php | 29 ------------------- CRM/Core/DAO.php | 24 +++------------ CRM/Core/PseudoConstant.php | 8 ----- CRM/Report/Form.php | 4 +-- api/v3/Generic.php | 3 +- api/v3/utils.php | 2 +- .../phpunit/api/v3/SyntaxConformanceTest.php | 2 +- xml/templates/dao.tpl | 3 -- 9 files changed, 9 insertions(+), 68 deletions(-) diff --git a/CRM/Contact/Form/Search/Builder.php b/CRM/Contact/Form/Search/Builder.php index b2abeb0586..d32d2a35d7 100644 --- a/CRM/Contact/Form/Search/Builder.php +++ b/CRM/Contact/Form/Search/Builder.php @@ -429,7 +429,7 @@ class CRM_Contact_Form_Search_Builder extends CRM_Contact_Form_Search { foreach ($entities as $entity) { $fields = civicrm_api3($entity, 'getfields'); foreach ($fields['values'] as $field => $info) { - if (!empty($info['options']) || !empty($info['pseudoconstant']) || !empty($info['option_group_id']) || !empty($info['enumValues'])) { + if (!empty($info['options']) || !empty($info['pseudoconstant']) || !empty($info['option_group_id'])) { $options[$field] = $entity; if (substr($field, -3) == '_id') { $options[substr($field, 0, -3)] = $entity; diff --git a/CRM/Core/CodeGen/Specification.php b/CRM/Core/CodeGen/Specification.php index da2a6e6399..a94e3d7e60 100644 --- a/CRM/Core/CodeGen/Specification.php +++ b/CRM/Core/CodeGen/Specification.php @@ -187,13 +187,6 @@ class CRM_Core_CodeGen_Specification { } $table['fields'] = &$fields; - $table['hasEnum'] = FALSE; - foreach ($table['fields'] as $field) { - if ($field['crmType'] == 'CRM_Utils_Type::T_ENUM') { - $table['hasEnum'] = TRUE; - break; - } - } if ($this->value('primaryKey', $tableXML)) { $this->getPrimaryKey($tableXML->primaryKey, $fields, $table); @@ -259,28 +252,6 @@ class CRM_Core_CodeGen_Specification { $field['size'] = $this->getSize($fieldXML); break; - case 'enum': - $value = (string ) $fieldXML->values; - $field['sqlType'] = 'enum('; - $field['values'] = array(); - $field['enumValues'] = $value; - $values = explode(',', $value); - $first = TRUE; - foreach ($values as $v) { - $v = trim($v); - $field['values'][] = $v; - - if (!$first) { - $field['sqlType'] .= ', '; - } - $first = FALSE; - $field['sqlType'] .= "'$v'"; - } - $field['sqlType'] .= ')'; - $field['phpType'] = $field['sqlType']; - $field['crmType'] = 'CRM_Utils_Type::T_ENUM'; - break; - case 'text': $field['sqlType'] = $field['phpType'] = $type; $field['crmType'] = 'CRM_Utils_Type::T_' . strtoupper($type); diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index afcbbcace5..87f38e8885 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -1383,26 +1383,10 @@ SELECT contact_id case CRM_Utils_Type::T_LONGTEXT: case CRM_Utils_Type::T_EMAIL: default: - if (isset($value['enumValues'])) { - if (isset($value['default'])) { - $object->$dbName = $value['default']; - } - else { - if (is_array($value['enumValues'])) { - $object->$dbName = $value['enumValues'][0]; - } - else { - $defaultValues = explode(',', $value['enumValues']); - $object->$dbName = $defaultValues[0]; - } - } - } - else { - $object->$dbName = $dbName . '_' . $counter; - $maxlength = CRM_Utils_Array::value('maxlength', $value); - if ($maxlength > 0 && strlen($object->$dbName) > $maxlength) { - $object->$dbName = substr($object->$dbName, 0, $value['maxlength']); - } + $object->$dbName = $dbName . '_' . $counter; + $maxlength = CRM_Utils_Array::value('maxlength', $value); + if ($maxlength > 0 && strlen($object->$dbName) > $maxlength) { + $object->$dbName = substr($object->$dbName, 0, $value['maxlength']); } } } diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index 30c01bd552..98f8558a14 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -283,14 +283,6 @@ class CRM_Core_PseudoConstant { return FALSE; } - // If the field is an enum, explode the enum definition and return the array. - if (isset($fieldSpec['enumValues'])) { - // use of a space after the comma is inconsistent in xml - $enumStr = str_replace(', ', ',', $fieldSpec['enumValues']); - $output = explode(',', $enumStr); - return array_combine($output, $output); - } - elseif (!empty($fieldSpec['pseudoconstant'])) { $pseudoconstant = $fieldSpec['pseudoconstant']; // Merge params with schema defaults diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index d62971e68d..9f3a2beec8 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -574,9 +574,7 @@ class CRM_Report_Form extends CRM_Core_Form { break; default: if ($daoOrBaoName && - (array_key_exists('pseudoconstant', $this->_columns[$tableName][$fieldGrp][$fieldName]) - || array_key_exists('enumValues', $this->_columns[$tableName][$fieldGrp][$fieldName])) - ) { + array_key_exists('pseudoconstant', $this->_columns[$tableName][$fieldGrp][$fieldName])) { // with multiple options operator-type is generally multi-select $this->_columns[$tableName][$fieldGrp][$fieldName]['operatorType'] = CRM_Report_Form::OP_MULTISELECT; if (!array_key_exists('options', $this->_columns[$tableName][$fieldGrp][$fieldName])) { diff --git a/api/v3/Generic.php b/api/v3/Generic.php index 3c4fc8a189..fd4d934c54 100644 --- a/api/v3/Generic.php +++ b/api/v3/Generic.php @@ -250,7 +250,6 @@ function civicrm_api3_generic_getoptions($apiRequest) { * - the reason for this is that checking / transformation is done on pseudoconstants but * - if the field is an FK then mysql will enforce the data quality (& we have handling on failure) * @todo - if may be we should define a 'resolve' key on the psuedoconstant for when these rules are not fine enough - * 3) if there is an 'enum' then it is split up into the relevant options * * This function is only split out for the purpose of code clarity / comment block documentation * @param array $metadata the array of metadata that will form the result of the getfields function @@ -259,7 +258,7 @@ function civicrm_api3_generic_getoptions($apiRequest) { * @param array $fieldsToResolve anny field resolutions specifically requested */ function _civicrm_api3_generic_get_metadata_options(&$metadata, $entity, $fieldname, $fieldSpec, $fieldsToResolve){ - if(empty($fieldSpec['pseudoconstant']) && empty($fieldSpec['enumValues'])) { + if (empty($fieldSpec['pseudoconstant'])) { return; } diff --git a/api/v3/utils.php b/api/v3/utils.php index 96bef98ca8..c5ad6c32b9 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -1680,7 +1680,7 @@ function _civicrm_api3_validate_string(&$params, &$fieldName, &$fieldInfo, $enti throw new Exception("Currency not a valid code: $value"); } } - if (!empty($fieldInfo['pseudoconstant']) || !empty($fieldInfo['options']) || !empty($fieldInfo['enumValues'])) { + if (!empty($fieldInfo['pseudoconstant']) || !empty($fieldInfo['options'])) { _civicrm_api3_api_match_pseudoconstant($params, $entity, $fieldName, $fieldInfo); } // Check our field length diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index aab3c1b14b..34d83fee27 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -726,7 +726,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { case CRM_Utils_Type::T_URL: $entity[$field] = 'warm.beer.com'; } - if (!empty($specs['pseudoconstant']) || !empty($specs['enumValues'])) { + if (!empty($specs['pseudoconstant'])) { $options = $this->callAPISuccess($entityName, 'getoptions', array('context' => 'create', 'field' => $field)); if (empty($options['values'])) { } diff --git a/xml/templates/dao.tpl b/xml/templates/dao.tpl index 3d4d29e3dd..2bb97135ee 100644 --- a/xml/templates/dao.tpl +++ b/xml/templates/dao.tpl @@ -213,9 +213,6 @@ class {$table.className} extends CRM_Core_DAO {ldelim} {if $field.default} 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}', {/if} {* field.default *} -{if $field.enumValues} - 'enumValues' => '{$field.enumValues}', -{/if} {* field.enumValues *} {if $field.FKClassName} 'FKClassName' => '{$field.FKClassName}', -- 2.25.1