Merge pull request #22673 from agileware/CIVICRM-1924
[civicrm-core.git] / CRM / Dedupe / Merger.php
index 8f10cc9693e16564d24644f4363ddd9795d4f698..152273f9926ea43e7b5ac6f79ed844558d5748eb 100644 (file)
@@ -102,7 +102,7 @@ class CRM_Dedupe_Merger {
         'rel_table_custom_groups' => [
           'title' => ts('Custom Groups'),
           'tables' => ['civicrm_custom_group'],
-          'url' => CRM_Utils_System::url('civicrm/admin/custom/group', 'reset=1'),
+          'url' => CRM_Utils_System::url('civicrm/admin/custom/group'),
         ],
         'rel_table_uf_groups' => [
           'title' => ts('Profiles'),
@@ -607,7 +607,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     foreach ($sqls as $sql) {
       CRM_Core_DAO::executeQuery($sql, [], TRUE, NULL, TRUE);
     }
-    CRM_Dedupe_Merger::addMembershipToRealtedContacts($mainId);
+    CRM_Dedupe_Merger::addMembershipToRelatedContacts($mainId);
   }
 
   /**
@@ -687,7 +687,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     // 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,51 +700,23 @@ 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,
-    $contactID = NULL,
-    $ufGroupId = NULL,
-    $ctype = NULL
+    $params,
+    int $contactID
   ) {
 
     $data = $contactDetails = [];
 
     // get the contact details (hier)
-    if ($contactID) {
-      $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;
-      $data['contact_sub_type'] = $contactDetails['contact_sub_type'] ?? NULL;
-    }
-    else {
-      //we should get contact type only if contact
-      if ($ufGroupId) {
-        $data['contact_type'] = CRM_Core_BAO_UFField::getProfileType($ufGroupId, TRUE, FALSE, TRUE);
-
-        //special case to handle profile with only contact fields
-        if ($data['contact_type'] == 'Contact') {
-          $data['contact_type'] = 'Individual';
-        }
-        elseif (CRM_Contact_BAO_ContactType::isaSubType($data['contact_type'])) {
-          $data['contact_type'] = CRM_Contact_BAO_ContactType::getBasicType($data['contact_type']);
-        }
-      }
-      elseif ($ctype) {
-        $data['contact_type'] = $ctype;
-      }
-      else {
-        $data['contact_type'] = 'Individual';
-      }
-    }
+    $contactDetails = $details[$contactID];
+    $data['contact_type'] = $contactDetails['contact_type'] ?? NULL;
+    $data['contact_sub_type'] = $contactDetails['contact_sub_type'] ?? NULL;
 
     //fix contact sub type CRM-5125
     if (array_key_exists('contact_sub_type', $params) &&
@@ -771,25 +743,12 @@ 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;
 
-    if ($contactID) {
-      //add contact id
-      $data['contact_id'] = $contactID;
-      $primaryLocationType = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactID);
-    }
-    else {
-      $defaultLocation = CRM_Core_BAO_LocationType::getDefault();
-      $defaultLocationId = $defaultLocation->id;
-    }
+    //add contact id
+    $data['contact_id'] = $contactID;
+    $primaryLocationType = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactID);
 
     $billingLocationTypeId = CRM_Core_BAO_LocationType::getBilling();
 
@@ -812,18 +771,13 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
       [$fieldName, $locTypeId, $typeId] = CRM_Utils_System::explode('-', $key, 3);
 
       if ($locTypeId == 'Primary') {
-        if ($contactID) {
-          if (in_array($fieldName, $blocks)) {
-            $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactID, FALSE, $fieldName);
-          }
-          else {
-            $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactID, FALSE, 'address');
-          }
-          $primaryLocationType = $locTypeId;
+        if (in_array($fieldName, $blocks)) {
+          $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactID, FALSE, $fieldName);
         }
         else {
-          $locTypeId = $defaultLocationId;
+          $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactID, FALSE, 'address');
         }
+        $primaryLocationType = $locTypeId;
       }
 
       if (is_numeric($locTypeId) &&
@@ -1045,23 +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;
-          }
-        }
-        elseif (!$contactID) {
-          $data[$key] = 0;
-        }
-      }
-    }
-
     return $data;
   }
 
@@ -1156,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.
    *
@@ -1980,7 +1917,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    * @throws \CRM_Core_Exception
    * @throws \CiviCRM_API3_Exception
    */
-  public static function addMembershipToRealtedContacts($contactID) {
+  public static function addMembershipToRelatedContacts($contactID) {
     $dao = new CRM_Member_DAO_Membership();
     $dao->contact_id = $contactID;
     $dao->is_test = 0;
@@ -2688,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
    *