Merge pull request #22599 from civicrm/5.46
[civicrm-core.git] / CRM / Dedupe / Merger.php
index f3763fffaa10df00832fba2f84515cfc7d3bb329..48e000f2a8cace9352699647acfec8fbf5c4c5f8 100644 (file)
@@ -683,11 +683,11 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    * @throws \CiviCRM_API3_Exception
    * @throws \Civi\API\Exception\UnauthorizedException
    */
-  protected static function createContact($contactID, $params) {
+  protected static function updateContact(int $contactID, $params): void {
     // This parameter causes blank fields to be be emptied out.
     // We can probably remove.
     $params['updateBlankLocInfo'] = TRUE;
-    $data = self::formatProfileContactParams($params, [], $contactID);
+    $data = self::formatProfileContactParams($params, $contactID);
     CRM_Contact_BAO_Contact::create($data);
   }
 
@@ -700,25 +700,19 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    * eliminate a toxic function.
    *
    * @param array $params
-   * @param $fields
    * @param int $contactID
-   * @param int $ufGroupId
-   * @param null $ctype
    *
    * @return array
    */
   private static function formatProfileContactParams(
-    &$params,
-    $fields,
-    int $contactID,
-    $ufGroupId = NULL,
-    $ctype = NULL
+    $params,
+    int $contactID
   ) {
 
     $data = $contactDetails = [];
 
     // get the contact details (hier)
-    $details = CRM_Contact_BAO_Contact::getHierContactDetails($contactID, $fields);
+    $details = CRM_Contact_BAO_Contact::getHierContactDetails($contactID, []);
 
     $contactDetails = $details[$contactID];
     $data['contact_type'] = $contactDetails['contact_type'] ?? NULL;
@@ -749,13 +743,6 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
       }
     }
 
-    if ($ctype == 'Organization') {
-      $data['organization_name'] = $contactDetails['organization_name'] ?? NULL;
-    }
-    elseif ($ctype == 'Household') {
-      $data['household_name'] = $contactDetails['household_name'] ?? NULL;
-    }
-
     $locationType = [];
     $count = 1;
 
@@ -1012,20 +999,6 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
       $data['contact_type'] = 'Individual';
     }
 
-    //set the values for checkboxes (do_not_email, do_not_mail, do_not_trade, do_not_phone)
-    $privacy = CRM_Core_SelectValues::privacy();
-    foreach ($privacy as $key => $value) {
-      if (array_key_exists($key, $fields)) {
-        // do not reset values for existing contacts, if fields are added to a profile
-        if (array_key_exists($key, $params)) {
-          $data[$key] = $params[$key];
-          if (empty($params[$key])) {
-            $data[$key] = 0;
-          }
-        }
-      }
-    }
-
     return $data;
   }
 
@@ -1120,7 +1093,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    *
    * @param bool $checkPermissions
    *   Respect logged in user permissions.
-   * @param bool|NULL $reloadCacheIfEmpty
+   * @param bool|null $reloadCacheIfEmpty
    *  If not set explicitly this is calculated but it is preferred that it be set
    *  per comments on isSelected above.
    *
@@ -1898,7 +1871,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
       if (!isset($submitted['suffix_id']) && !empty($migrationInfo['main_details']['suffix_id'])) {
         $submitted['suffix_id'] = $migrationInfo['main_details']['suffix_id'];
       }
-      self::createContact($mainId, $submitted);
+      self::updateContact($mainId, $submitted);
     }
     $transaction->commit();
     CRM_Utils_Hook::post('merge', 'Contact', $mainId);
@@ -2652,7 +2625,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
   /**
    * Build up the location block for the contact in dedupe-screen display format.
    *
-   * @param integer $cid
+   * @param int $cid
    * @param array $blockInfo
    * @param string $blockName
    *