Use Batch API for import

nbz - February 7, 2008 - 17:34
Project:phpBB2Drupal
Version:HEAD
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:active
Description

I have decided to separate this issue out from the port to Drupal 6 issue.

Currently the module uses a default ini_set of 1200 seconds to avoid timing out when importing data. There are still time outs. The answer should be to use the new batch api introduces in Drupal 6. "Should be" because I am finding it trickier to do than I probably should.

Attached is a patch to batch import the users. I have tried a few different ways, but nothing seems to work. Worse, I do not know what I am doing wrong.

The only place I can think of which may be wrong is the query to get the user id's:

$user_ids = db_query_range('SELECT user_id FROM %susers WHERE user_id > 2 ORDER BY user_id', $pre, $context['sandbox']['user_row'], $limit);

Any input will be helpful.

AttachmentSize
phpbb2drupal_batch.patch3.3 KB

#1

nbz - February 7, 2008 - 18:19

I think I should qualify "nothing seems to work".

What happens, the batch operation starts, says "2 users processed", finishes a few seconds later and says 1 user imported.

It seems the batch (or the "while" loop) loops just twice instead of how ever many users there are. (the final tally is not from the score kept, but by reading the phpbb2drupal_temp_users table.)

I have also previously tried a different approach where the while loop,is outside the batch operation similar to:

while $result = db_fetch_object($user_ids) {

$operations = phpbb2drupal_batch_import_users, array ($result)

}

$batch = array(
  'operations' => array($operations),
  'finished' => 'phpbb2drupal_batch_import_users_finished',
  'title' => t('Migrating Users'),
  'init_message' => t('User import is starting.'),
  'progress_message' => t('@current users processes.'),
  'error_message' => t('User import has encountered an error.'),
);
batch_set($batch);

But this caused an OOM as (I think) there were too many operations (one for each user). Additionally, I do not expect that code to work... I would expect it to load the same user over and over again.

 
 

Drupal is a registered trademark of Dries Buytaert.