QA changes
authormonishdeb <monish.deb@webaccessglobal.com>
Sun, 1 Mar 2015 22:03:28 +0000 (03:33 +0530)
committerJamie McClelland <jm@mayfirst.org>
Fri, 6 Mar 2015 19:39:27 +0000 (14:39 -0500)
CRM/Upgrade/Incremental/php/FourFive.php

index c001277db0b43830253a719e564a2b2218cd9ed4..537095fd0bff4f25f8ed6e6566f93f99a757d13c 100755 (executable)
@@ -326,13 +326,34 @@ DROP KEY `{$dao->CONSTRAINT_NAME}`";
     $dao = CRM_Core_DAO::executeQuery($sql);
     while ($dao->fetch()) {
       $formValues = unserialize($dao->form_values);
-      while (list($field, $data_value) = each($formValues)) {
-        if (preg_match('/^custom_/', $field) && is_array($data_value)) {
+        foreach ($formValues as $field => &$data_value) {
+        if (preg_match('/^custom_/', $field) && is_array($data_value) && !array_key_exists("${field}_operator", $formValues)) {
           // This indicates old-style data format. We need to fix it.
           $op = 'and';
-          if ($key = array_search('CiviCRM_OP_OR', $data_value)) {
-            $op = 'or';
-            unset($formValues[$field][$key]);
+          $fieldID = end(explode('_', $field));
+          $htmlType = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $fieldID, 'html_type');
+
+          switch ($htmlType) {
+            case 'CheckBox':
+              if (array_key_exists('CiviCRM_OP_OR', $data_value)) {
+                $op = 'or';
+                unset($data_value['CiviCRM_OP_OR']);
+              }
+              $data_value = array_keys($data_value, 1);
+              break;
+
+            default:
+              $key = array_search('CiviCRM_OP_OR', $data_value);
+              if (!is_null($key)) {
+                $op = 'or';
+                unset($data_value[$key]);
+                if (count($data_value) == 0) {
+                  $customOption = CRM_Core_BAO_CustomOption::getCustomOption($fieldID);
+                  foreach ($customOption as $option) {
+                    $data_value[] = CRM_Utils_Array::value('value', $option);
+                  }
+                }
+              }
           }
 
           // Add new key for the operator.