-- fixed for CRM-10146, Restricted the creation of same membership and activity again.
authordpradeep <pradeep.dorugade@webaccess.co.in>
Wed, 17 Jul 2013 07:29:58 +0000 (12:59 +0530)
committerdpradeep <pradeep.dorugade@webaccess.co.in>
Wed, 17 Jul 2013 07:29:58 +0000 (12:59 +0530)
CRM/Contact/BAO/Contact.php
CRM/Contact/BAO/Contact/Utils.php

index dcff832d7eca963232367c93e357dd6435b82c16..f6fbc52631dbe16dd4d5d15a3c68e6d217e35a65 100644 (file)
@@ -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']) {
index c463a0c1b39a7a7f6f8aaee288869ab6ec795e20..cab40793dc5435be40f76dfcfb945304b7314d41 100644 (file)
@@ -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);
+    }
   }
 
   /**