From 90f0b591be665b80265f3b06ca5b523d3d7883e6 Mon Sep 17 00:00:00 2001 From: dpradeep Date: Wed, 17 Jul 2013 12:59:58 +0530 Subject: [PATCH] -- fixed for CRM-10146, Restricted the creation of same membership and activity again. --- CRM/Contact/BAO/Contact.php | 2 +- CRM/Contact/BAO/Contact/Utils.php | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index dcff832d7e..f6fbc52631 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -231,7 +231,7 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { // create current employer if (isset($params['employer_id'])) { CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, - $params['employer_id'] + $params['employer_id'], $employerId ); } elseif ($params['current_employer']) { diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index c463a0c1b3..cab40793dc 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -259,7 +259,7 @@ UNION * @access public * @static */ - static function createCurrentEmployerRelationship($contactID, $organization) { + static function createCurrentEmployerRelationship($contactID, $organization, $previousEmployerID = NULL) { $organizationId = NULL; // if organization id is passed. @@ -296,8 +296,7 @@ UNION } } - $previousEmployerID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'employer_id'); - if ($organizationId && $organizationId != $previousEmployerID) { + if ($organizationId) { $cid = array('contact' => $contactID); // get the relationship type id of "Employee of" @@ -318,6 +317,9 @@ UNION // In case we change employer, clean prveovious employer related records. + if (!$previousEmployerID) { + $previousEmployerID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'employer_id'); + } if ($previousEmployerID && $previousEmployerID != $organizationId ) { @@ -329,7 +331,7 @@ UNION $relationshipParams['relationship_ids'] = $relationshipIds; // handle related meberships. CRM-3792 - self::currentEmployerRelatedMembership($contactID, $organizationId, $relationshipParams, $duplicate); + self::currentEmployerRelatedMembership($contactID, $organizationId, $relationshipParams, $duplicate, $previousEmployerID); } } @@ -344,7 +346,7 @@ UNION * @access public * @static */ - static function currentEmployerRelatedMembership($contactID, $employerID, $relationshipParams, $duplicate = FALSE) { + static function currentEmployerRelatedMembership($contactID, $employerID, $relationshipParams, $duplicate = FALSE, $previousEmpID = NULL) { $ids = array(); $action = CRM_Core_Action::ADD; @@ -365,7 +367,9 @@ UNION } //need to handle related meberships. CRM-3792 - CRM_Contact_BAO_Relationship::relatedMemberships($contactID, $relationshipParams, $ids, $action); + if ($previousEmpID != $employerID) { + CRM_Contact_BAO_Relationship::relatedMemberships($contactID, $relationshipParams, $ids, $action); + } } /** -- 2.25.1