Here is a comment and forum to nodecomment and nodeforum update script.

robertDouglass - December 14, 2007 - 10:14
Project:Node comments
Version:6.x-2.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

It's marginally well tested but your results may vary. Use with caution and only on a backup of your site. Check the accuracy of the results carefully. Please note that the script DROPS the forum and comment tables. You can comment those lines out if you don't want that, but it is intended to be a 1-way street. You also need to adjust the variables at the end of the script to reflect the comment types you're migrating to.

<?php
/**
* 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}");

 
// Adjust these variables to suite your needs.
 
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;
}
?>

AttachmentSize
nodecomment_upgrade.txt3.13 KB

#1

Summit - March 15, 2008 - 15:35

Hi Robert,

You are referring to nodeforum. Do you have nodeforum working correctly?

Greetings,
Martijn

#2

peterw - March 22, 2008 - 18:34

Will this work with the recently uploaded nodeforum (tagged in cvs as 1.1)?

#3

Summit - May 24, 2008 - 10:20

I tweaked nodeforum a little bit, it is working for my situation, see: http://drupal.org/node/234504#comment-770266 , please try it and make possible patches if you can to improve it on. I can't find out the functions completely downunder in the module.

Robert, I don't want to "steal" nodecomments threads, but nodeforum is not on drupal projects yet, do you know how to get it on project, so it gets is own issuelog, I am willing to maintain it a little bit, I am not a hardtime programmer, but have been able to manage nodeforum to my needings..

EDIT nodeforum module in test now.

Greetings,
Martijn

#4

peterw - March 25, 2008 - 00:50

Another question i have is how is this script used? Is it added on to one of the files in the nodeforum cvs? or added to another script which calls the function?

Any help would be appreciated.

#5

sirkitree - May 24, 2008 - 14:44

you would temporarily put this into the nodecomment.install and run update.php to execute.

#6

yngens - August 3, 2008 - 23:52

sirkitree, putting the code in .install did not work for me. in fact nodecomment modules is not listed among other modules on http://www.mysite.com/update.php?op=selection page.

#7

sirkitree - August 3, 2008 - 23:59

try changing nodecomment_upgrade() to nodecomment_update_5100()

make sure you understand what the code is doing before running it as well... it converts more then just comments.

#8

yngens - August 5, 2008 - 04:33

sirkitree, which part of the code i need to delete to be able to convert only comments? for instance, if i setup fresh drupal installation, add several comments on story done type using core comment module, and then i want to convert those comments to node comments?

thanks!

#9

greg.harvey - May 4, 2009 - 16:57

Out of interest, anyone seen anything to go the other way?? Having to temporarily drop nodecomment because the moderation features aren't working on my D6 blog and I'm getting spammed to hell. =(

Will write it myself if no one has anything already. Just thought I'd ask.

#10

ianchan - May 11, 2009 - 16:16

subscribe

#11

webchick - May 12, 2009 - 22:20

#12

quicksketch - May 27, 2009 - 19:30
Status:needs review» duplicate

This will be implemented as a feature in #472886: Convert comments to nodecomments and viceversa when the type is changed in the 2.x branch.

#13

jason2009 - July 1, 2009 - 07:10
Version:5.x-1.0» 6.x-2.x-dev
Status:duplicate» fixed

    $result = db_query("SELECT * FROM {comments}");
  while($item = db_fetch_object($result)) {
      $node = new stdClass();
      $node->type = 'comment';
      $node->comment_target_nid = $item->nid;
      $node->comment_target_cid = $item->pid;
      $node->nid = isset($item->uid) ? $item->uid : null;
      $node->teaser = $item->comment;
      $node->body = $item->comment;
      $node->title = $item->subject;
      $node->created = $item->timestamp;
      $node->changed = $item->timestamp;
      $node->status = 1;
      $node->moderate = 0;

      node_save($node);
  }

#14

System Message - July 15, 2009 - 07:20
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.