You are here

Drupal - direkter Import in die Datenbank

I was trying the last week to import data from one database into a Drupal database. Basically this worked fairly well. The needed fields from the old database are easy to get by simple SELECT statements. Because I don't know anything about PHP, I doing the export/import with a Python script directly into the database. After all this is about articles, comments and tags, that need to be imported into a Drupal database.

The articles will be stored into tables node_revisions, node and node_counter. The tags into tables term_data and term_node. Comments will go into table comments. Here are the INSERTs:

Articles:
"insert into node_revisions (uid, body, teaser, log, timestamp, format, nid, title) values ('3', '%s', '%s', '', '%s', '1', '%s', '%s')" % (body, body, timestamp, i, title)
"insert into node (vid, type, uid, status, created, changed, comment, promote, moderate, sticky, language, tnid, translate, title) values ('%s', 'blog', '3', '1', '%s', '%s', '2', '1', '0', '0', '', '0', '0', '%s')" % (vid, timestamp, timestamp, title)
"insert into node_counter (nid,totalcount,daycount,timestamp) values ('%s', '100', '0','%s')" % (nid, timestamp)

Tags:
"insert into term_data (vid, name) values ('3', '%s')" % tag
"insert into term_node (nid, vid, tid) values ('%s', '%s', '%s')" % (nid, vid, tagtid)

Comments:
"insert into comments (pid, nid, uid, subject, comment, hostname, timestamp, status, format, thread, name, mail, homepage) values ('%s', '%s', '0', '%s', '%s', '%s', '%s', '0', '1', '01', '%s', '%s', '%s')" % (parentid, nid, ctitle, cbody, cip, ctimestamp, cauthor, cemail, curl)
sql="insert into term_node (nid, vid, tid) values ('%s', '%s', '%s')" % (nid, vid, tid)

The import is successful as there are comments and tags attached to each article or node. But there are still some problems. When accessing Recent Posts there are no entries listed. Yet, Drupal still thinks there are so many articles that it lists more than 30 pages:

Recent Post Errors

Something similar happens to the tags. The tags are actually assigned to and are displayed as well with the nodes. But when accessign taxonomys vocabular and trying to list the terms, the resulting page is empty:

Tag Errors

If my understanding of the Drupal6 database (on PostgreSQL this is) is correct, everything should be fine and properly stored into the database. But apparently there's something missing. But what? As already mentioned I have no clue about PHP, so using node_api or any other API calls by Drupal/PHP is no option for me. Except when the calls can be placed via Pythons system() call.

If anyone has some tips or hints for me, I would appreciate when you write a comment.
When there's interest I can provide the entire Python import script. I'm going to make it public anyway, when the last problems are solved.

UPDATE:
Killes on IRC hinted me that node_comment_statistics and term_hierarchy needs to be filled as well. Thanks for the hint!

Kategorie: 
 

Comments

Ich habe mir in ähnlichen Fällen auch damit geholfen, dass ich einen SQL dump genommen habe, dann in Drupal einen (!) Beitrag mit Kommentar(en) angelegt habe. Dann die Seite ein paar mal aufrufen für die Statistiken und wieder einen SQL dump genommen und mit Diff verglichen. So war gut zu sehen, welche Tabellen mit welchen Werten zu füllen waren. Viel Spaß beim Basteln!

Dirk

Ja, so hab ich das auch gemacht, aber irgendwie waren die beiden anderen Tabellen da dann auch noch leer. Sonst waere ich ja viel frueher auf die Idee gekommen, die auch noch zu befuellen.

So, eigentlich sollte das nun hier der letzte Eintrag in Serendipity werden... :-)

[...] lief. Im Großen und Ganzen lief der Wechsel ziemlich problemlos, nachdem ich gestern die letzten Probleme aus der Welt räumen konnte. Aber sicherlich wird es noch einige Zeit brauchen, bis ich alles [...]

Pages

Add new comment

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer