CRM-21008 - Checkbox to explicitly change employer when sharing address
[civicrm-core.git] / CRM / Core / BAO / Address.php
index 2ff74bbb3740a2ed0726826795635103670f18b9..090bde61b3464a8fbc739b8f1b00d64900cf67d7 100644 (file)
@@ -1047,11 +1047,16 @@ SELECT is_primary,
     $query = 'SELECT id, contact_id FROM civicrm_address WHERE master_id = %1';
     $dao = CRM_Core_DAO::executeQuery($query, array(1 => array($addressId, 'Integer')));
 
+    // Default to TRUE if not set to maintain api backward compatibility.
+    $createRelationship = isset($params['update_current_employer']) ? $params['update_current_employer'] : TRUE;
+
     // unset contact id
     $skipFields = array('is_primary', 'location_type_id', 'is_billing', 'contact_id');
     if (isset($params['master_id']) && !CRM_Utils_System::isNull($params['master_id'])) {
-      // call the function to create a relationship for the new shared address
-      self::processSharedAddressRelationship($params['master_id'], $params['contact_id']);
+      if ($createRelationship) {
+        // call the function to create a relationship for the new shared address
+        self::processSharedAddressRelationship($params['master_id'], $params['contact_id']);
+      }
     }
     else {
       // else no new shares will be created, only update shared addresses
@@ -1064,7 +1069,7 @@ SELECT is_primary,
     $addressDAO = new CRM_Core_DAO_Address();
     while ($dao->fetch()) {
       // call the function to update the relationship
-      if (isset($params['master_id']) && !CRM_Utils_System::isNull($params['master_id'])) {
+      if ($createRelationship && isset($params['master_id']) && !CRM_Utils_System::isNull($params['master_id'])) {
         self::processSharedAddressRelationship($params['master_id'], $dao->contact_id);
       }
       $addressDAO->copyValues($params);