Merge pull request #2471 from eileenmcnaughton/CRM-14148
[civicrm-core.git] / CRM / Contact / BAO / Contact.php
index 49fd4b065d18ff4d4c9ea704158639dc98963c7c..f0dce175149bf9fb1e663162db1a22855e96b80f 100644 (file)
@@ -1188,9 +1188,9 @@ WHERE id={$id}; ";
             'middle_name',
             'last_name',
             'job_title',
-            'gender',
-            'individual_prefix',
-            'individual_suffix',
+            'gender_id',
+            'prefix_id',
+            'suffix_id',
             'birth_date',
             'organization_name',
             'legal_name',
@@ -1205,9 +1205,9 @@ WHERE id={$id}; ";
             'middle_name',
             'last_name',
             'job_title',
-            'gender',
-            'individual_prefix',
-            'individual_suffix',
+            'gender_id',
+            'prefix_id',
+            'suffix_id',
             'birth_date',
             'household_name',
             'is_deceased',
@@ -1278,11 +1278,13 @@ WHERE id={$id}; ";
    *
    * currentlty we are using importable fields as exportable fields
    *
-   * @param int     $contactType contact Type
+   * @param int|string $contactType contact Type
    * @param boolean $status true while exporting primary contacts
    * @param boolean $export true when used during export
    * @param boolean $search true when used during search, might conflict with export param?
    *
+   * @param bool $withMultiRecord
+   *
    * @return array array of exportable Fields
    * @access public
    * @static
@@ -1443,9 +1445,9 @@ WHERE id={$id}; ";
               'middle_name',
               'last_name',
               'job_title',
-              'gender',
-              'individual_prefix',
-              'individual_suffix',
+              'gender_id',
+              'prefix_id',
+              'suffix_id',
               'birth_date',
               'organization_name',
               'legal_name',
@@ -1466,9 +1468,9 @@ WHERE id={$id}; ";
               'middle_name',
               'last_name',
               'job_title',
-              'gender',
-              'individual_prefix',
-              'individual_suffix',
+              'gender_id',
+              'prefix_id',
+              'suffix_id',
               'birth_date',
               'household_name',
               'email_greeting_custom',
@@ -1534,9 +1536,10 @@ WHERE id={$id}; ";
    * given a set of flat profile style field names, create a hierarchy
    * for query to use and crete the right sql
    *
-   * @param array $properties a flat return properties name value array
-   * @param int   $contactId contact id
+   * @param $fields
+   * @param int $contactId contact id
    *
+   * @internal param array $properties a flat return properties name value array
    * @return array a hierarchical property tree if appropriate
    * @access public
    * @static
@@ -1604,6 +1607,10 @@ WHERE id={$id}; ";
    * $params boolean $isPrimaryExist if true, return primary contact location type otherwise null
    * $params boolean $skipDefaultPriamry if true, return primary contact location type otherwise null
    *
+   * @param $contactId
+   * @param bool $skipDefaultPriamry
+   * @param null $block
+   *
    * @return int $locationType location_type_id
    * @access public
    * @static
@@ -1889,7 +1896,7 @@ ORDER BY civicrm_email.is_primary DESC";
     }
 
     // get the billing location type
-    $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
+    $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
     $billingLocationTypeId = array_search('Billing', $locationTypes);
 
     $blocks = array('email', 'phone', 'im', 'openid');
@@ -1906,6 +1913,7 @@ ORDER BY civicrm_email.is_primary DESC";
     }
 
     $primaryPhoneLoc = NULL;
+    $session = CRM_Core_Session::singleton();
     foreach ($params as $key => $value) {
       $fieldName = $locTypeId = $typeId = NULL;
       list($fieldName, $locTypeId, $typeId) = CRM_Utils_System::explode('-', $key, 3);
@@ -2067,10 +2075,11 @@ ORDER BY civicrm_email.is_primary DESC";
             $value .= ' ' . $params[$key . '_time'];
           }
 
-          // updateBlankCustomInfo flag is false && $value is blank, do not proceed
-          if (!CRM_Utils_Array::value('updateBlankCustomInfo', $params, TRUE) && ($value == '' || !isset($value))) {
+          // if auth source is not checksum / login && $value is blank, do not proceed - CRM-10128
+          if (($session->get('authSrc') & (CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN)) == 0 &&
+            ($value == '' || !isset($value))) {
             continue;
-          }
+          } 
 
           $valueId = NULL;
           if (CRM_Utils_Array::value('customRecordValues', $params)) {
@@ -2127,6 +2136,21 @@ ORDER BY civicrm_email.is_primary DESC";
               }
             }
           }
+          else if (in_array($key, 
+              array('nick_name', 
+                'job_title', 
+                'middle_name', 
+                'birth_date', 
+                'gender_id',
+                'current_employer', 
+                'prefix_id', 
+                'suffix_id')) &&
+            ($value == '' || !isset($value)) &&
+            ($session->get('authSrc') & (CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN)) == 0) {
+            // CRM-10128: if auth source is not checksum / login && $value is blank, do not fill $data with empty value 
+            // to avoid update with empty values
+            continue;
+          } 
           else {
             $data[$key] = $value;
           }
@@ -2488,7 +2512,9 @@ AND       civicrm_openid.is_primary = 1";
     // fields that are required to calculate greeting and
     // also other fields used in tokens etc,
     // hence we need to retrieve it again.
-    $contact->find(TRUE);
+    if ( $contact->_query !== FALSE ) {
+      $contact->find(TRUE);
+    }
 
     // store object values to an array
     $contactDetails = array();