['relationship_type_id', '=', $relationshipTypeID],
['is_active', 'IN', [0, 1]],
])
- ->setSelect(['id', 'is_active', 'start_date', 'end_date', 'contact_id_a.employer_id'])
+ ->setSelect(['id', 'is_active', 'start_date', 'end_date', 'contact_id_a.employer_id', 'contact_id_a.organization_name', 'contact_id_b.organization_name'])
->addOrderBy('is_active', 'DESC')
->setLimit(1)
->execute()->first();
if (!empty($existingRelationship)) {
if ($existingRelationship['is_active']) {
+ if ($existingRelationship['contact_id_a.organization_name'] !== $existingRelationship['contact_id_b.organization_name']){
+ self::setCurrentEmployer([$contactID => $employerID]);
+ }
// My work here is done.
return;
}
* @throws \CRM_Core_Exception
*/
public function testMergeWithEmployer(): void {
+ $organizationToRemoveID = $this->organizationCreate(['organization_name' => 'remove']);
+ $organizationToKeepID = $this->organizationCreate(['organization_name' => 'keep']);
+ $individualToKeepID = $this->createContactWithEmployerRelationship([
+ 'contact_id_b' => $organizationToRemoveID,
+ ]);
+ $individualToRemoveID = $this->createContactWithEmployerRelationship([
+ 'contact_id_b' => $organizationToKeepID,
+ ]);
+ $employerName = Contact::get()->addSelect('organization_name')->addWhere('id', '=', $individualToKeepID)->execute()->first()['organization_name'];
+ $this->assertEquals('remove', $employerName);
+ $this->mergeContacts($individualToKeepID, $individualToRemoveID, ['move_employer_id' => $organizationToKeepID, 'move_rel_table_relationships' => TRUE]);
+ $employerName = Contact::get()->addSelect('organization_name')->addWhere('id', '=', $individualToKeepID)->execute()->first()['organization_name'];
+ $this->assertEquals('keep', $employerName);
+ }
+
+ /**
+ * Test that organization name is updated for employees of merged organizations..
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testMergeWithEmployee(): void {
$organizationToRemoveID = $this->organizationCreate(['organization_name' => 'remove']);
$organizationToKeepID = $this->organizationCreate(['organization_name' => 'keep']);
$individualID = $this->createContactWithEmployerRelationship([