twomice / com.joineryhq.reltoken

CiviCRM extension: Provides tokens for any related contact, for all available contact tokens. E.g., to get the spouse's first name, or parent's marriage date.
Other
1 stars 5 forks source link

fix bad query when token is for a non-existent relationship #6

Closed MegaphoneJon closed 5 years ago

MegaphoneJon commented 5 years ago

I just found out what happens when you try to process a token for a relationship that doesn't exist, and it's not pretty.

The line in question is:

$tokenDetails = CRM_Utils_Token::getTokenDetails($relatedContactIDs, array($baseToken => 1), FALSE, FALSE, NULL, array('contact' => array($baseToken)), 'CRM_Reltoken');

If $relatedContactIDs is populated, then this query will do the rather sane act of making an API call to retrieve token data from the contacts in that array. If $relatedContactIDs is NOT populated, then getTokenDetails() will make an API call to get token details for EVERY contact in the db. Oops. Crashes my UI every time.

Anyway, if $relatedContactIDs isn't populated, that means that there are no contacts that have the relationship this token is trying to process, so this patch skips it.

twomice commented 5 years ago

Looks great, Jon. Good catch. Merging.