function mailchimp_cron in Mailchimp 6
Same name and namespace in other branches
- 8 mailchimp.module \mailchimp_cron()
- 5.2 mailchimp.module \mailchimp_cron()
- 5 mailchimp.module \mailchimp_cron()
- 6.2 mailchimp.module \mailchimp_cron()
- 7.5 mailchimp.module \mailchimp_cron()
- 7 mailchimp.module \mailchimp_cron()
- 7.3 mailchimp.module \mailchimp_cron()
- 7.4 mailchimp.module \mailchimp_cron()
- 2.x mailchimp.module \mailchimp_cron()
Implementation of hook_cron. Resubscribes all users to the required lists if the user has chosen to do so.
2 string references to 'mailchimp_cron'
File
- ./
mailchimp.module, line 154 - Mailchimp module.
Code
function mailchimp_cron() {
if (variable_get('mailchimp_cron', FALSE) && ($q = _mailchimp_get_api_object())) {
$result = db_query('SELECT uid FROM {users} where status = %d', 1);
if ($result) {
$lists = _mailchimp_get_required_lists($q
->lists());
foreach ($lists as $key => $list) {
$lists[$key]['batch'] = array();
$lists[$key]['mergevars'] = $q
->listMergeVars($list['id']);
}
while ($row = db_fetch_object($result)) {
$account = user_load(array(
'uid' => $row->uid,
));
foreach ((array) $lists as $key => $list) {
foreach ((array) $account->roles as $rid => $info) {
if (variable_get('mailchimp_list_' . $list['id'] . '_role_' . $rid, 0)) {
$lists[$key]['batch'][] = _mailchimp_load_user_list_mergevars($row->uid, $list['id'], $lists[$key]['mergevars']);
break;
}
}
}
}
$count = 0;
foreach ($lists as $key => $list) {
if (count($lists[$key]['batch'])) {
$ret = $q
->listBatchSubscribe($list['id'], $lists[$key]['batch'], FALSE, TRUE);
if ($ret['error_count'] > 0) {
foreach ((array) $ret['errors'] as $error) {
watchdog('mailchimp', $error['email_address'] . ': ' . $error['message'], array(), WATCHDOG_ERROR);
}
}
}
$count += $ret['success_count'];
}
watchdog('mailchimp', 'Updated !count records in MailChimp', array(
'!count' => $count,
), WATCHDOG_NOTICE);
}
}
}