Here's just a little something to get us started:

/**
 * Implementation of hook_init()
 */
function example_init() {
  $results = db_query('SELECT * FROM {comments}');
  while ($result = db_fetch_object($results)) {
    $node = (object) array(
      'type' => 'comment',
      'title' => $result->subject,
      'teaser' => $result->subject,
      'body' => $result->comment,
      'uid' => $result->uid,
      'status' => 1,
      'created' => $result->timestamp,
      'changed' => $result->timestamp,
      'comment_target_nid' => $result->nid,
      'comment_target_cid' => $result->pid,
      'comment' => 0,
      'promote' => 0,
      'moderate' => 0,
      'sticky' => 0,
      'thread' => $result->thread,
      'name' => $result->name,
      'mail' => $result->mail,
      'homepage' => $result->homepage,      
    );
    
    node_save($node);
  
    // update hostname
    db_query("UPDATE {node_comments} SET hostname = '%s' WHERE cid = '%d' LIMIT 1;", $result->hostname, $node->nid);
  }
}

Comments

quicksketch’s picture

Status: Needs work » Closed (duplicate)

This will be fixed in the 2.x version of the module which works comment module. See #472886: Convert comments to nodecomments and viceversa when the type is changed.