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 infinite loop on Civi 5.44+ #19

Closed MegaphoneJon closed 2 years ago

MegaphoneJon commented 2 years ago

This extension causes an infinite loop (w/ eventual OOM error or segfault) anywhere it's called in Civi 5.44+. https://github.com/civicrm/civicrm-core/pull/21429 is the culprit, registerTokens() now calls a new function getLegacyHookTokens().

Static vars aren't pretty but this extension already uses one, and it gets the job done.

To replicate this, go to any mailing screen (including a quick email) on 5.44+ with this extension enabled.

twomice commented 2 years ago

Thanks @MegaphoneJon . Will review and (hopefully) merge soon.

twomice commented 2 years ago

Testing this PR indicates that it solves the problem described #18:

CiviCRM version 5.44.0 Extension version: master 84a3b88371d19539027bbec1a55221d040b6e521 (version "0.3")

Before:

  1. Navigate to https://example.com/civicrm/activity/email/add?action=add&reset=1&cid=N&selectedChild=activity&atype=3, where N is the ID of any contact with an email address. (This is the same URL you'd reach by navigating to the contact and selecting Actions > Send an Email. It helps to use this URL directly, or else to use your browser's "Open Link In New Tab" feature so as to see any error messages easily. It also help to have civicrm's debugging features enabled.)
  2. Observe a fatal error of some kind. On my system, the OOM error is precluded by xdebug's detection of possible infinite loop. My system reports this error:
    Error messageError: Xdebug has detected a possible infinite loop, and aborted your script with a stack depth of '256' frames in Civi\Token\ImpliedContextSubscriber->getMappings() (line 105 of /[drupal-docroot]/sites/all/modules/civicrm/Civi/Token/ImpliedContextSubscriber.php).

After:

  1. Repeat step 1 above.
  2. Observe the "Send an Email" form loads without error. Also observe that the expected relationship-based tokens are available in the Tokens drop-down.

I'm merging and closing. Thanks @MegaphoneJon !