You are here

function mailchimp_lists_execute_mergevar_batch_update in Mailchimp 7.3

Same name and namespace in other branches
  1. 8 modules/mailchimp_lists/mailchimp_lists.module \mailchimp_lists_execute_mergevar_batch_update()
  2. 7.5 modules/mailchimp_lists/mailchimp_lists.module \mailchimp_lists_execute_mergevar_batch_update()
  3. 7.4 modules/mailchimp_lists/mailchimp_lists.module \mailchimp_lists_execute_mergevar_batch_update()
  4. 2.x modules/mailchimp_lists/mailchimp_lists.module \mailchimp_lists_execute_mergevar_batch_update()

Batch processor for member mergevar updates to submit batches to MailChimp.

1 string reference to 'mailchimp_lists_execute_mergevar_batch_update'
mailchimp_lists_update_member_merge_values in modules/mailchimp_lists/mailchimp_lists.module
Triggers an update of all merge field values for appropriate entities.

File

modules/mailchimp_lists/mailchimp_lists.module, line 476

Code

function mailchimp_lists_execute_mergevar_batch_update($list_id, &$context) {
  if (!isset($context['sandbox']['progress'])) {
    $context['sandbox']['mc_batch_limit'] = variable_get('mailchimp_batch_limit', 1000);
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['total'] = count($context['results']['update_queue']);
    $context['results']['updates'] = 0;
    $context['results']['errors'] = 0;
  }
  if ($context['sandbox']['progress'] < $context['sandbox']['total']) {
    $batch = array_slice($context['results']['update_queue'], $context['sandbox']['progress'], $context['sandbox']['mc_batch_limit']);
    $result = mailchimp_batch_update_members($list_id, $batch, FALSE, TRUE, FALSE);
    if ($result) {
      $context['results']['updates'] += $result['update_count'];
      $context['results']['errors'] += $result['error_count'];
    }
    $batch_size = count($batch);
    $context['sandbox']['progress'] += $batch_size;
    $context['message'] = t('Updating MailChimp mergevars for items %count - %next.', array(
      '%count' => $context['sandbox']['progress'],
      '%next' => $context['sandbox']['progress'] + $batch_size,
    ));
    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['total'];
  }
}