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 |
Jump to:
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;
}
?>| Attachment | Size |
|---|---|
| nodecomment_upgrade.txt | 3.13 KB |

#1
Hi Robert,
You are referring to nodeforum. Do you have nodeforum working correctly?
Greetings,
Martijn
#2
Will this work with the recently uploaded nodeforum (tagged in cvs as 1.1)?
#3
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
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
you would temporarily put this into the nodecomment.install and run update.php to execute.
#6
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
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
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
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
subscribe
#11
subscribe
#12
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
$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
Automatically closed -- issue fixed for 2 weeks with no activity.