-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
CRM-21316: Add missing code to handle smart group on sms mode #11558
Conversation
@JKingsnorth can you please review my patch? |
CRM/Mailing/BAO/Mailing.php
Outdated
"$contact.do_not_sms", | ||
"$contact.is_opt_out = 0", | ||
"$contact.is_deceased <> 1", | ||
"$phone.phone_type_id = " . CRM_Utils_Array::value('Mobile', CRM_Core_OptionGroup::values('phone_type', TRUE, FALSE, FALSE, NULL, 'name')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does CRM_Core_PseudoConstant::getKey not work here? It's certainly shorter & that OptionGroup::values function is a bit evil
UT would be great here. |
CRM/Mailing/BAO/Mailing.php
Outdated
->param('#groups', $includeSmartGroupIDs) | ||
->param('#mailingID', $mailingID) | ||
->execute(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is almost all duplicated - could we just store the label of the ID field in a variable to use? This should help avoid SMS being accidentally omitted if anything else were to change. Or do you think that would make it unnecessarily hard to read?
CRM/Mailing/BAO/Mailing.php
Outdated
"$phone.phone != ''", | ||
"mg.mailing_id = #mailingID", | ||
'temp.contact_id IS null', | ||
); | ||
CRM_Utils_SQL_Select::from($phone) | ||
->select(" DISTINCT $phone.id as phone_id ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@monishdeb This needs to also select contact id, otherwise it causes a fatal error because the column count doesn't match up with replace into.
@monishdeb Additionally, we can't rely on this here: https://github.com/JMAConsulting/civicrm-core/blob/038b55fd5b9407b4f10eb9666c0106a24173cc9b/CRM/Mailing/BAO/Mailing.php#L126 Because the SMS provider is set on the second step of creating an SMS. So the first time this function is called, the SMS provider ID is not set, and it tries to calculate email recipients for the SMS. We could fix this by passing a 'dummy' SMS provider ID from the first page of the 'New SMS' form perhaps? |
I have started on some tests for the getRecipients function as part of #11162 . I'd like to set aside some time to write some further tests for this. |
@JKingsnorth sorry for the delay. I am not getting enough time (working on an internal project, need to be deployed next week) to make the additional changes as required in this PR. Can you please submit a patch on top my PR changes. And I will include that patch as commit of yours, in this PR. Or if it's not urgent can I submit the final changes by next week itself? @michaelmcandrew I saw your PR #11589, can I include your fix in this PR? |
@monishdeb - sure :) |
@JKingsnorth - since you are interested in SMS tests, I wanted to point you in the direction of @mattwire's open pr with some sms tests in case you hadn't seen it. (I had forgotten about it until today). |
e8a785a
to
2be0395
Compare
First of all, sorry for delay :( I have updated the PR and here are new changes:
@eileenmcnaughton @seamuslee001 @JKingsnorth @michaelmcandrew thankyou all for your feedback and fixes made for this regression. Can you please review my latest patch so that we can merge it against 4.7.31-rc ? |
Jenkins re test this please |
CRM/Mailing/BAO/Mailing.php
Outdated
->where('gc.group_id IN (#groups)') | ||
->where($includeFilters) | ||
->orderBy($order_by) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need the orderby anymore? @monishdeb
Just a note that I have not been following this closely but I know others have so I'm happy to merge if @seamuslee001 @JKingsnorth or @michaelmcandrew approve it |
I'll try to take a look at this early on Monday. Thanks for merging in the test and fix for the SMS ordering. |
test this please |
Looking at this one now. I'm running through some manual tests, but once this issue is merged I'm going to work on some more unit tests for getRecipients. |
@monishdeb @michaelmcandrew This still isn't working at all for SMS mailings. The count is incorrect on the second step of sending a mass SMS. The code: at the beginning of getRecipients doesn't work because an sms_provider_id is not set during the first step of creating an SMS mailing. This means that getRecipients treats it as an 'email', and bases the recipient list off of whether they have an email address. This is currently not covered by the test because the test creates the mailing with the SMS provider ID. We can resolve this by setting the SMS provider ID to the default SMS provider on this step of the form - like: #11628 (As a side note - you can have TWO default SMS providers (separate issue), hence the way I've structured the API call...) This seems to get things working; but I'm going to keep testing the SMS inclusion/exclusion for a few minutes. |
@monishdeb Additionally, the functionality to include/exclude recipients of previous mailings does not appear to work for email or SMS mailings? |
Thanks @JKingsnorth for your feedback let me cover each of your points:
This would be a separate issue as the current patch is only about retaining the earlier code which got missed during refactoring.
Yes, it should because the same table is used to fetch the exclude and include group ids here and eventually same SQL queries is used filter out contacts which are present in exclude groups. |
I think these issues are within scope for this, since they were all introduced as a side-effect of #11142. Reverting that PR fixes all these issues as far as I can tell. Cannot include 'previous recipients' in mailing UI is buggy when adding/removing recipient groups
and
SMS recipient estimation doesn't work on second step of creating SMS If we have time to fix these in this release cycle then great, I can help with the PRs. Otherwise I think we should revert #11142 until we have unit tests in place to ensure continuity. There have undoubtedly been performance improvements thanks to @monishdeb 's hard work on this area. But I don't think we can introduce this many regressions in such a sensitive area of the system. |
@totten @colemanw @mlutfy adding you in on this as we may need to make a decision to revert & try again next release if this can't be sorted out in time. Current status is that a patch merged to master (in time for 4.7.31) is causing regression/s that Monish & John are working on. Monish's time has opened up a bit so we may be fine but you should be monitoring this |
I have fixed the 'UI is buggy when adding/removing recipient groups' issue. Going to fix the 'previous mailing' issue shortly and will update the PR. |
@eileenmcnaughton @JKingsnorth I have fixed the two regressions where earlier:
|
Well done @monishdeb - @JKingsnorth await your review on this to merge |
Cool, thanks @monishdeb, testing this now. |
Yes, thanks @monishdeb, confirmed this version fixes:
I'm working on the PR to fix SMS recipient estimation now. Just a couple of things I want to test/investigate there; but we can do that separately. |
Great. Thanks a lot for your persistent response and getting all the regression fixed :) @JKingsnorth can we merge this PR ? |
Thumbs up from me to merge. |
merged based on @JKingsnorth review |
Fastest merging finger in the Southern Hemisphere @eileenmcnaughton . |
@JKingsnorth @monishdeb @michaelmcandrew is this closable now? https://issues.civicrm.org/jira/browse/CRM-21713 |
quickdraw-mcGraw |
@eileenmcnaughton yes indeed - it can be closed. |
Yup can be closed. |
I'm starting work on a suite of tests for getRecipients, https://issues.civicrm.org/jira/browse/CRM-21739 |
And the last fix in the other PR has passed the test suite: #11628 |
Overview
This is a break on
CRM_Mailing_BAO_Mailing::getRecipients()
where during refactoring, the code responsible to fetch contacts of selected smart group IDs, on SMS mode was missed. And this PR is about retaining that code and some additional changes. Thanks to @JKingsnorth for notifying this break.