Fix Address test failure by passing the hook through to copyCustomFields and fix...
authorSeamus Lee <seamuslee001@gmail.com>
Mon, 30 Aug 2021 03:01:02 +0000 (13:01 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Mon, 30 Aug 2021 03:04:45 +0000 (13:04 +1000)
CRM/Core/BAO/Address.php
CRM/Core/DAO.php
tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php

index 14516f1f7b9e537424b8b7806dbce17d03892ad0..480501d81589ad5e147aabd1714f0d25863d6d6f 100644 (file)
@@ -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);
     }
   }
 
index 35b26c4b23407e3903d52447e9adacf16410532d..8b903ec24462d59280df859aef933440c1377d0f 100644 (file)
@@ -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 )
index 464bd3a81f2412adf1e42a604c5990d1ff1c790d..6a370f248ad0eb291c6db6a9070ed65de2a73cb1 100644 (file)
@@ -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']]);
   }
 
   /**