batch_birthdays_sync_p2b($field, &$context)Profile to Birthdays batch copying process.
contributions/birthdays/birthdays.sync.inc, line 109
<?php
function batch_birthdays_sync_p2b($field, &$context) {
// First run, set up the sandbox.
if (empty($context['sandbox'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['current_user'] = 0;
// Count how many users are going to be processed.
$context['sandbox']['max'] = db_result(db_query('SELECT COUNT(DISTINCT uid) FROM {users} WHERE uid > 0'));
}
// I'm not sure how many a slow server can process within the batch execution
// limit, but 25 seems not too much. Faster machines won't notice the limit
// thanks to the Batch API.
$limit = 25;
// Get next batch of users.
$result = db_query_range('SELECT uid FROM {users} WHERE uid > %d ORDER BY uid ASC', $context['sandbox']['current_user'], 0, $limit);
// For each user id.
while ($uid = db_fetch_object($result)) {
// Get the user object.
$account = user_load(array('uid' => $uid->uid));
// If the date of birth was set
if ($account->{$field->name}) {
// Save it, so birthdays_user() will be called and all necessary actions
// will be performed.
user_save($account, array($field->name => $account->{$field->name}));
}
// Updating the sandbox.
$context['sandbox']['progress']++;
$context['sandbox']['current_user'] = $account->uid;
}
// Update the message.
$context['message'] = t('Synchronized @current of @total users.', array('@current' => $context['sandbox']['progress'], '@total' => $context['sandbox']['max']));
// If not yet finished, calculate the proportion of items that are.
if ($context['sandbox']['progress'] < $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
}
?>