From 29b2323117d549d4e155fc03afad2b2ff9c61deb Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Mon, 30 Aug 2021 13:01:02 +1000 Subject: [PATCH] Fix Address test failure by passing the hook through to copyCustomFields and fix Contribution Recur test failures by doing some cleanup --- CRM/Core/BAO/Address.php | 7 ++++--- CRM/Core/DAO.php | 5 +++-- tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php | 2 ++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CRM/Core/BAO/Address.php b/CRM/Core/BAO/Address.php index 14516f1f7b..480501d815 100644 --- a/CRM/Core/BAO/Address.php +++ b/CRM/Core/BAO/Address.php @@ -104,7 +104,7 @@ class CRM_Core_BAO_Address extends CRM_Core_DAO_Address { // call the function to sync shared address and create relationships // if address is already shared, share master_id with all children and update relationships accordingly // (prevent chaining 2) CRM-21214 - self::processSharedAddress($address->id, $params); + self::processSharedAddress($address->id, $params, $hook); // lets call the post hook only after we've done all the follow on processing CRM_Utils_Hook::post($hook, 'Address', $address->id, $address); @@ -956,8 +956,9 @@ SELECT is_primary, * Address id. * @param array $params * Associated array of address params. + * @param string $parentOperation Operation being taken on the parent entity. */ - public static function processSharedAddress($addressId, $params) { + public static function processSharedAddress($addressId, $params, $parentOperation = NULL) { $query = 'SELECT id, contact_id FROM civicrm_address WHERE master_id = %1'; $dao = CRM_Core_DAO::executeQuery($query, [1 => [$addressId, 'Integer']]); @@ -996,7 +997,7 @@ SELECT is_primary, $addressDAO->copyValues($params); $addressDAO->id = $dao->id; $addressDAO->save(); - $addressDAO->copyCustomFields($addressId, $addressDAO->id); + $addressDAO->copyCustomFields($addressId, $addressDAO->id, $parentOperation); } } diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 35b26c4b23..8b903ec244 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -1971,8 +1971,9 @@ LIKE %1 * * @param int $entityID * @param int $newEntityID + * @param string $parentOperation */ - public function copyCustomFields($entityID, $newEntityID) { + public function copyCustomFields($entityID, $newEntityID, $parentOperation = NULL) { $entity = CRM_Core_DAO_AllCoreTables::getBriefName(get_class($this)); $tableName = CRM_Core_DAO_AllCoreTables::getTableForClass(get_class($this)); // Obtain custom values for the old entity. @@ -2010,7 +2011,7 @@ LIKE %1 } // Save Custom Fields for new Entity. - CRM_Core_BAO_CustomValueTable::postProcess($customParams, $tableName, $newEntityID, $entity, 'create'); + CRM_Core_BAO_CustomValueTable::postProcess($customParams, $tableName, $newEntityID, $entity, $parentOperation ?? 'create'); } // copy activity attachments ( if any ) diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php index 464bd3a81f..6a370f248a 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php @@ -294,6 +294,8 @@ class CRM_Contribute_BAO_ContributionRecurTest extends CiviUnitTestCase { $templateContribution = $templateContribution->first(); $this->assertNotNull($templateContribution['template.field']); $this->assertEquals('Second and most recent Contribution', $templateContribution['template.field']); + $this->callAPISuccess('CustomField', 'delete', ['id' => $custom_field['id']]); + $this->callAPISuccess('CustomGroup', 'delete', ['id' => $custom_group['id']]); } /** -- 2.25.1