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#2463 - Adjust returned list of activity ids when sending emails since it changes in 5.36+ #19873

Merged

Conversation

demeritcowboy
Copy link
Contributor

Overview

https://lab.civicrm.org/dev/core/-/issues/2463

Followup to #19826 and towards making the recorded activity ids available to hooks.

I'm a bit conflicted about changing the signature for a public static function. But at the same time any extensions that call this function and act on the single activity id it returns are now doing it wrong as of 5.36, since they're missing all the other activity ids. Universe suggests there's a small handful. An alternative would be to keep the signature and provide some other way to get at the ids, which doesn't seem hard, but does it really help the existing extensions?

Before

In 5.35 and earlier, only one activity was recorded when there were multiple recipients when sending a (non-bulk) email. In 5.36 it now records multiple activities, but the code still returns just the last activity id to its caller.

After

Returns all the ids.

Technical Details

One thing that came up during the original review of the multiple activities PR had to do with any scheduled followups. I've left that as-is so it still only links the followup to one of the activity ids. The original quote:

For scheduled followups (the section at the bottom of the email form where you can create a supplementary activity at the same time as sending the email), it doesn't quite match my understanding of the discussion and the "multiple" policy, but this doesn't have anything to do with tokens and seems fine to me. In the multiple policy, there'd be a separate followup activity for each To recipient, but I think it's fine that it creates just one with the combined To's. If you really want separate ones, you can still make more manually.

Comments

This doesn't do anything with the returned ids yet. Making it available to hooks would be a followup.

There's some coverage for multiple recipients at testSendEmailWillReplaceTokensUniquelyForEachContact. But I should probably add something to explicitly test the returned values.

@civibot
Copy link

civibot bot commented Mar 23, 2021

(Standard links)

@civibot civibot bot added the master label Mar 23, 2021
@eileenmcnaughton
Copy link
Contributor

@demeritcowboy does this need to be against 5.36?

@demeritcowboy
Copy link
Contributor Author

demeritcowboy commented Mar 24, 2021

The two most straightforward choices seem to be:

  1. Yes. In which case it would first need 19826 backported, and then after this PR a small handful of extensions may fail in 5.36 (if they attempt to use array as integer) unless the devs do something in the next 2 weeks.
  2. No. In which case 5.36 would mean a small handful of extensions continue to work but don't completely act on all the resulting activities, until whenever either this PR or something else happens, and then they may fail.

@eileenmcnaughton
Copy link
Contributor

@demeritcowboy doesn't sound like a compelling case for putting it against 5.36 if it increases the risk of breakage :-)

I'll take a look in a bit

@demeritcowboy
Copy link
Contributor Author

They'll be broken either way in 5.36, just different kinds of broken. The fact that some extensions call sendEmail and act on the resulting activity was unnoticed/unforseen during the change to store the replacement values of tokens in separate activities per recipient.

@@ -1017,7 +1017,7 @@ public static function createEmailActivity($sourceContactID, $subject, $html, $t
* @param int $caseId
*
* @return array
* ( sent, activityId) if any email is sent and activityId
* ( sent, activityIds) if any email is sent and the corresponding activity ids
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is not clear, I think an improvement would be:

Suggested change
* ( sent, activityIds) if any email is sent and the corresponding activity ids
* [ bool sent, array activityIds ] if any email is sent and the corresponding activity ids

I'm also not sure it's correct. $sent is initialised to [] but then set FALSE and maybe TRUE in the loop; so it's only referring to the last loop iteration. Seems the same problem as for $activityId(s)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to look at the $sent issue separately since it's been like that since 2009. Kudos for noticing.

@eileenmcnaughton
Copy link
Contributor

@artfulrobot thanks for taking a look - I'm happy to merge this when you are happy with it

@demeritcowboy demeritcowboy force-pushed the multiemail-activityids branch from 88a5146 to 13ecf77 Compare March 27, 2021 13:33
@demeritcowboy
Copy link
Contributor Author

Addressed the other comments and added an explicit test for the returned ids.

@artfulrobot
Copy link
Contributor

Looks good to me, thanks @demeritcowboy

@demeritcowboy
Copy link
Contributor Author

Thanks for the review!

@eileenmcnaughton eileenmcnaughton merged commit 48649f1 into civicrm:master Mar 29, 2021
@eileenmcnaughton
Copy link
Contributor

Thanks @artfulrobot & @demeritcowboy

@demeritcowboy demeritcowboy deleted the multiemail-activityids branch March 29, 2021 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants