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

dev/core#4537 Ensure that Event Registration email works when CiviCon… #27237

Merged
merged 1 commit into from
Sep 1, 2023

Conversation

seamuslee001
Copy link
Contributor

…tribute component is disabled and add unit test

Overview

This fixes an issue where performing an event registration without the CiviContribute Component / Extension enabled errors because LineItem APIv4 class isn't present and also fixes issues with smarty template rendering in similar

Before

Event Registration fails without CiviContribute enabled

After

Works

ping @eileenmcnaughton @totten @MegaphoneJon

@civibot
Copy link

civibot bot commented Sep 1, 2023

🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷

Introduction for new contributors...
  • If this is your first PR, an admin will greenlight automated testing with the command ok to test or add to whitelist.
  • A series of tests will automatically run. You can see the results at the bottom of this page (if there are any problems, it will include a link to see what went wrong).
  • A demo site will be built where anyone can try out a version of CiviCRM that includes your changes.
  • If this process needs to be repeated, an admin will issue the command test this please to rerun tests and build a new demo site.
  • Before this PR can be merged, it needs to be reviewed. Please keep in mind that reviewers are volunteers, and their response time can vary from a few hours to a few weeks depending on their availability and their knowledge of this particular part of CiviCRM.
  • A great way to speed up this process is to "trade reviews" with someone - find an open PR that you feel able to review, and leave a comment like "I'm reviewing this now, could you please review mine?" (include a link to yours). You don't have to wait for a response to get started (and you don't have to stop at one!) the more you review, the faster this process goes for everyone 😄
  • To ensure that you are credited properly in the final release notes, please add yourself to contributor-key.yml
  • For more information about contributing, see CONTRIBUTING.md.
Quick links for reviewers...

➡️ Online demo of this PR 🔗

@civibot civibot bot added the 5.65 label Sep 1, 2023
@civibot
Copy link

civibot bot commented Sep 1, 2023

The issue associated with the Pull Request can be viewed at https://lab.civicrm.org/dev/core/-/issues/4537

@@ -56,7 +56,10 @@ public function setupSmartyAliases(TokenValueEvent $e) {
*/
public function onRender(TokenRenderEvent $e): void {
$useSmarty = !empty($e->context['smarty']);
$e->string = $e->getTokenProcessor()->visitTokens($e->string, function() {
$e->string = $e->getTokenProcessor()->visitTokens($e->string, function($token = NULL, $entity = NULL, $field = NULL, $filterParams = NULL) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

without CiviContribute there were issues in the event online receipt (and other related templates) because they would have tokens like

{contribution.tax_amount|boolean} in if statements and this was filtering that down to an empty string which then if there were multiple parts to the if e.g. {if $showTaxAmount && {contribution.tax_amount|boolean}} it was being passed to smarty as {if $showTaxAmount && } which of course is a PHP syntax error this causes it to resolve any that use boolean filter to be 0

Copy link
Contributor

Choose a reason for hiding this comment

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

OK - let me see if I can move this into where booleans are otherwise rendered - ie this sort of area

if (!isset($filter[0])) {
return $value;
}
elseif (is_callable([StandardFilters::class, $filter[0]])) {
return call_user_func([StandardFilters::class, $filter[0]], $value, $filter, $messageFormat);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the problem is we don't get to there because of

if (isset($tokens[$entity][$field])) {

Copy link
Contributor

Choose a reason for hiding this comment

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

@seamuslee001 yeah we could do

image

Which feels more right to me - in that generally token filters are handled in the token system. OTOH I am somewhat terrified of the code in vistiTokens and associated functions cos it's hard to follow which might be a case for not touching it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeh that might be right but yeh likewise and it seemed like as this was doing the "cleanup" it might be the most sensible place to put things

Copy link
Contributor

Choose a reason for hiding this comment

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

ok - well I'm otherwise happy with this PR so @totten can merge this as is or opt for the other location to handle unset booleans

Copy link
Member

Choose a reason for hiding this comment

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

OK, this is the first time I've really looked at |boolean. So I'm trying to catch-up. Here's what I'm understanding:

  • The idea in 6543dfe is to help write Smarty conditionals that key-off of token-data, eg
    {if {contact.first_name|boolean}}...{/if}
  • This kind of {if {token}} notation is the quintessential quirk of Token-Smarty format. It's why Token-Smarty is evil and should never be used. It's also why we have to keep it around -- because changing to a simpler/singular language would break these conditionals.
  • So I guess the idea of |boolean is to make the conditional a bit safer, eg
    {if {contact.first_name}}...{/if}        {* More evil *}
    {if {contact.first_name|boolean}}...{/if} {* Less evil *}
  • In the callpath of this specific bug, we have a CiviEvent message with expression:
    {if $isShowTax && {contribution.tax_amount|boolean}}
  • In CiviEvent contexts, the token {contribution.tax_amount} may or may not be defined. (CiviEvent is only softly dependent on CiviContribute.)
  • The approach here is to define {any_unkn.own|boolean} to output 0.
  • The question you're mulling is: Where, exactly, should we put in the override to make {any_unkn.own|boolean} evaluate to 0?

Copy link
Member

Choose a reason for hiding this comment

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

So, yes, to my eye, both locations work, and the TokenProcessor::$getToken() seems a bit more poignant than TokenCompatSubscriber::onRender().

Whichever location it's in, I think it should have a code-comment explaining why it's there, e.g.

if ($filterParams && $filterParams[0] === 'boolean') {
  // This token was missed during primary rendering, and it's supposed to be coerced to boolean.
  // Treat an unknown token as false-y.
  return 0;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@totten that seems about right

Copy link
Member

Choose a reason for hiding this comment

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

Force-pushed a commit with the extra comment.

'end_date' => 20351023,
'registration_end_date' => 20351015,
]);
CRM_Core_BAO_ConfigSetting::disableComponent('CiviContribute');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I moved this before eventCreteUnpaid I ran into a whole bunch of issues with Example Data creation so decided to skip overall of that for now

@seamuslee001 seamuslee001 force-pushed the dev_core_4537 branch 2 times, most recently from 8b32a77 to 8b28675 Compare September 1, 2023 00:53
@eileenmcnaughton eileenmcnaughton added the merge ready PR will be merged after a few days if there are no objections label Sep 1, 2023
@eileenmcnaughton
Copy link
Contributor

eileenmcnaughton commented Sep 1, 2023

Happy leap year

CRM_Member_BAO_MembershipTest::testRenewMembership
Verify correct end date is calculated after membership renewal
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'2025-03-01'
+'2025-02-28'

/home/homer/buildkit/build/build-2/web/sites/all/modules/civicrm/tests/phpunit/CRM/Member/BAO/MembershipTest.php:518
/home/homer/buildkit/build/build-2/web/sites/all/modules/civicrm/tests/phpunit/CiviTest/CiviUnitTestCase.php:237
/home/homer/buildkit/extern/phpunit8/phpunit8.phar:1721

…tribute component is disabled and add unit test

Shift to using action object provider and rename function to remove Component
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.65 has-test merge on pass merge ready PR will be merged after a few days if there are no objections
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants