I need an upgrade/import script for 6.x. Something to import the comments into the correct tables and convert them to nodes of type 'comment'. Similar to the script seen here: http://drupal.org/node/200871

My comments do not import automatically.

Set to critical, since this keeps one from using any previous posts made via the comment.module.

Comments

nicholas.alipaz’s picture

OK, figured it out based on robertDouglass' 5.x script. There was one table that didn't exist in 6.x.

If anyone needs it, here are the queries I needed to run to sync everything up. I couldn't get the queries to process quite right via the update.php page as he had suggested so I ran them directly on the database via phpmyadmin.

Here is what I ran:

    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
  // here I needed to find the highest nid for my {node_revisions} table and insert it in the query
    INSERT INTO {temp_ncids} (nvid, cid)
    VALUES ([INSERT_NID], 0)

  // increment the temp table by inserting the comments we have
    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
    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
    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
    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
    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
  // I didn't do this step, however it is up to you.
    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
    )

  // copy over nodeforum data
    INSERT INTO {nodeforum} (nid, vid, tid)
    SELECT nid, vid, tid
    FROM {forum}

After, you might want to drop your forum and comments tables.

You will need to edit the queries to replace anything in squiggly brackets {} with your correct table. Many times the same name with a "drup_" in front of it.

quicksketch’s picture

Status: Active » Closed (duplicate)

We'll be fixing this in #472886: Convert comments to nodecomments and viceversa when the type is changed. It won't make it into the 1.x version of Node Comments.