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

Respect pre hook for relationship to alter id in $params #12834

Merged
merged 2 commits into from
Feb 4, 2019

Conversation

pradpnayak
Copy link
Contributor

Overview

If we alter the $params['id'] in pre hook then its not respected by CRM_Contact_BAO_Relationship::add() function. This PR allows hook to alter id.

@@ -316,7 +316,7 @@ public static function add(&$params, $ids = array(), $contactId = NULL) {
$relationship->contact_id_b = $params['contact_id_b'];
$relationship->contact_id_a = $params['contact_id_a'];
$relationship->relationship_type_id = $type;
$relationship->id = $relationshipId;
$relationship->id = $params['id'];
Copy link
Contributor

Choose a reason for hiding this comment

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

@pradpnayak I worry that this isn't robust & could be changed at any point, breaking any extensions that rely on it, since there is no specific contract / commitment to permitting id to be altered. 2 ways to protect it are

  1. by using code practices as standardised as possible - in this case perhaps merge in the defaults first & then do per code comment
 //@todo this code needs to be updated for the possibility that not all fields are set
    // by using $relationship->copyValues($params);


  1. unit tests

@eileenmcnaughton
Copy link
Contributor

@totten @colemanw what do you think of this - I get why people would want it - but it seems to be ad hoc expanding our hook support contract (I don't think this is the first place that has been done but the concern still applies) - perhaps we need a generic syntax conformance test & to add it as a standard rather than an ad hoc approach. Note that adding Syntax conformance doesn't mean making it work for EVERY entity - it means doing the easy ones & setting the others to be skipped

@eileenmcnaughton eileenmcnaughton added the sig:extension support Supports being able to integrate extensions with CiviCRM label Sep 21, 2018
@colemanw
Copy link
Member

IMO this is consistent with other places in our codebase where we are working to deprecate the $ids param in BAO add/create functions. So I'm good with merging this with one caveat, I think we should remove the & from the function signature so it reads public static function add(&$params, $ids = array(), $contactId = NULL) {. If we are going to modify the array, we should not take it by reference.

@pradpnayak
Copy link
Contributor Author

jenkins test this please

@eileenmcnaughton
Copy link
Contributor

I'm going to merge based on @colemanw's review - my caution remains that this handling of $params['id'] is not locked in by tests or by our hook contract & could change at any time so extensions that rely on it need to implement their own unit testing to warn them if it does change

@eileenmcnaughton eileenmcnaughton merged commit 2099e28 into civicrm:master Feb 4, 2019
@pradpnayak pradpnayak deleted the preRelHook branch March 23, 2020 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
master merge on pass sig:extension support Supports being able to integrate extensions with CiviCRM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants