function mailchimp_lists_queue_existing in Mailchimp 7.2
Queue existing users in a list. Optionally, queue users to remove.
@mailchimp_list $list
@boolean $queue_removals If set to TRUE, will queue anyone who should be removed from the list.
Return value
int Number of users queued.
3 calls to mailchimp_lists_queue_existing()
- MailchimpListsBasicTestCase::testMailchimpListSubscriptionWorkflow in modules/
mailchimp_lists/ tests/ mailchimp_lists.test - Tests subscription workflows.
- mailchimp_lists_list_form_submit in modules/
mailchimp_lists/ includes/ mailchimp_lists.admin.inc - Submit handler for mailchimp_lists_list_form().
- mailchimp_lists_queue_existing_form_submit in modules/
mailchimp_lists/ includes/ mailchimp_lists.admin.inc - Submit handler for mailchimp_lists_queue_existing_form().
File
- modules/
mailchimp_lists/ mailchimp_lists.module, line 1003 - Mailchimp lists module.
Code
function mailchimp_lists_queue_existing($list, $queue_removals = FALSE) {
// Grab our queue:
$queue = DrupalQueue::get(MAILCHIMP_QUEUE_CRON);
$queue
->createQueue();
// Get a list of active users:
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'user')
->propertyCondition('status', 1);
$result = $query
->execute();
$users = user_load_multiple(array_keys($result['user']));
// If the user belongs in the list, add to queue.
// @todo Use the batch system to avoid timeouts for lots of users.
$count = 0;
foreach ($users as $user) {
$intersect = array_intersect(array_keys($user->roles), $list->settings['roles']);
if (!empty($intersect)) {
if ($list->settings['required']) {
$merge_vars = mailchimp_lists_load_user_mergevars($user, $list);
mailchimp_lists_execute_change('add', $list, $user->mail, $merge_vars, $user, NULL, $queue);
$count++;
}
}
elseif ($queue_removals) {
if (mailchimp_is_subscribed($list->mc_list_id, $user->mail)) {
mailchimp_lists_execute_change('remove', $list, $user->mail, NULL, $user, NULL, $queue);
$count++;
}
}
}
return $count;
}