[REF] Improve Custom data insert performance when using the copyCustomFields
authorSeamus Lee <seamuslee001@gmail.com>
Mon, 30 Aug 2021 01:07:12 +0000 (11:07 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Mon, 30 Aug 2021 01:10:20 +0000 (11:10 +1000)
CRM/Core/BAO/CustomValueTable.php
CRM/Core/DAO.php

index f158a0f19d50a5f6e8b8fa3cf48aa745d3542fda..fa5373b087765ae03dab245508a8bcf3165b5aed 100644 (file)
@@ -396,15 +396,16 @@ class CRM_Core_BAO_CustomValueTable {
    * @param $entityTable
    * @param int $entityID
    * @param $customFieldExtends
+   * @param $parentOperation
    */
-  public static function postProcess(&$params, $entityTable, $entityID, $customFieldExtends) {
+  public static function postProcess(&$params, $entityTable, $entityID, $customFieldExtends, $parentOperation = NULL) {
     $customData = CRM_Core_BAO_CustomField::postProcess($params,
       $entityID,
       $customFieldExtends
     );
 
     if (!empty($customData)) {
-      self::store($customData, $entityTable, $entityID);
+      self::store($customData, $entityTable, $entityID, $parentOperation);
     }
   }
 
index 5bb34367c713f0f0d8045ec04c2e7a186fed7db7..35b26c4b23407e3903d52447e9adacf16410532d 100644 (file)
@@ -1975,7 +1975,7 @@ LIKE %1
   public function copyCustomFields($entityID, $newEntityID) {
     $entity = CRM_Core_DAO_AllCoreTables::getBriefName(get_class($this));
     $tableName = CRM_Core_DAO_AllCoreTables::getTableForClass(get_class($this));
-    // Obtain custom values for old event
+    // Obtain custom values for the old entity.
     $customParams = $htmlType = [];
     $customValues = CRM_Core_BAO_CustomValueTable::getEntityValues($entityID, $entity);
 
@@ -2009,8 +2009,8 @@ LIKE %1
         }
       }
 
-      // Save Custom Fields for new Event
-      CRM_Core_BAO_CustomValueTable::postProcess($customParams, $tableName, $newEntityID, $entity);
+      // Save Custom Fields for new Entity.
+      CRM_Core_BAO_CustomValueTable::postProcess($customParams, $tableName, $newEntityID, $entity, 'create');
     }
 
     // copy activity attachments ( if any )