/** * Migrate comment and forum to nodecomment and nodeforum **/ function nodecomment_upgrade() { $ret = array(); // set up a temp table for our nid/vid sequence to get new node_comment nids $ret[] = update_sql(" CREATE TABLE {temp_ncids} ( nvid int(10) NOT NULL AUTO_INCREMENT, cid int(10) NOT NULL default '0', PRIMARY KEY (nvid) ) "); // set the intial values that are equal to the drupal sequences table values $ret[] = update_sql(" INSERT INTO {temp_ncids} (nvid, cid) VALUES ( (SELECT id FROM {sequences} WHERE name = 'node_revisions_vid'), 0) "); // increment the temp table by inserting the comments we have $ret[] = update_sql(" INSERT INTO {temp_ncids} (cid) SELECT cid FROM {comments} "); // create the node table records // note that we are setting them all to comment type for now // forum_replies are fixed in a later query $ret[] = update_sql(" INSERT INTO {node} (nid, vid, type, title, uid, status, created, changed, comment, promote, moderate, sticky) SELECT t.nvid, t.nvid, 'comment', c.subject, c.uid, 1, c.timestamp, c.timestamp, 0, 0, 0, 0 FROM {comments} c, {temp_ncids} t WHERE c.cid = t.cid "); // create the node_revisions table records $ret[] = update_sql(" INSERT INTO node_revisions (nid, vid, uid, title, body, teaser, log, timestamp, format) SELECT t.nvid, t.nvid, c.uid, c.subject, c.comment, c.comment, '', c.timestamp, c.format FROM {comments} c, {temp_ncids} t WHERE c.cid = t.cid "); // move the comments data into the node_comments table $ret[] = update_sql(" INSERT INTO {node_comments} (cid, pid, nid, hostname, thread, name, mail, homepage) SELECT t.nvid, c.pid, c.nid, c.hostname, c.thread, c.name, c.mail, c.homepage FROM {comments} c, temp_ncids t WHERE c.cid = t.cid "); // migrate the term_node data to the new nodes $ret[] = update_sql(" INSERT INTO {term_node} (nid, tid) SELECT t.nvid, tn.tid FROM {temp_ncids} t, {term_node} tn WHERE t.nvid = tn.nid "); // change the forum comments to the forum_reply content type $ret[] = update_sql(" UPDATE node n SET n.type = 'forum_reply' WHERE n.nid IN ( SELECT nc.cid FROM forum f, node_comments nc WHERE f.nid = nc.nid ) "); // reset the sequences table $ret[] = update_sql(" UPDATE {sequences} SET id = ( SELECT MAX(nid) FROM {node} ) WHERE name = 'node_nid' OR name = 'node_revisions_vid' OR name = 'comments_cid' "); // copy over nodeforum data $ret[] = update_sql(" INSERT INTO {nodeforum} (nid, vid, tid) SELECT nid, vid, tid FROM {forum} "); // clean up old tables $ret[] = update_sql("DROP TABLE {temp_ncids}"); $ret[] = update_sql("DROP TABLE {comments}"); $ret[] = update_sql("DROP TABLE {forum}"); variable_set('default_comment_type', 'comment'); variable_set('comment_type_forum', 'forum_reply'); variable_set('comment_view_forum', 'forum_replies'); variable_set('comment_forum_reply', 0); variable_set('comment_comment', 0); variable_set('nodeforum_nav_vocabulary', 3); return $ret; }