[development] Batch API Help (data import in phpBB2Drupal)

Naheem Zaffar naheemzaffar at gmail.com
Thu Feb 7 17:54:38 UTC 2008


hi all

I am the current maintainer for the phpbb2drupal module and am trying
to get it to batch import data. First step: Import users.

I have read the batch_example (http://drupal.org/node/180528 ), but I
cannot make it work for this module.

Following is a quick summary up this is what I have done:

phpbb2drupal_import_users() is called from a form and it contains
amongst other things:

$batch = array(
  'operations' => array('phpbb2drupal_batch_import_users', array()),
  'finished' => 'phpbb2drupal_batch_import_users_finished',
);
batch_set($batch);

phpbb2drupal_batch_import_users contains:

if (!isset($context['sandbox']['progress'])) {
  $context['sandbox']['progress'] = 0;
  $context['sandbox']['user_row'] = 0;
  db_set_active('phpbb');
  $user_count = db_result(db_query('SELECT COUNT(user_id) FROM %susers
WHERE user_id > 2 ORDER BY user_id', $pre));
  db_set_active('default');
  $context['sandbox']['max'] = $usercount;
}

$limit = 5;
$user_ids = db_query_range('SELECT user_id FROM %susers WHERE user_id
> 2 ORDER BY user_id', $pre, $context['sandbox']['user_row'], $limit);
while ($result = db_fetch_object($user_ids)) {
//import user data then
   $context['sandbox']['progress']++;
   $context['sandbox']['user_row']++;
}

if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
  $context['finished'] = $context['sandbox']['progress'] /
$context['sandbox']['max'];
}

The issue and full patch are on this issue:
http://drupal.org/node/218966

Anyone got any ideas on how to make this work?

(I will assume I am doing something absolutely obvious wrong. That
assumption has never failed me before.)


More information about the development mailing list