Skip to content

Commit

Permalink
Prevent unsubscribing contacts during CiviCRM to Mailchimp sync
Browse files Browse the repository at this point in the history
  • Loading branch information
krishgopi committed Aug 20, 2020
1 parent 027808e commit f7820ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions CRM/Mailchimp/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,17 +745,20 @@ public function updateMailchimpFromCivi() {
if ($this->dry_run) {
// Just log.
if ($unsubscribes) {
CRM_Mailchimp_Utils::checkDebug("Would unsubscribe " . count($unsubscribes) . " Mailchimp members: " . implode(', ', $removals));
CRM_Mailchimp_Utils::checkDebug("Total of " . count($unsubscribes) . " Mailchimp members are not in CiviCRM: " . implode(', ', $removals));
}
else {
CRM_Mailchimp_Utils::checkDebug("No Mailchimp members would be unsubscribed.");
}
}
else {
// For real, not dry run.
// we are not unsubcribing Mailchimp members from CiviCRM now.
/*
foreach ($removals as $email) {
$operations[] = ['PATCH', $url_prefix . md5(strtolower($email)), ['status' => 'unsubscribed']];
}
*/
}

if (!$this->dry_run && !empty($operations)) {
Expand Down Expand Up @@ -1169,13 +1172,17 @@ public function updateMailchimpFromCiviSingleContact($contact_id) {
$api = CRM_Mailchimp_Utils::getMailchimpApi();

if (!$currently_a_member) {

// They are not currently a member.
//
// We are not unsubscribing Mailchimp members from CiviCRM now.
CRM_Core_Session::setStatus(ts('This email is not in CiviCRM group now but exists in Mailchimp list; any differences will remain until this is unsubscribed in Mailchimp.'));
return;
// We should ensure they are unsubscribed from Mailchimp. They might
// already be, but as we have no way of telling exactly what just changed
// at our end, we have to make sure.
//
// Nb. we don't bother updating their interests for unsubscribes.
/*
try {
$result = $api->patch("/lists/$this->list_id/members/$subscriber_hash",
['status' => 'unsubscribed']);
Expand All @@ -1191,6 +1198,7 @@ public function updateMailchimpFromCiviSingleContact($contact_id) {
catch (CRM_Mailchimp_NetworkErrorException $e) {
CRM_Core_Session::setStatus(ts('There was a network problem trying to unsubscribe this contact at Mailchimp; any differences will remain until a CiviCRM to Mailchimp Sync is done.'));
}
*/
return;
}

Expand Down
4 changes: 2 additions & 2 deletions templates/CRM/Mailchimp/Form/Sync.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<tr><td>{ts}Contacts that were in sync already{/ts}:</td><td>{$group.stats.in_sync}</td></tr>
<tr><td>{ts}Contacts updated at Mailchimp{/ts}:</td><td>{$group.stats.updates}</td></tr>
<tr><td>{ts}Contacts Subscribed{/ts}:</td><td>{$group.stats.additions}</td></tr>
<tr><td>{ts}Contacts Unsubscribed from Mailchimp{/ts}:</td><td>{$group.stats.unsubscribes}</td></tr>
<tr><td>{ts}Contacts need to be unsubscribed from Mailchimp{/ts}:</td><td>{$group.stats.unsubscribes}</td></tr>
</table>
{/foreach}
</div>
Expand All @@ -38,7 +38,7 @@
supposed to be subscribed to the Mailchimp list is correct.{/ts}</p>
<p>{ts}Points to know:{/ts}</p>
<ul>
<li>{ts}If a contact is not in the membership group at CiviCRM, they will be unsubscribed from Mailchimp (assuming they are currently subscribed at Mailchimp).{/ts}</li>
<li>{ts}If a contact is not in the membership group at CiviCRM and currently subscribed at Mailchimp, they will need to be unsubscribed from Mailchimp manually.{/ts}</li>
<li>{ts}If a contact is in the membership group, they will be subscribed at Mailchimp. <strong>This could cost you money if adding subscribers exceeds your current tariff.</strong>
Check the numbers of contacts in each group and/or do a Dry Run first.{/ts}</li>
<li>{ts}Any and all CiviCRM groups set up to sync to Mailchimp Interests will be consulted and changes made to members' interests at Mailchimp, as needed.{/ts}</li>
Expand Down

0 comments on commit f7820ae

Please sign in to comment.