Index: realname.admin.inc =================================================================== --- realname.admin.inc (revision 737) +++ realname.admin.inc (working copy) @@ -452,6 +452,50 @@ } /** + * Batchable function used to rebuild realnames + */ +function _realname_rebuild_realnames(&$context) { + if (empty($context['sandbox'])) { + // Initiate multistep processing. + $context['sandbox']['progress'] = 0; + $context['sandbox']['current_user'] = 0; + $context['sandbox']['max'] = db_result(db_query('SELECT COUNT(DISTINCT uid) FROM {users}')); + } + + // Process the next 20 users. + $limit = 20; + $result = db_query_range("SELECT u.uid, u.name, u.mail FROM {users} u WHERE uid > %d ORDER BY uid ASC", $context['sandbox']['current_user'], 0, $limit); + while ($row = db_fetch_object($result)) { + $realname->uid = $row->uid; + $realname->realname = _realname_make_name($row); + // Try to update, if fail - try to insert. + if (db_result(db_query('SELECT COUNT(uid) FROM {realname} WHERE uid=%d', $realname->uid))) { + drupal_write_record('realname', $realname, 'uid'); + } + else { + drupal_write_record('realname', $realname); + } + $context['sandbox']['progress']++; + $context['sandbox']['current_user'] = $row->uid; + } + + // Multistep processing : report progress. + if ($context['sandbox']['progress'] != ($context['sandbox']['max']) - 1) { + $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; + } +} + +function _realname_rebuild_batch_finished($success, $results, $operations) { + if ($success) { + drupal_set_message(t('The realnames have been rebuilt.')); + variable_set('realname_recalculate', FALSE); + drupal_goto('admin/user/realname'); + } + else { + drupal_set_message(t('The realnames have not been properly rebuilt.'), 'error'); + } +} +/** * Handler for rebuild confirmation */ function realname_rebuild_confirm_submit($form, &$form_state) { @@ -459,8 +503,9 @@ 'title' => t('Rebuilding realnames'), 'operations' => array( array('_realname_rebuild_realnames', array()), - ), - 'finished' => '_realname_rebuild_batch_finished' + ), + 'file' => drupal_get_path('module', 'realname') . '/realname.admin.inc', + 'finished' => '_realname_rebuild_batch_finished', ); batch_set($batch); } Index: realname.module =================================================================== --- realname.module (revision 737) +++ realname.module (working copy) @@ -803,46 +803,3 @@ drupal_json($matches); } - -/** - * Batchable function used to rebuild realnames - * Batch API does not for some reason pick'em up in realname.admin.inc - */ -function _realname_rebuild_realnames(&$context) { - if (empty($context['sandbox'])) { - // Initiate multistep processing. - $context['sandbox']['progress'] = 0; - $context['sandbox']['current_user'] = 0; - $context['sandbox']['max'] = db_result(db_query('SELECT COUNT(DISTINCT uid) FROM {users}')); - } - - // Process the next 20 users. - $limit = 20; - $result = db_query_range("SELECT u.uid, u.name, u.mail FROM {users} u WHERE uid >= %d ORDER BY uid ASC", $context['sandbox']['current_user'], 0, $limit); - while ($row = db_fetch_object($result)) { - $realname->uid = $row->uid; - $realname->realname = _realname_make_name($row); - // Try to update, if fail - try to insert. - if (!drupal_write_record('realname', $realname, 'uid')) { - drupal_write_record('realname', $realname); - } - $context['sandbox']['progress']++; - $context['sandbox']['current_user'] = $row->uid; - } - - // Multistep processing : report progress. - if ($context['sandbox']['progress'] != $context['sandbox']['max']) { - $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; - } -} - -function _realname_rebuild_batch_finished($success, $results, $operations) { - if ($success) { - drupal_set_message(t('The realnames have been rebuilt.')); - variable_set('realname_recalculate', FALSE); - drupal_goto('admin/user/realname'); - } - else { - drupal_set_message(t('The realanmes have not been properly rebuilt.'), 'error'); - } -}