The section of code in constant_contact_user() will unsubscribe users if user_save() is called as an api function (in our case, via the migrate module)

				if(isset($edit['cc_newsletter']) && $edit['cc_newsletter']):
					$status = $cc->update_contact($contact['id'], $edit['mail'], array_keys($lists), $fields);
				elseif (isset($edit['cc_newsletter'])) :
					$status = $cc->update_contact($contact['id'], $edit['mail'], array(), $fields);
				endif;

furthermore, even without that little gotcha, it slows the import process down by several orders of magnitude by unnecessarily contacting constant contact. The attached patch does 2 things. First, it aborts the function if $edit['cc_newsletter'] is not set (which is an indication that user_save() was called from a source other than the user edit or user registration form, and secondly, it updates the code above to explicitly only act if the cc_newsletter variable is present. I'm not familiar enough with the code here:

			else:
				if(isset($account->cc_newsletter) && $account->cc_newsletter):
					$status = $cc->update_contact($contact['id'], $account->mail, array_keys($lists), $fields);
				else:
					$status = $cc->update_contact($contact['id'], $account->mail, array(), $fields);
				endif;
			endif;

to know if and how it is called. It may need a similar elseif (isset($account->cc_newsletter)) to avoid inadvertent unsubscribe requests being sent to constant contact.

CommentFileSizeAuthor
constant_contact.user_save.patch1.07 KBjhedstrom

Comments

jhedstrom’s picture

Correction, the code posted above includes the patch...so the original code is this:

                if(isset($edit['cc_newsletter']) && $edit['cc_newsletter']):
                    $status = $cc->update_contact($contact['id'], $edit['mail'], array_keys($lists), $fields);
                else:
                    $status = $cc->update_contact($contact['id'], $edit['mail'], array(), $fields);
                endif;
justphp’s picture

Assigned: Unassigned » justphp
Status: Needs review » Needs work

Ok, thanks for taking the time to report this problem, I'll be releasing an update with some new features next week so will get this fixed at the same time.

justphp’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Status: Closed (fixed) » Needs review

Sorry to open this again, but this patch breaks the module when the selected method is checkbox and not list. This code fixes it:

// Fixes a bug: http://drupal.org/node/697400
	if($op == 'insert' || $op == 'after_update'):
        if ($category == 'account' && (!isset($edit['cc_newsletter_lists']) AND !isset($edit['cc_newsletter']))):
                 return;
        endif;
		if(!isset($edit['cc_newsletter']) && !isset($account->cc_newsletter) && !count($edit['cc_newsletter_lists']) && !count($account->cc_newsletter_lists)):
			return;
		endif;
	endif;

Sincerely,
Leighton Whiting

locomo’s picture

i can confirm the fix in #5 works for me

justphp’s picture

Status: Needs review » Needs work

I'll add it to the next release. Thanks.

justphp’s picture

Status: Needs work » Closed (fixed)

Fixed in git, will be deployed with the next release,