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

CRM-21316: Add missing code to handle smart group on sms mode #11558

Merged
merged 4 commits into from
Feb 6, 2018

Conversation

monishdeb
Copy link
Member

@monishdeb monishdeb commented Jan 19, 2018

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.


@monishdeb
Copy link
Member Author

@JKingsnorth can you please review my patch?

"$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')),
Copy link
Contributor

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

@eileenmcnaughton
Copy link
Contributor

UT would be great here.

->param('#groups', $includeSmartGroupIDs)
->param('#mailingID', $mailingID)
->execute();
}
Copy link
Contributor

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?

"$phone.phone != ''",
"mg.mailing_id = #mailingID",
'temp.contact_id IS null',
);
CRM_Utils_SQL_Select::from($phone)
->select(" DISTINCT $phone.id as phone_id ")
Copy link
Contributor

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.

@JKingsnorth
Copy link
Contributor

@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?

@JKingsnorth
Copy link
Contributor

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.

@monishdeb
Copy link
Member Author

monishdeb commented Jan 26, 2018

@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?

@michaelmcandrew
Copy link
Contributor

@monishdeb - sure :)

@michaelmcandrew
Copy link
Contributor

@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).

@monishdeb monishdeb force-pushed the CRM-21260 branch 2 times, most recently from e8a785a to 2be0395 Compare February 2, 2018 15:59
@monishdeb
Copy link
Member Author

monishdeb commented Feb 2, 2018

First of all, sorry for delay :( I have updated the PR and here are new changes:

  1. Cherry-picked @michaelmcandrew commit for CRM-21316: Add missing code to handle smart group on sms mode #11558
  2. Cherry-picked @JKingsnorth commit to include SMS unit test 31a5c38
  3. Refactored code to use same SQL queries for both mailing and sms
  4. Modified unit-test to use smart group and other style fixes.

@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 ?

@seamuslee001
Copy link
Contributor

Jenkins re test this please

->where('gc.group_id IN (#groups)')
->where($includeFilters)
->orderBy($order_by)
Copy link
Contributor

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

@eileenmcnaughton
Copy link
Contributor

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

@JKingsnorth
Copy link
Contributor

I'll try to take a look at this early on Monday. Thanks for merging in the test and fix for the SMS ordering.

@eileenmcnaughton
Copy link
Contributor

test this please

@JKingsnorth
Copy link
Contributor

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.

@JKingsnorth
Copy link
Contributor

@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:
$isSMSmode = (!CRM_Utils_System::isNull($mailingObj->sms_provider_id));

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.

@JKingsnorth
Copy link
Contributor

@monishdeb Additionally, the functionality to include/exclude recipients of previous mailings does not appear to work for email or SMS mailings?

@monishdeb
Copy link
Member Author

monishdeb commented Feb 5, 2018

Thanks @JKingsnorth for your feedback let me cover each of your points:

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:
$isSMSmode = (!CRM_Utils_System::isNull($mailingObj->sms_provider_id));

This would be a separate issue as the current patch is only about retaining the earlier code which got missed during refactoring.

Additionally, the functionality to include/exclude recipients of previous mailings does not appear to work for email or SMS mailings?

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.

@JKingsnorth
Copy link
Contributor

JKingsnorth commented Feb 5, 2018

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
There doesn't seem to be anything in the new SQL that includes the groups used in previous mailings? If you try to include a 'previous mailing' then the estimated recipients does not change. I am not sure whether this is due to a UI issue, or a functional issue (see below). Reverting 11142 makes this work again.

UI is buggy when adding/removing recipient groups

and

  • Add a 'previous mailing' recipient list to a mailing
  • Note that it does not appear
  • Add a normal group
  • Now they both appear

SMS recipient estimation doesn't work on second step of creating SMS
This is actually caused by the original PR too. In the original code we passed in a $mode to the getRecipients function (see https://github.com/civicrm/civicrm-core/pull/11142/files#diff-d751a392a437280fae775ae39f59760bL273), so the 'isSMS' detection worked correctly. That parameter was removed as part of the original PR, so SMS mode detection stopped working. I've suggested a workaround, as per #11628

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.

@eileenmcnaughton
Copy link
Contributor

@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

@monishdeb
Copy link
Member Author

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.

@monishdeb monishdeb added the needs-work-not-review-ready Submitter required to take action, will be closed after 1-2 weeks in this state label Feb 5, 2018
@monishdeb
Copy link
Member Author

monishdeb commented Feb 6, 2018

@eileenmcnaughton @JKingsnorth I have fixed the two regressions where earlier:

  1. If we select any prior mailing in recipient field then it doesn't fetch the prior recipients from civicrm_mailing_recipients table.
    As per refactoring, I have retained the query that handles this scenario.

  2. We cannot unselect the groups/prior mailing from recipients field.
    This was a regression due to a bug fix where earlier there was a one-line change made in Recipients.js to fix an API error when no group/mailing was selected.

Here's the screencast, after the fix:
test-multiple-after

@eileenmcnaughton
Copy link
Contributor

Well done @monishdeb - @JKingsnorth await your review on this to merge

@JKingsnorth
Copy link
Contributor

Cool, thanks @monishdeb, testing this now.

@JKingsnorth
Copy link
Contributor

Yes, thanks @monishdeb, confirmed this version fixes:

  • The UI issues
  • Including/excluding previous mailing recipients

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.

@monishdeb
Copy link
Member Author

monishdeb commented Feb 6, 2018

Great. Thanks a lot for your persistent response and getting all the regression fixed :)

@JKingsnorth can we merge this PR ?

@JKingsnorth
Copy link
Contributor

Thumbs up from me to merge.

@eileenmcnaughton eileenmcnaughton merged commit 1a34d42 into civicrm:master Feb 6, 2018
@eileenmcnaughton
Copy link
Contributor

merged based on @JKingsnorth review

@monishdeb monishdeb deleted the CRM-21260 branch February 6, 2018 10:02
@JKingsnorth
Copy link
Contributor

Fastest merging finger in the Southern Hemisphere @eileenmcnaughton .

@eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton
Copy link
Contributor

quickdraw-mcGraw

@JKingsnorth
Copy link
Contributor

JKingsnorth commented Feb 6, 2018

@eileenmcnaughton yes indeed - it can be closed.

@monishdeb
Copy link
Member Author

Yup can be closed.

@monishdeb monishdeb removed the needs-work-not-review-ready Submitter required to take action, will be closed after 1-2 weeks in this state label Feb 6, 2018
@JKingsnorth
Copy link
Contributor

I'm starting work on a suite of tests for getRecipients, https://issues.civicrm.org/jira/browse/CRM-21739

@JKingsnorth
Copy link
Contributor

And the last fix in the other PR has passed the test suite: #11628

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.

8 participants