])->execute()->first()['id'];
}
- // get the relationship type id of "Employee of"
- $relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Employee of', 'id', 'name_a_b');
- if (!$relTypeId) {
- throw new CRM_Core_Exception(ts("You seem to have deleted the relationship type 'Employee of'"));
+ $relTypeId = CRM_Contact_BAO_RelationshipType::getEmployeeRelationshipTypeID();
+ if (!CRM_Contact_BAO_Contact::getContactType($contactID) || !CRM_Contact_BAO_Contact::getContactType($organization)) {
+ // There doesn't seem to be any reason to think this would ever be true but there
+ // was a previous more complicated check.
+ CRM_Core_Error::deprecatedWarning('attempting to create an employer with invalid contact types is deprecated');
+ return;
}
-
// create employee of relationship
[$duplicate, $relationshipIds]
= self::legacyCreateMultiple($relTypeId, $organization, $contactID);
'contact_id_b' => $organizationID,
'relationship_type_id' => $relationshipTypeID,
];
- if (!CRM_Contact_BAO_Relationship::checkRelationshipType($contactFields['contact_id_a'], $contactFields['contact_id_b'],
- $contactFields['relationship_type_id'])) {
- return [0, []];
- }
if (
CRM_Contact_BAO_Relationship::checkDuplicateRelationship(
//2. delete related membership.
//get the relationship type id of "Employee of"
- $relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Employee of', 'id', 'name_a_b');
- if (!$relTypeId) {
- throw new CRM_Core_Exception(ts("You seem to have deleted the relationship type 'Employee of'"));
- }
+ $relTypeId = CRM_Contact_BAO_RelationshipType::getEmployeeRelationshipTypeID();
$relMembershipParams['relationship_type_id'] = $relTypeId . '_a_b';
$relMembershipParams['contact_check'][$employerId] = 1;
$sharedContact->id = $relationship->contact_id_a;
$sharedContact->find(TRUE);
- // CRM-15881 UPDATES
- // changed FROM "...relationship->relationship_type_id == 4..." TO "...relationship->relationship_type_id == 5..."
- // As the system should be looking for type "employer of" (id 5) and not "sibling of" (id 4)
- // As suggested by @davecivicrm, the employee relationship type id is fetched using the CRM_Core_DAO::getFieldValue() class and method, since these ids differ from system to system.
- $employerRelTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Employee of', 'id', 'name_a_b');
-
+ $employerRelTypeId = CRM_Contact_BAO_RelationshipType::getEmployeeRelationshipTypeID();
if ($relationship->relationship_type_id == $employerRelTypeId && $relationship->contact_id_b == $sharedContact->employer_id) {
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($relationship->contact_id_a);
}
+--------------------------------------------------------------------+
*/
+use Civi\Api4\Relationship;
use Civi\Api4\RelationshipType;
+use Civi\Core\Event\PreEvent;
/**
*
/**
* Callback for hook_civicrm_pre().
+ *
* @param \Civi\Core\Event\PreEvent $event
- * @throws CRM_Core_Exception
+ *
+ * @throws \API_Exception
+ * @throws \Civi\API\Exception\UnauthorizedException
*/
- public static function self_hook_civicrm_pre(\Civi\Core\Event\PreEvent $event) {
+ public static function self_hook_civicrm_pre(PreEvent $event): void {
if ($event->action === 'delete') {
// need to delete all option value field before deleting group
- \Civi\Api4\Relationship::delete(FALSE)
+ Relationship::delete(FALSE)
->addWhere('relationship_type_id', '=', $event->id)
->execute();
}
}
-
/**
* Get the id of the employee relationship, checking it is valid.
*
\Civi\Api4\Relationship::create(FALSE)
->addValue('contact_id_a', $contactID)
->addValue('contact_id_b', $orgID)
- ->addValue('relationship_type_id', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Employee of', 'id', 'name_a_b'))
+ ->addValue('relationship_type_id', $relTypeId = CRM_Contact_BAO_RelationshipType::getEmployeeRelationshipTypeID())
->addValue('is_permission_a_b:name', 'View and update')
->execute();
}
* Test creating a current employer through API.
*
* Check it will re-activate a de-activated employer
- *
- * @throws \CRM_Core_Exception
*/
public function testContactCreateDuplicateCurrentEmployerEnables(): void {
// Set up - create employer relationship.