From 6eae3162a5bcdef55150791f5da94221df63b72f Mon Sep 17 00:00:00 2001 From: monishdeb Date: Thu, 3 Jul 2014 18:25:51 +0530 Subject: [PATCH] CRM-14758 fix - API ( contact, create ) does not always create related membership https://issues.civicrm.org/jira/browse/CRM-14758 --- CRM/Contact/BAO/Contact.php | 6 +++++- CRM/Contact/BAO/Contact/Utils.php | 6 +++--- CRM/Contact/Form/Edit/Individual.php | 1 - 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 0c04192c60..54fe7206ce 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -237,7 +237,11 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { $newEmployer = !empty($params['employer_id']) ? $params['employer_id'] : CRM_Utils_Array::value('current_employer', $params); // create current employer if ($newEmployer) { - CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, $newEmployer, $employerId); + $newContact = FALSE; + if (empty($params['contact_id'])) { + $newContact = TRUE; + } + CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, $newEmployer, $employerId, $newContact); } else { //unset if employer id exits diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index e59da7a1bc..3b1001edb5 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -284,7 +284,7 @@ UNION * @access public * @static */ - static function createCurrentEmployerRelationship($contactID, $organizationId, $previousEmployerID = NULL) { + static function createCurrentEmployerRelationship($contactID, $organizationId, $previousEmployerID = NULL, $newContact = FALSE) { if ($organizationId && is_numeric($organizationId)) { $cid = array('contact' => $contactID); @@ -305,8 +305,8 @@ UNION ) = CRM_Contact_BAO_Relationship::create($relationshipParams, $cid); - // In case we change employer, clean prveovious employer related records. - if (!$previousEmployerID) { + // In case we change employer, clean previous employer related records. + if (!$previousEmployerID && !$newContact) { $previousEmployerID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'employer_id'); } if ($previousEmployerID && diff --git a/CRM/Contact/Form/Edit/Individual.php b/CRM/Contact/Form/Edit/Individual.php index 8df832970c..190e1c2bec 100644 --- a/CRM/Contact/Form/Edit/Individual.php +++ b/CRM/Contact/Form/Edit/Individual.php @@ -170,4 +170,3 @@ class CRM_Contact_Form_Edit_Individual { return empty($errors) ? TRUE : $errors; } } - -- 2.25.1