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

Other
22 stars 43 forks source link

Interest Groups missing on Civi -> MailChimp push for contacts belonging to several Civi groups #298

Open ghost opened 6 years ago

ghost commented 6 years ago

If a contact belongs to a large number of groups (in my case, the contact was in 12 groups - not all syncable to Mailchimp), the API result when retrieving the contact's groups gets cut off. As a result, the contact's interests are not fully synced to MailChimp.

The following code in CRM_Mailchimp_Sync::collectCivicrm() results in a GROUP_CONCAT in MySQL, which can result in the list of groups $result['values'][cid]['groups'] being cut off for really "engaged" contacts:

    $result = civicrm_api3('Contact', 'get', [
      'is_deleted' => 0,
      // The email filter in comment below does not work (CRM-18147)
      // 'email' => array('IS NOT NULL' => 1),
      // Now I think that on_hold is NULL when there is no e-mail, so if
      // we are lucky, the filter below implies that an e-mail address
      // exists ;-)
      'is_opt_out' => 0,
      'do_not_email' => 0,
      'on_hold' => 0,
      'is_deceased' => 0,
      'group' => $this->membership_group_id,
      'return' => ['first_name', 'last_name', 'group'],
      'options' => ['limit' => 0],
      //'api.Email.get' => ['on_hold'=>0, 'return'=>'email,is_bulkmail'],
    ]);

In most MySQL configurations, GROUP_CONCAT has a default limit that is too low to handle more than 6-10 group memberships per contact (depending how long the group names are).

Workaround is to change the MySQL configuration in my.cnf: group_concat_max_len = 50000;

But I suspect the API query could be done differently in the MailChimp extension itself, to avoid users needing to troubleshoot their MySQL configuration.