Merge pull request #15833 from yashodha/participant_edit
[civicrm-core.git] / CRM / Core / BAO / Block.php
index a9ffa34e2f4461182c95675d6de1e5b2f9f67675..6c37470377d71e9d0844175dbe1fa5c709565ae6 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019                                |
+ | Copyright CiviCRM LLC (c) 2004-2020                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2019
+ * @copyright CiviCRM LLC (c) 2004-2020
  *
  * Add static functions to include some common functionality used across location sub object BAO classes.
  */
@@ -277,7 +277,6 @@ class CRM_Core_BAO_Block {
             $block->is_primary = FALSE;
             $block->save();
           }
-          $block->free();
         }
       }
     }
@@ -345,8 +344,18 @@ class CRM_Core_BAO_Block {
       }
 
       $blockFields = array_merge($value, $contactFields);
-      $baoString = 'CRM_Core_BAO_' . $name;
-      $blocks[] = $baoString::add($blockFields);
+      if ($name === 'Email') {
+        // @todo ideally all would call the api which is our main tested function,
+        // and towards that call the create rather than add which is preferred by the
+        // api. In order to be careful with change only email is swapped over here because it
+        // is specifically tested in testImportParserWithUpdateWithContactID
+        // and the primary handling is otherwise bypassed on importing an email update.
+        $blocks[] = CRM_Core_BAO_Email::create($blockFields);
+      }
+      else {
+        $baoString = 'CRM_Core_BAO_' . $name;
+        $blocks[] = $baoString::add($blockFields);
+      }
     }
 
     return $blocks;