function mailchimp_batch_update_members in Mailchimp 8
Same name and namespace in other branches
- 7.5 mailchimp.module \mailchimp_batch_update_members()
- 7.3 mailchimp.module \mailchimp_batch_update_members()
- 7.4 mailchimp.module \mailchimp_batch_update_members()
- 2.x mailchimp.module \mailchimp_batch_update_members()
Batch updates a number of Mailchimp list members.
See also
Mailchimp_Lists::batchSubscribe()
1 call to mailchimp_batch_update_members()
- mailchimp_lists_execute_mergevar_batch_update in modules/
mailchimp_lists/ mailchimp_lists.module - Batch processor for member mergevar updates to submit batches to Mailchimp.
File
- ./
mailchimp.module, line 772 - Mailchimp module.
Code
function mailchimp_batch_update_members($list_id, $batch) {
$results = FALSE;
try {
/* @var \Mailchimp\MailchimpLists $mc_lists */
$mc_lists = mailchimp_get_api_object('MailchimpLists');
if (!$mc_lists) {
throw new Exception('Cannot batch subscribe to list without Mailchimp API. Check API key has been entered.');
}
if (!empty($batch)) {
// Create a new batch update operation for each member.
foreach ($batch as $batch_data) {
// TODO: Remove 'advanced' earlier? Needed at all?
unset($batch_data['merge_vars']['advanced']);
$parameters = [
'email_type' => $batch_data['email_type'],
'merge_fields' => (object) $batch_data['merge_vars'],
];
$mc_lists
->addOrUpdateMember($list_id, $batch_data['email'], $parameters, TRUE);
}
// Process batch operations.
return $mc_lists
->processBatchOperations();
}
} catch (\Exception $e) {
\Drupal::logger('mailchimp')
->error('An error occurred performing batch subscribe/update. "{message}"', [
'message' => $e
->getMessage(),
]);
}
return $results;
}