function testGetContactInMailchimpListByEmail() { $params = CRM_CiviMailchimp_UtilsTest::sampleContactParams(); $email = $params['email'][0]['email']; $contact = CRM_Contact_BAO_Contact::create($params); $mailchimp_sync_setting = CRM_CiviMailchimp_BAO_SyncSettingsTest::createTestGroupAndSyncSettings('Test group testGetContactInMailchimpListByEmail'); $contact_ids = array($contact->id); CRM_Contact_BAO_GroupContact::addContactsToGroup($contact_ids, $mailchimp_sync_setting->civicrm_group_id); $mailchimp_contact = CRM_CiviMailchimp_Utils::getContactInMailchimpListByEmail($email, $mailchimp_sync_setting->mailchimp_list_id); $this->assertEquals($contact->id, $mailchimp_contact->id); $this->assertEquals($email, $mailchimp_contact->email[0]->email); }
/** * Put a Mailchimp subscriber's email On Hold in CiviCRM. */ static function mailchimpWebhookCleaned($request_data) { $mailchimp_contact = CRM_CiviMailchimp_Utils::getContactInMailchimpListByEmail($request_data['email'], $request_data['list_id']); foreach ($mailchimp_contact->email as $email) { if ($email->email === $request_data['email']) { // We have to go the circuitous route to saving so we can trigger // CiviCRM's hooks to allow other extensions to act. $params = array(); CRM_Core_DAO::storeValues($email, $params); $params['on_hold'] = 1; CRM_Core_BAO_Email::add($params); } } }