Update copyright date for 2020
[civicrm-core.git] / api / v3 / Generic / Update.php
index 8ab6953534edb73ce2aff5bdd76c7d571b706e66..f983ba4b76dabee08bf6b26316009fb7db4cdbdc 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2017                                |
+ | Copyright CiviCRM LLC (c) 2004-2020                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -64,7 +64,7 @@ function civicrm_api3_generic_update($apiRequest) {
   if (strtolower($apiRequest['entity']) == 'contribution') {
     return civicrm_api($apiRequest['entity'], 'create', $apiRequest['params']);
   }
-  $seek = array($key_id => $apiRequest['params'][$key_id], 'version' => $apiRequest['version']);
+  $seek = [$key_id => $apiRequest['params'][$key_id], 'version' => $apiRequest['version']];
   $existing = civicrm_api($apiRequest['entity'], 'get', $seek);
   if ($existing['is_error']) {
     return $existing;
@@ -77,6 +77,12 @@ function civicrm_api3_generic_update($apiRequest) {
   }
 
   $existing = array_pop($existing['values']);
+  // Per Unit test testUpdateHouseholdWithAll we don't want to load these from the DB
+  // if they are not passed in then we'd rather they are calculated.
+  // Note update is not recomended anyway...
+  foreach (['sort_name', 'display_name'] as $fieldToNotSet) {
+    unset($existing[$fieldToNotSet]);
+  }
   $p = array_merge($existing, $apiRequest['params']);
   return civicrm_api($apiRequest['entity'], 'create', $p);
 }