From 6cee3c2c7e13637b67681f5da5e6f03b4d846899 Mon Sep 17 00:00:00 2001 From: Samuel Vanhove Date: Tue, 30 Jun 2020 15:43:51 -0400 Subject: [PATCH] dev/core#1670 simpler version using copyCustomFields instead of CopyGeneric --- CRM/Core/BAO/Address.php | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/CRM/Core/BAO/Address.php b/CRM/Core/BAO/Address.php index 81fc24573c..909415ae3f 100644 --- a/CRM/Core/BAO/Address.php +++ b/CRM/Core/BAO/Address.php @@ -157,25 +157,15 @@ class CRM_Core_BAO_Address extends CRM_Core_DAO_Address { self::fixSharedAddress($params); } - if (empty($params['id']) && isset($params['master_id']) && !CRM_Utils_System::isNull($params['master_id'])) { - // copy from master to ensure we have custom fields - // but keep all params data that might have been updated above - $fieldsFix = [ - 'replace' => $params, - ]; - $address = CRM_Core_DAO::copyGeneric( - 'CRM_Core_DAO_Address', - ['id' => $params['master_id']], - NULL, - $fieldsFix - ); - } - else { - $address->copyValues($params); - $address->save(); - } + $address->copyValues($params); + $address->save(); if ($address->id) { + // first get custom field from master address if any + if (isset($params['master_id']) && !CRM_Utils_System::isNull($params['master_id'])) { + $address->copyCustomFields($params['master_id'], $address->id); + } + if (isset($params['custom'])) { $addressCustom = $params['custom']; } -- 2.25.1