Download & Extend

Standard db_last_insert_id instead of VBTODRUPAL_ADD_TO_IDS

Project:vBulletin to Drupal
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (works as designed)

Issue Summary

Instead of:

define('VBTODRUPAL_ADD_TO_IDS', 1000000);

which gives IDs such as 1000001, etc., the standard way for vbtodrupal -and all D6 modules- would be to use the db_last_insert_id API function for each table.

For example, comment_save uses it in this way:

$edit['cid'] = db_last_insert_id('comments', 'cid');

Comments

#1

vBulletin to Drupal doesn't create rows one by one, hence this approach won't work.

It should work, however, to read out the current auto_increment counters for all affected tables, determine the maximum value and use it as offset:
SELECT MAX(Auto_increment) FROM information_schema.tables WHERE table_schema = 'drupal_database_name' AND table_name IN ('node', 'node_revisions', 'comment', 'user', etc...);
This doesn't save us from "holes" in index numbers, but at least keeps the holes as small as possible. And it's limited to MySQL 5 (or whichever version introduced the information_schema).

#2

The reason the hole was added -- yeah, I did do it on purpose! ;) -- was so imported posts could easily be deleted. Not the best solution though, I agree.

We could store the start and finish id's for each table we import into. Wonder if it's safe to make the code MySQL 5 only yet.

Anyway, I haven't any time to work on this at the moment, but throw some ideas (or maybe even patches!) around and I'll be back shortly. :)

#3

Status:active» closed (works as designed)

I attempted to use db_last_insert_id() instead of VBTODRUPAL_ADD_TO_IDS in a new part of the import process but it broke the referential integrity between records in foreign tables.

Take {node} and {term_node}:
If we import a thread with id=1 into {node} with nid=23 posted in forum id=12, we run into a problem when associating nodes with taxonomy terms when inserting records into {term_node}. How do we know that thread id=1 now has nid=23? Moreover, how do we know what the equivalent to forum id=12 is in Drupal?

The Migrate module gets around this by using Drupal's API to save records, rather than importing directly to the database, but that is extremely slow when dealing with hundreds of thousands of records.