I maintain a store where users can purchase roles that expire if they do not renew. However, unlike issue #630036: Automatic removal, my client would like them to stay on the email list even after expiration. Therefore we set our list preferences to allow this purchased role AND authenticated users to subscribe to the list. The problem is that the mailchimp_lists_user_sync doesn't check to see if a user still has a valid role. Instead, it checks to see if the removed role was in the allowable roles for the list (see code)

  if ($is_subscribed) {
    foreach ($removed_roles as $role_id => $role) {
      if (array_key_exists($role_id, $list->settings['roles'])) {
        // queue up for cron processing
        if ($list->settings['cron']) {
          $queue = DrupalQueue::get(MAILCHIMP_QUEUE_CRON);
            'uid' => $account->uid,
            'list_id' => $list->id,
            'op' => 'remove',
        // process immediately
        else {
          mailchimp_unsubscribe_user($list, $account->mail, FALSE, NULL, TRUE);

Instead of looping over the expired roles, the code should loop over the remaining roles and then only sending a request to remove if no valid roles are found.

This is major as we've already experienced a significant loss in our email list size as a result. Thankfully we keep weekly backups and will be able to restore a significant portion of this, but it's going to take a bit of time to make sure all their list preferences are in place!

Patch will be submitted in the next comment...

Members fund testing for the Drupal project. Drupal Association Learn more


rickmanelius’s picture

rickmanelius’s picture

Status: Active » Needs review
rickmanelius’s picture

FWIW, I ran some manual tests on this a second time to prove to myself that removing one role (but still having another valid role) would NOT result in an account being unsubscribed to mailchimp.

I'd like to set this to RBTC because I'm not sure if others will fit my edge case... but I'll stick to "needs review" for now and hope that this can make it into the next release!

levelos’s picture

Assigned: Unassigned » gcb
gcb’s picture

Status: Needs review » Fixed

Great patch rickmanelius, rolled into the latest set of commits: thanks for tracking this use case down! We'll put this into a release shortly.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.