[Header Picture]

# Code snippit: Inserting Drupal entries

I recently helped a friend import 9 years worth of content into a Drupal system. The documentation for Drupal sucks, so for the benefit of anyone else needing to do the same thing, here's some valuable information on how to import nodes into a Drupal system.

The SQL below will insert whatever content you need into a standard node. It will create term entries so you can use the standard Drupal category listings. It's also a good base to start from if you're trying to use flexinodes or whatever else you need to use.

You're left on your own for finding free NIDs. There's a sequence you can query and store in a variable, or you can do what I did and generate a list of NIDs that were in use at once time but had been deleted for one reason or another.

This information was figured out through no help of anyone related to Drupal. I found the Drupal documentation to be less than worthless. I also found #drupal-support on Freenode to be completely worthless, as well. The only way I was able to figure out exactly which tables to add entries to was by doing a mysql dump of the db, and searching for existing node ids.

(And don't get me started on their DB. Mysql and a DB with no referential integrity. Would a few REFERENCES statements in their DB schema be such a bad thing?)

Term Definition Term Definition
uid User ID nid Node ID
changed A unix timestamp representing the time you uploaded the entry created A unix timestamp representing the time the entry was created
title The Entry's title body The content for the entry
gid The Group ID for the entry (For permissions) tid The Term (or category) ID for the entry
DELETE FROM history WHERE nid = %(nid)s;
        (uid, nid, timestamp)
        (%(uid), %(nid)s, %(changed)s);
        (nid, type, title, uid, status, created, changed, comment, promote,
        moderate, teaser, body, sticky, format)
        (%(nid)s, 'blog', '%(title)s', 1, 1, %(created)s, %(changed)s, 2, 0, 0,
        '%(body)s', '%(body)s', 0, 3);
DELETE FROM node_access WHERE nid = %(nid)s;
INSERT INTO node_access
        (nid, gid, realm, grant_view, grant_update, grant_delete)
        (%(nid)s, %(gid)s, 'term_access', 1, 0, 0);
DELETE FROM node_comment_statistics WHERE nid = %(nid)s;
INSERT INTO node_comment_statistics
        (nid, last_comment_timestamp, last_comment_name, last_comment_uid,
        (%(nid)s, %(changed)s, NULL, 1, 0);
DELETE FROM term_node WHERE nid = %(nid)s;
INSERT INTO term_node
        (nid, tid)
        (%(nid)s, %(tid)s);

posted at: 2006 Jun 09 01:37 UTC | category: tech | (story link)

Copyright © 2006-2008 Zach White