You are here

function mailchimp_lists_execute_mergevar_batch_update in Mailchimp 8

Same name and namespace in other branches
  1. 7.5 modules/mailchimp_lists/mailchimp_lists.module \mailchimp_lists_execute_mergevar_batch_update()
  2. 7.3 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 480
Mailchimp lists/audiences module.

Code

function mailchimp_lists_execute_mergevar_batch_update($list_id, &$context) {
  if (!isset($context['sandbox']['progress'])) {
    $config = \Drupal::config('mailchimp.settings');
    $batch_limit = $config
      ->get('mailchimp_batch_limit');
    if (empty($batch_limit)) {
      $batch_limit = 1000;
    }
    $context['sandbox']['mc_batch_limit'] = $batch_limit;
    $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) {

      /* @var \Mailchimp\Mailchimp $mc */
      $mc = mailchimp_get_api_object();
      $batch_result = $mc
        ->getBatchOperation($result->id);
      $context['results']['updates'] += count($context['results']['update_queue']);
      $context['results']['errors'] += $batch_result->errored_operations;
    }
    $batch_size = count($batch);
    $context['sandbox']['progress'] += $batch_size;
    $context['message'] = t('Updating Mailchimp mergevars for items %count - %next.', [
      '%count' => $context['sandbox']['progress'],
      '%next' => $context['sandbox']['progress'] + $batch_size,
    ]);
    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['total'];
  }
}