Skip to content
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

CRM-19801: Fixing changing a relationship type from A to B or vice versa #9579

Merged
merged 3 commits into from
Jan 23, 2017
Merged

CRM-19801: Fixing changing a relationship type from A to B or vice versa #9579

merged 3 commits into from
Jan 23, 2017

Conversation

omarabuhussein
Copy link
Member

@omarabuhussein omarabuhussein commented Dec 26, 2016

If you tried to change A relationship type (Like Parent of ) of an exiting relationship to other B relationship type (Like Child of ) or vice versa then it will show you that the relationship get updated but it will not be it actually updated.

The issue is related to how postProcess handle contact_id_a & contact_id_b parameters .

So in this PR I've refactored the postProcess method for the relationship form and with this refactoring I've fixed this issue too by properly handling contact_id_a and contact_id_b parameters.


If you tried to change (A) relationship type of an exiting relationship (Like parent of) to another (B) relationship type (Like Child of) or vice versa then
it will show you that the relationship get updated but it will not be it actually get updated.

The issue is related to how postProcess handle contact_id_a & contact_id_b paramterters .

So in this PR I've refactored the postProcess method for the relationship form and with this refactoring I've have fixed this issue too
by properly hanlding conact_id_a and contact_id_b parameters.
@jitendrapurohit
Copy link
Contributor

@omarabuhussein Thanks for the cleanup :-). I've listed few issues found during initial QA. Also, I wasn't able to save start_date and end_date while updating the relationship after this PR. I see it is working fine on create action. Can you please have a look ?

Thanks.

}
}
if (isset($params['note'])) {
$this->saveRelationshipNotes($relationshipIds, $params['note']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think saveRelationshipNotes should also be called when $this->_action & CRM_Core_Action::UPDATE is TRUE to satisfy previous behaviour ?

Copy link
Member Author

@omarabuhussein omarabuhussein Dec 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took another look into what happens and it appear to me that the previous logic is not that elegant .. for example the $params['note'] was used but there was no kind of checking to confirm if it exist or not . so I refactored this method again with proper checking and corrected how it get called.

* @return array
*/
private function updateAction($params) {
$params = array_shift($this->preparePostProcessParameters($params));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This throws a notice error for me -

Notice: Only variables should be passed by reference in CRM_Contact_Form_Relationship->updateAction() (line 514 of /home/web/civi_master/civicrm/CRM/Contact/Form/Relationship.php).

May be $this->preparePostProcessParameters($params) should be assigned to a variable instead of passing directly to array_shift() ?

@omarabuhussein
Copy link
Member Author

omarabuhussein commented Dec 28, 2016

thanks @jitendrapurohit for reviewing , will check again and fix the issues

@omarabuhussein
Copy link
Member Author

@jitendrapurohit I fixed the issues , can you please take another look

@omarabuhussein
Copy link
Member Author

failed test doesn't seem to be related

@jitendrapurohit
Copy link
Contributor

jenkins, test this please

@omarabuhussein
Copy link
Member Author

thanks @jitendrapurohit , tests pass this time . can you please take another look whenever you have the time

@jitendrapurohit
Copy link
Contributor

jitendrapurohit commented Jan 6, 2017

@omarabuhussein I see there's a bunch of code which is being removed completely in this PR. This is actually good unless it worries to cause any regressions. I've done a basic manual testing which seems to be working correctly for all insert/update operation. Things that are tested and worked fine -

  • Create/Update/Enable/Disable relationship from contact summary page.
  • Add a current_employer from summary tab and check if relationship is created.
  • Perform multiple relationship create from Search results.

One bug which I've found and was working before the changes is that clearing of current_employer doesn't work on create and update action. Steps to reproduce :-

  • Go to any Contact Summary Page.
  • Add/Edit an Employee of relationship. Uncheck the checkbox that say Current Employer -> Save.
  • Click Edit link and see that the checkbox still remains checked.

Thanks.

@colemanw
Copy link
Member

@omarabuhussein I really like the code cleanup. Can you please look into the current employer issue that Jitendra noticed and we'll get this merged.

@omarabuhussein
Copy link
Member Author

thanks so much @jitendrapurohit & @colemanw .. I will look into the reported issue and fix it as soon as possible.

@jamienovick
Copy link

👍 nice work Omar!

@omarabuhussein
Copy link
Member Author

thanks @jamienovick ..

@jitendrapurohit current employee issue is fixed now ... for your check

@jitendrapurohit
Copy link
Contributor

confirmed that current employer issue has been fixed. Thanks for the update @omarabuhussein

@omarabuhussein
Copy link
Member Author

@colemanw the PR is approved

@kurund kurund merged commit 67bab11 into civicrm:master Jan 23, 2017
@omarabuhussein omarabuhussein deleted the CRM-19801-fix-relationship-saving branch January 23, 2017 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants