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#448 Fix issue where when building mailings with smart groups, removed members of the smart group were being included #12945

Merged
merged 2 commits into from
Oct 17, 2018

Conversation

seamuslee001
Copy link
Contributor

@seamuslee001 seamuslee001 commented Oct 16, 2018

Overview

When using a smart group as a mailing list, users who unsubscribe from the smart group are still included in the mailing.

Before

When creating a mailing using a smart group as a mailing list, users who have previously unsubscribed from the smart group mailing list will still receive the mailing.

No Unit Test on this particular part of the recipient building logic

After

Users who have unsubscribed form smart group mailing lists and are marked as removed in the civicrm_group_contact table, no longer receive the mailings.

Unit test exists

Technical Details

In CRM/Mailing/BAO/Mailing.php the query below doesn't join to the civicrm_group_contact to check if the recipient has been removed.

if (count($includeSmartGroupIDs)) {
      $query = CRM_Utils_SQL_Select::from($contact)
        ->select("$contact.id as contact_id, $entityTable.id as $entityColumn")
        ->join($entityTable, " INNER JOIN $entityTable ON $entityTable.contact_id = $contact.id ")
        ->join('gc', " INNER JOIN civicrm_group_contact_cache gc ON $contact.id = gc.contact_id ")
        ->join('mg', " INNER JOIN civicrm_mailing_group mg  ON  gc.group_id = mg.entity_id AND mg.search_id IS NULL ")
        ->join('temp', " LEFT JOIN $excludeTempTablename temp ON $contact.id = temp.contact_id ")
        ->where('gc.group_id IN (#groups)')
        ->merge($criteria)
        ->replaceInto($includedTempTablename, array('contact_id', $entityColumn))
        ->param('#groups', $includeSmartGroupIDs)
        ->param('#mailingID', $mailingID)
        ->execute();
    }

Comments

This PR replaces #12943 which was against the wrong branch & had no test but had the correct fix, which has been cherry-picked in.

This appears to be a semi-recent regression - having seemingly worked in 5.2

ping @eileenmcnaughton @monishdeb

… groups and contats removed from smart groups not being properly checked
@civibot
Copy link

civibot bot commented Oct 16, 2018

(Standard links)

@civibot civibot bot added the master label Oct 16, 2018
@seamuslee001
Copy link
Contributor Author

also pinging @johntwyman @andrew-cormick-dockery as you two will want to be on top of this (surprised we haven't seen this surface yet)

@seamuslee001
Copy link
Contributor Author

Jenkins re test this please

@seamuslee001 seamuslee001 changed the title dev/core#448 Add in a Unit test to demonstrate the problem with smart… dev/core#448 Fix issue where when building mailings with smart groups, removed members of the smart group were being included Oct 16, 2018

// Create a New mailing, Testing contacts removed from smart group.
// In this case groupIDs6 will only pick up contacts[0] amd contacts[8] with it's
// criteria. However we are deliberly going to remove contactIds[8] from the group
Copy link
Contributor

Choose a reason for hiding this comment

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

@seamuslee001 I think you mean "deliberately" - not "deliberly"

Copy link
Contributor

Choose a reason for hiding this comment

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

or he was slurring....

@jusfreeman
Copy link
Contributor

@seamuslee001 any idea when this started happening? Was this bug recently introduced by some other change?

@eileenmcnaughton
Copy link
Contributor

@jusfreeman the bug seems to have been introduced in 5.3 or earlier.

@eileenmcnaughton
Copy link
Contributor

Test looks good. The fix by @tmannell makes sense & has been tested by @seamuslee001 in creating the test - merging

@eileenmcnaughton eileenmcnaughton merged commit fc3d6bd into civicrm:master Oct 17, 2018
@eileenmcnaughton eileenmcnaughton deleted the lab_core_448 branch October 17, 2018 08:07
@eileenmcnaughton
Copy link
Contributor

@seamuslee001 I just merged & then realised we talked about this going agaiinst the rc!

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