-
-
Notifications
You must be signed in to change notification settings - Fork 814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core/issues/80 - Current Employer is not reset after relationship is … #12032
Conversation
// @todo this belongs in the BAO. | ||
if ($this->_isCurrentEmployer) { | ||
$relChanged = $params['relationship_type_id'] != $this->_values['relationship_type_id']; | ||
if (!$params['is_active'] || !$params['is_current_employer'] || $relChanged) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the $params['is_current_employer'] functionality does seem to be form-relevant - ie there could be 2 employers & one (or possibly neither?) could be form-selected - I do like the move to bao for rel type change tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on assigning relationship through search results and we don't offer current employer
checkbox on that form. I found another issue(before this PR) which failed to remove current employer when the checkbox is unchecked while editing the relationship. It has been fixed in the changes made here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jitendrapurohit just spotted one more thing - looks like the original code would also clear current employer if toggled to inactive (presumably date changes could trigger that too but I think that could stay out of scope since it was not part of the previous behaviour)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this brings another related issue on dmaster which fails to reset current employer after is_active
checkbox is unchecked and the form is saved. Added fix for the same to this PR.
76bb1ef
to
2b8f8bd
Compare
CRM/Contact/BAO/Relationship.php
Outdated
if (!empty($relationshipId)) { | ||
$existingTypeID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Relationship', $relationshipId, 'relationship_type_id'); | ||
$existingTypeName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $existingTypeID, 'name_b_a'); | ||
if ($existingTypeName == 'Employer of' && (empty($params['is_active']) || empty($params['is_current_employer']) || $existingTypeID != $type)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be
if (empty($params['is_current_employer']) && $existingTypeName == 'Employer of' && (empty($params['is_active']) || $existingTypeID != $type))
Or else it gets hit when you do an api update. 'is_current_employer' is basically an override that can be passed in & which will skip that clear behaviour.
There is a weirdness with the form that I think you could assign ANY relationship with current_employer in the form but then it might be wiped by an api update of some sort - but I don't know how valid that path is - seems pretty obscure really
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the above format - it fails on the form layer and doesn't remove employer_id when is_current_employer
is unchecked.
The change is now modified to look for 'is_current_employer' variable on the form itself instead of BAO and clear the employer if it is not enabled. Tested various scenarios and looks fine to me.
CRM/Contact/BAO/Relationship.php
Outdated
@@ -304,7 +304,7 @@ public static function add(&$params, $ids = array(), $contactId = NULL) { | |||
if (!empty($relationshipId)) { | |||
$existingTypeID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Relationship', $relationshipId, 'relationship_type_id'); | |||
$existingTypeName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $existingTypeID, 'name_b_a'); | |||
if (empty($params['is_current_employer']) && $existingTypeName == 'Employer of' && (empty($params['is_active']) || $existingTypeID != $type)) { | |||
if ($existingTypeName == 'Employer of' && (empty($params['is_active']) || $existingTypeID != $type)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we still need to have !$params['is_current_employer'] here to respect any flag from the form?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the PR which should respect both API and form params. A new function is added which aims to decide if we need to set the current employer for the relationship or not. Tagging it as wip until I do a manual testing for some good number of scenarios. As a quick testing on the contact summary form, it worked fine for me.
b2c60b0
to
7aedab9
Compare
Done initial testing from my side and looks good on API as well as on form layer. removing wip from the title. |
CRM/Contact/BAO/Relationship.php
Outdated
|
||
$isExpired = FALSE; | ||
if (!empty($params['end_date']) && strtotime($params['end_date']) < time()) { | ||
$isExpired = TRUE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stylistically it might be nicer to return FALSE here
CRM/Contact/BAO/Relationship.php
Outdated
* @return bool | ||
* TRUE if current employer needs to be enabled. | ||
*/ | ||
public static function isCurrentEmployerSetInParams($params, $relationshipId, $updatedRelTypeID = NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like the function name is 'isCurrentEmployerNeedingToBeCleared'
@jitendrapurohit I took a look at this & tested it & it seems good. I had some readability concerns - ie. the function name seems wrong. Also, I think you could make that IF more readable if you used early returns instead. ie
I guess that doesn't quite work with your efforts to share with the form function? But I feel the readability is a bit tricky. Also I note that calling
really just does some unnecessary work & then wraps
|
Updated the PR as per above comments. Seems returning early for |
OK - I think this is good to merge - maybe squash the commits first? |
…updated Additional fixes Additional fixes
yep - done now. |
@civicrm-builder retest this please |
test this please |
…updated
Overview
Current Employer is not reset after relationship is updated.
Before
On editing a relationship type from
Employer of
to some other value, current employer value is still shown for the contact.After
Current Employer is deleted when relationship type is updated.
Technical Details
Moved the logic to BAO layer as commented on
CRM_Contact_Form_Relationship-> clearCurrentEmployer
function.Comments
Added unit test.
Gitlab issue - https://lab.civicrm.org/dev/core/issues/80