Merge pull request #2471 from eileenmcnaughton/CRM-14148
[civicrm-core.git] / CRM / Contact / BAO / Contact.php
index 0adb9c26d10945b0d6453a0ff541f7953d30e15a..f0dce175149bf9fb1e663162db1a22855e96b80f 100644 (file)
@@ -1896,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');
@@ -2136,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;
           }
@@ -2497,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();