Only call function when applicable
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 26 Dec 2022 22:15:29 +0000 (11:15 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 4 Jan 2023 20:38:01 +0000 (09:38 +1300)
Big whitespace change as IF is moved

CRM/Dedupe/Merger.php

index 935ed72557b6178e9e9beabc716ca3db640742d5..ca76a69c785e70be46968607c87f7a057183b933 100644 (file)
@@ -1783,7 +1783,9 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
       $submitted = [];
     }
     foreach ($submitted as $key => $value) {
-      $submitted = self::processCustomFields($mainId, $key, $cFields, $submitted, $value);
+      if (substr($key, 0, 7) === 'custom_') {
+        $submitted = self::processCustomFields($mainId, $key, $cFields, $submitted, $value);
+      }
     }
 
     // move view only custom fields CRM-5362
@@ -2203,77 +2205,75 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    * @throws \CRM_Core_Exception
    */
   protected static function processCustomFields($mainId, $key, $cFields, $submitted, $value) {
-    if (substr($key, 0, 7) === 'custom_') {
-      $fid = (int) substr($key, 7);
-      if (empty($cFields[$fid])) {
-        return $submitted;
-      }
-      $htmlType = $cFields[$fid]['attributes']['html_type'];
-      $isSerialized = CRM_Core_BAO_CustomField::isSerialized($cFields[$fid]['attributes']);
-
-      if ($htmlType === 'File') {
-        // Handled in CustomField->move(). Tested in testMergeCustomFields.
-        unset($submitted["custom_$fid"]);
-      }
-      elseif (!$isSerialized && ($htmlType === 'Select Country' || $htmlType === 'Select State/Province')) {
-        // @todo Test in testMergeCustomFields disabled as this does not work, Handle in CustomField->move().
-        $submitted[$key] = CRM_Core_BAO_CustomField::displayValue($value, $fid);
-      }
-      elseif ($htmlType === 'Select Date') {
-        if ($cFields[$fid]['attributes']['is_view']) {
-          $submitted[$key] = date('YmdHis', strtotime($submitted[$key]));
-        }
-      }
-      elseif ($isSerialized) {
-        // Merge values from both contacts for multivalue fields, CRM-4385
-        // get the existing custom values from db.
-        $customParams = ['entityID' => $mainId, $key => TRUE];
-        $customfieldValues = CRM_Core_BAO_CustomValueTable::getValues($customParams);
-        if (!empty($customfieldValues[$key])) {
-          $existingValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, $customfieldValues[$key]);
-          if (is_array($existingValue) && !empty($existingValue)) {
-            $mergeValue = $submittedCustomFields = [];
-            if ($value === 'null') {
-              // CRM-19074 if someone has deliberately chosen to overwrite with 'null', respect it.
-              $submitted[$key] = $value;
+    $fid = (int) substr($key, 7);
+    if (empty($cFields[$fid])) {
+      return $submitted;
+    }
+    $htmlType = $cFields[$fid]['attributes']['html_type'];
+    $isSerialized = CRM_Core_BAO_CustomField::isSerialized($cFields[$fid]['attributes']);
+
+    if ($htmlType === 'File') {
+      // Handled in CustomField->move(). Tested in testMergeCustomFields.
+      unset($submitted["custom_$fid"]);
+    }
+    elseif (!$isSerialized && ($htmlType === 'Select Country' || $htmlType === 'Select State/Province')) {
+      // @todo Test in testMergeCustomFields disabled as this does not work, Handle in CustomField->move().
+      $submitted[$key] = CRM_Core_BAO_CustomField::displayValue($value, $fid);
+    }
+    elseif ($htmlType === 'Select Date') {
+      if ($cFields[$fid]['attributes']['is_view']) {
+        $submitted[$key] = date('YmdHis', strtotime($submitted[$key]));
+      }
+    }
+    elseif ($isSerialized) {
+      // Merge values from both contacts for multivalue fields, CRM-4385
+      // get the existing custom values from db.
+      $customParams = ['entityID' => $mainId, $key => TRUE];
+      $customfieldValues = CRM_Core_BAO_CustomValueTable::getValues($customParams);
+      if (!empty($customfieldValues[$key])) {
+        $existingValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, $customfieldValues[$key]);
+        if (is_array($existingValue) && !empty($existingValue)) {
+          $mergeValue = $submittedCustomFields = [];
+          if ($value === 'null') {
+            // CRM-19074 if someone has deliberately chosen to overwrite with 'null', respect it.
+            $submitted[$key] = $value;
+          }
+          else {
+            if ($value) {
+              $submittedCustomFields = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
             }
-            else {
-              if ($value) {
-                $submittedCustomFields = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
-              }
 
-              // CRM-19653: overwrite or add the existing custom field value with dupicate contact's
-              // custom field value stored at $submittedCustomValue.
-              foreach ($submittedCustomFields as $k => $v) {
-                if ($v != '' && !in_array($v, $mergeValue)) {
-                  $mergeValue[] = $v;
-                }
+            // CRM-19653: overwrite or add the existing custom field value with dupicate contact's
+            // custom field value stored at $submittedCustomValue.
+            foreach ($submittedCustomFields as $k => $v) {
+              if ($v != '' && !in_array($v, $mergeValue)) {
+                $mergeValue[] = $v;
               }
+            }
 
-              //keep state and country as array format.
-              //for checkbox and m-select format w/ VALUE_SEPARATOR
-              if (in_array($htmlType, ['CheckBox', 'Select'])) {
-                $submitted[$key] = CRM_Utils_Array::implodePadded($mergeValue);
-              }
-              else {
-                $submitted[$key] = $mergeValue;
-              }
+            //keep state and country as array format.
+            //for checkbox and m-select format w/ VALUE_SEPARATOR
+            if (in_array($htmlType, ['CheckBox', 'Select'])) {
+              $submitted[$key] = CRM_Utils_Array::implodePadded($mergeValue);
+            }
+            else {
+              $submitted[$key] = $mergeValue;
             }
           }
         }
-        elseif (in_array($htmlType, ['Select Country', 'Select State/Province'])) {
-          //we require submitted values should be in array format
-          if ($value) {
-            $mergeValueArray = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
-            //hack to remove null values from array.
-            $mergeValue = [];
-            foreach ($mergeValueArray as $k => $v) {
-              if ($v != '') {
-                $mergeValue[] = $v;
-              }
+      }
+      elseif (in_array($htmlType, ['Select Country', 'Select State/Province'])) {
+        //we require submitted values should be in array format
+        if ($value) {
+          $mergeValueArray = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
+          //hack to remove null values from array.
+          $mergeValue = [];
+          foreach ($mergeValueArray as $k => $v) {
+            if ($v != '') {
+              $mergeValue[] = $v;
             }
-            $submitted[$key] = $mergeValue;
           }
+          $submitted[$key] = $mergeValue;
         }
       }
     }