You are here

function mailchimp_lists_get_subscribers in Mailchimp 7.4

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

Batch processor for pulling in subscriber information for a list.

File

modules/mailchimp_lists/mailchimp_lists.module, line 408

Code

function mailchimp_lists_get_subscribers($field, &$context) {
  if (!isset($context['sandbox']['progress'])) {
    $context['results']['subscribers'] = array();
    $context['sandbox']['progress'] = 0;
  }
  $batch_size = variable_get('mailchimp_batch_limit', 100);
  $options = array(
    'offset' => $context['sandbox']['progress'],
    'count' => $batch_size,
  );
  $matches = mailchimp_get_members($field['settings']['mc_list_id'], 'subscribed', $options);
  if (!empty($matches) && $matches->total_items > 0) {
    if (!isset($context['sandbox']['max'])) {
      $context['sandbox']['max'] = $matches->total_items;
    }
    foreach ($matches->members as $result) {
      $context['results']['subscribers'][strtolower($result->email_address)] = $result;
    }
    $context['sandbox']['progress'] += count($matches->members);
    $context['message'] = t('Check subscription status for contact %count of %total.', array(
      '%count' => $context['sandbox']['progress'],
      '%total' => $context['sandbox']['max'],
    ));
    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
  }
}