veda-consulting-company / uk.co.vedaconsulting.mailchimp

Other
22 stars 43 forks source link

Subscribes to all CiviCRM groups if contact has no group memberships #153

Closed twomice closed 9 years ago

twomice commented 9 years ago

We're finding that this extension tries to subscribe a contact to all CviCRM/Mailchimp groups each time any contact is edited, if the contact is a member of zero CiviCRM groups.

Here's what's happening:

  1. mailchimp_civicrm_post() fires for any contact edit event. It queries for all groups for the contact using CRM_Contact_BAO_GroupContact::getGroupList($objectId), which will return an empty array if the contact has no groups.
  2. mailchimp_civicrm_post() then queries all Mailchimp lists for the contact's groups, using CRM_Mailchimp_Utils::getGroupsToSync(), which takes as its argument an array of CiviCRM groups; if that array is empty, it returns all Mailchimp lists.
  3. mailchimp_civicrm_post() then asks Mailchimp to subscribe the contact to each of those lists, using CRM_Mailchimp_Utils::subscribeOrUnsubsribeToMailchimpList().

I think the simple fix is to quit the process as soon as it's known that the contact has no groups.

If you like, I can issue a PR which will hopefully be more self-explanatory.

veda-consulting commented 9 years ago

@twomice sure thing, a PR would be amazing!

veda-consulting commented 9 years ago

@twomice closing as the issue is now merged, will be in 1.8.1 due out tomorrow.