From f7820ae257f4ca91ae9e588e4311ec83dc273dc6 Mon Sep 17 00:00:00 2001
From: krishgopi
Date: Thu, 20 Aug 2020 23:17:48 +0100
Subject: [PATCH] Prevent unsubscribing contacts during CiviCRM to Mailchimp
sync
---
CRM/Mailchimp/Sync.php | 12 ++++++++++--
templates/CRM/Mailchimp/Form/Sync.tpl | 4 ++--
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/CRM/Mailchimp/Sync.php b/CRM/Mailchimp/Sync.php
index ae2dd02..c2fb33c 100644
--- a/CRM/Mailchimp/Sync.php
+++ b/CRM/Mailchimp/Sync.php
@@ -745,7 +745,7 @@ 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.");
@@ -753,9 +753,12 @@ public function updateMailchimpFromCivi() {
}
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)) {
@@ -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']);
@@ -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;
}
diff --git a/templates/CRM/Mailchimp/Form/Sync.tpl b/templates/CRM/Mailchimp/Form/Sync.tpl
index 39cdd57..f25fdaf 100644
--- a/templates/CRM/Mailchimp/Form/Sync.tpl
+++ b/templates/CRM/Mailchimp/Form/Sync.tpl
@@ -13,7 +13,7 @@
{ts}Contacts that were in sync already{/ts}: | {$group.stats.in_sync} |
{ts}Contacts updated at Mailchimp{/ts}: | {$group.stats.updates} |
{ts}Contacts Subscribed{/ts}: | {$group.stats.additions} |
- {ts}Contacts Unsubscribed from Mailchimp{/ts}: | {$group.stats.unsubscribes} |
+ {ts}Contacts need to be unsubscribed from Mailchimp{/ts}: | {$group.stats.unsubscribes} |
{/foreach}
@@ -38,7 +38,7 @@
supposed to be subscribed to the Mailchimp list is correct.{/ts}
{ts}Points to know:{/ts}
- - {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}
+ - {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}
- {ts}If a contact is in the membership group, they will be subscribed at Mailchimp. This could cost you money if adding subscribers exceeds your current tariff.
Check the numbers of contacts in each group and/or do a Dry Run first.{/ts}
- {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}