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#2748 Remove unused token assigns #21059

Merged
merged 1 commit into from
Sep 9, 2021

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Aug 7, 2021

Overview

Per https://lab.civicrm.org/dev/core/-/issues/2748 - this removes some no-longer-used token assigns & adds an upgrade message in case people have templates still referring to them

Before

We assign $first_name, $last_name, $displayName $contributeMode to the template but they have not been in the shipped templates for a long time - there is a preferred alternative (token) for the first 3

After

Assigns removed, system checks will warn

Technical Details

These variables are coming from the dreaded loadRelatedObjects function and in turn from loadRelatedEntitiesByID - which we hope to decommission

Comments

@civibot
Copy link

civibot bot commented Aug 7, 2021

(Standard links)

@civibot civibot bot added the master label Aug 7, 2021
@eileenmcnaughton eileenmcnaughton force-pushed the contribuion_mode branch 2 times, most recently from 7451f1e to 6cebcf6 Compare August 8, 2021 00:29
@totten
Copy link
Member

totten commented Aug 12, 2021

I did a clean build on 5.40 then edited the corresponding civicrm_msg_template to use the text:

<p>{$contributionMode} and {$last_name}</p>

Then made a snapshot and ran the upgrade using CLI and web UI:

Screen Shot 2021-08-11 at 8 57 20 PM

Screen Shot 2021-08-11 at 8 59 21 PM

This upgrade seems to create all the empty <li> bits.

The message about {$display_name} is pre-existing (from the 5.40=>5.41 upgrader). Tangentially, that message is a little confusing because you don't really have to do anything. (upgrade_5_41_alpha1() converts it.)

@eileenmcnaughton
Copy link
Contributor Author

oh - @totten the intent with the message is that it is generated AFTER the upgrade in case any were missed - I guess I misunderstood the order of events?

$upgradeMessage[] = $templateUpgrader->getMessageTemplateWarning('contribution_invoice_receipt', '$first_name', 'contact.first_name');
$upgradeMessage[] = $templateUpgrader->getMessageTemplateWarning('contribution_invoice_receipt', '$last_name', 'contact.last_name');
$upgradeMessage[] = $templateUpgrader->getMessageTemplateWarning('contribution_invoice_receipt', '$displayName', 'contact.display_name');
if (!empty($upgradeMessage)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@totten so if I just remove this bit is it right ? (Message wise - the face it is checking before rather than after is a separate & maybe not that solvable issue)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that emptiness check doesn't seem right. Arrays like [NULL,NULL,NULL] and ['','',''] are not empty(), but they are devoid of meaningful content. Maybe something like this...

$upgradeMessage = array_filter($upgradeMessage, function($v) { return !empty($v); });

... would trim the array down to only show meaningful content.

@totten
Copy link
Member

totten commented Aug 12, 2021

oh - @totten the intent with the message is that it is generated AFTER the upgrade in case any were missed - I guess I misunderstood the order of events?

Yeah, I find that confusing too. Pulled it up in a debugger and also ran it in verbose mode (cv upgrade:db -vv).

Screen Shot 2021-08-11 at 10 42 16 PM

So I think what happens is that it runs Upgrade DB to 5.41.alpha1 (CRM_Upgrade_Form::doIncrementalUpgradeStep...). As part of doIncrementalUpgradeStep, it calls both upgrade_5_41_alpha1() and setPostUpgradeMessage(..., 5.41.alpha1). Two things stand out:

  1. (More important) upgrade_5_41_alpha1() only enqueues the task -- it doesn't actually execute the change yet. So when you get to setPostUpgradeMessage(), the change hasn't taken effect yet. That remains for a future task.
  2. (Less important) setPostUpgradeMessage() can be called multiple times, once for each incremental version (alpha1, alpha2, beta1, beta2, .0, .1, etc). Pretty much everything that occurs within setPostUpgradeMessage() should have a guard so that it only runs once (e.g. if ($rev === '5.41.alpha1') { generateSomeWarnings();}).

@eileenmcnaughton eileenmcnaughton force-pushed the contribuion_mode branch 2 times, most recently from 0e11866 to bbb7e15 Compare August 12, 2021 06:12
@eileenmcnaughton
Copy link
Contributor Author

@totten I've ripped out the html (I possibly went too far but it took @demeritcowboy about 4 commits to get tit right last time :-) & made the message a bit more accurate.

I also added a version check.

But to go the extra step & only provide the message if it might apply seems like a bigger challenge?

@eileenmcnaughton
Copy link
Contributor Author

or rather - only display the message if it might STILL apply after the upgrade has run

@eileenmcnaughton
Copy link
Contributor Author

@totten I've updated this - I an on the fence about adding a conditional warning to check the status page - or just relying on it (that could be a follow up) - I copied the 'name' pattern from Dr when & I suspect that I'd need to revist to be able to call the check usefully from the upgrade script

I'm inclined to leave it for these tokens as it's been quite a while since they were used

image

@eileenmcnaughton
Copy link
Contributor Author

@totten I think we can merge this now? It is now using the status check mechanism to warn. These variables have not been used in core templates for a long time so as a minor cleanup we should be good on this one.

(now that we have a mapping between smarty & tplparams we have another tool for this stuff - but this is a complex bit of code so I think it's stil worth doing this cleanup - especially since it is so long since we shipped templatest that used these)

@demeritcowboy
Copy link
Contributor

This has conflicts now.

@eileenmcnaughton
Copy link
Contributor Author

@demeritcowboy thanks - the upgrade script not surprisingly - fixed now

@@ -1952,6 +1952,12 @@ public static function getTokenDeprecations(): array {
'contribution_invoice_receipt' => [
'$display_name' => 'contact.display_name',
],
'contribution_online_receipt' => [
'$contributionMode' => 'no longer available / relevant',
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be $contributeMode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah thanks - fixed!

@demeritcowboy
Copy link
Contributor

Since this went through some iterations, just to confirm:

  • I shouldn't be expecting any post-upgrade messages about smarty vars it replaced, right? Just a status check? (It did NOT give me a post-upgrade message.)

@eileenmcnaughton
Copy link
Contributor Author

@demeritcowboy that is correct - ideally no action is required but if there were some more complex smarty stuff going on it might be

@demeritcowboy
Copy link
Contributor

Ok I think that makes sense here - it can't really replace arbitrary smarty like {if $last_name eq 'foo'} by itself anyway. So looks good.

@eileenmcnaughton
Copy link
Contributor Author

thanks @demeritcowboy - nice to get rid of that contributeMode !

@eileenmcnaughton eileenmcnaughton merged commit 60fb93d into civicrm:master Sep 9, 2021
@eileenmcnaughton eileenmcnaughton deleted the contribuion_mode branch September 9, 2021 06:58
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Sep 9, 2021
Per civicrm#21059
its a really long time since this was in the stock templates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants