CRM-14181, remove special handing for enums
authorkurund <kurund@civicrm.org>
Mon, 10 Feb 2014 18:52:32 +0000 (10:52 -0800)
committerkurund <kurund@civicrm.org>
Mon, 10 Feb 2014 18:52:32 +0000 (10:52 -0800)
----------------------------------------
* 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
CRM/Core/CodeGen/Specification.php
CRM/Core/DAO.php
CRM/Core/PseudoConstant.php
CRM/Report/Form.php
api/v3/Generic.php
api/v3/utils.php
tests/phpunit/api/v3/SyntaxConformanceTest.php
xml/templates/dao.tpl

index b2abeb0586eb76ef582eea5d6434c44802253686..d32d2a35d758bbeae3b6e5dd8b9d60f3ab543bb6 100644 (file)
@@ -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;
index da2a6e6399c39b354cfc4521ee854d6f4afc33fd..a94e3d7e60453bcec6f7dc8b76fb0b1cfd0f4fa2 100644 (file)
@@ -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);
index afcbbcace5f8db3f70a9948f870d45a3707cfa22..87f38e888565ab999dd828fe24bfe8d37b5b2fed 100644 (file)
@@ -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']);
               }
           }
         }
index 30c01bd552927de8e29da5cfd84147ca30b414d7..98f8558a143adeb9d90399dd592741b26c52456c 100644 (file)
@@ -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
index d62971e68d851e876782a08d4010b89d0f9fa05d..9f3a2beec8cf86e91d293d70f18f5ef47f59dc9a 100644 (file)
@@ -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])) {
index 3c4fc8a189947e6261c6931d4ecbd2533f9520ec..fd4d934c54314d4de65f139543300e0536054c71 100644 (file)
@@ -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;
   }
 
index 96bef98ca8bd6a61416b27a17b0e015ff81f780d..c5ad6c32b9e659899129134c4ff516c095802cce 100644 (file)
@@ -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
index aab3c1b14bdae4496a51e445576156f0e77cc8ca..34d83fee276a1099a991cb768856939d0b100f60 100644 (file)
@@ -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'])) {
         }
index 3d4d29e3dd5cc9981873e6eb8fdfff0d9cc1c37b..2bb97135ee960412accaf4cf673e7851bff409b5 100644 (file)
@@ -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}',