ARCHIVE: Generic Mass SQL Import into Drupal
# General Notes for Mass Import into Drupal
#
# The below is a template for an SQL import file to programmatically
# add nodes into Drupal version 4.7.0.
#
# - Currently not tested on 4.7.3, but there does not seem to be any
# radical changes in the Database structure that would break this.
#
# - You will probably need to create a separate program to parse
# your existing content and create the needed looping structures
# to properly create the SQL import file for you system.
#
# - You must follow SQL rules for data entry, see your SQL
# documentation. Incorrect escaping will cause truncated fields.
#
# - Copyright M.J. Taylor, from Reason to Freedom
# - Personal use: Free of charge.
# - Professional use: Only with USD $20 donated
# to Drupal.org per domain you use it on.*
#
# - This header and all copyright notices must remain intact
# upon any reprint/redistribution.
#
# - *Don't stiff Drupal.org, if you're using this professionally
# on five domains, you can afford to send Drupal.org $100.
#
# ======== Set Once Vars ==========
set @uid_value = 7; # Author ID (User ID)
set @format = 3; # 1 => Filtered HTML | 2 => PHP code | 3 => Full HTML
# ======== End Set Once Vars ==========
# ======== Set Per Node Vars ==========
/* set some variables to zero */
set @node_value = 0, @node_rev_vid_value = 0; # load these values as we execute.
/* Set some default values */
set @title_value = 'The Title';
/* May also set entry_date_time like curr_date_time below */
set @entry_date_time = unix_timestamp('2002-05-20 12:00:00'); # get specific date and time as number of seconds from 01/01/1970.
set @url_dest = 'the_url.html';
set @teaser_value = '<P>Teaser Para 1.</P>
<P>Teaser Para 2.</P>
';
set @body_value = '<P>Body Para 1.</P>
<P>Body Para 2.</P>
<P>Body Para 3.</P>
<P>Body Para, ad nauseam</P>
';
set @curr_date_time = unix_timestamp(); # get current date and time as number of seconds from 01/01/1970.
START TRANSACTION;
/* Increment node_nid field in sequences. */
update sequences set id = id + 1 where name = 'node_nid';
/* Get new node_nid value from sequences for later */
select @node_value := max(id) from sequences where name = 'node_nid';
/* Increment node_revisions_vid field in sequences. */
update sequences set id = id + 1 where name = 'node_revisions_vid';
/* Get node_revisions_vid value from sequences for later */
select @revisions_value := max(id) from sequences where name = 'node_revisions_vid';
COMMIT;
START TRANSACTION;
Insert into node
(nid, type, title, uid, status, created, changed, comment, promote, moderate, sticky, vid)
VALUES
(@node_value, 'story', @title_value, @uid_value, 1, @entry_date_time, @curr_date_time, 2, 1, 0, 0, @revisions_value);
Insert into node_comment_statistics
(nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count)
VALUES
(@node_value, @curr_date_time, NULL, @uid_value, 0);
Insert into node_revisions
(nid, vid, uid, title, body, teaser, timestamp, format, log)
VALUES
(@node_value, @revisions_value, @uid_value, @title_value, @body_value, @teaser_value, @curr_date_time, @format, "");
Insert into history
(uid, nid, timestamp)
VALUES
(@uid_value, @node_value, @curr_date_time);
Insert into node_counter
(nid, totalcount, daycount, timestamp)
VALUES
(@node_value, 1, 1, @curr_date_time);
COMMIT;
set @url_src = concat( "node/", @node_value ) ;
Insert into url_alias
(src,dst)
VALUES
(@url_src, @url_dest);
# ======== End Set Per Node Vars ==========
# ======== Set multiple Terms per Node ==========
/* set term_value and insert as many times as you need */
set @term_value = 50;
Insert into term_node
(nid,tid)
VALUES
(@node_value, @term_value);
set @term_value = 48;
Insert into term_node
(nid,tid)
VALUES
(@node_value, @term_value);
# ======== End Set multiple Terms per Node ==========
# EOF #