title: costum module Convert Forum Topic to comment
body: <p>I need to develop one module that converts the 'Forum Topic' of the site, that is a content type, into one comment of another node of content type 'Action'. The Forum topic and the node 'action' have a taxonomy term in commun.
  So I start to searching the values that I need in the DB, from table 'node', 'user'... and after I made db_insert in the table 'comment'. </p>
  
  <pre><code>function mymodule_entry_insert($entry) {
      $select = db_select('node', 'n');
      $select-&gt;join('users','u','u.uid = n.uid');
  
  $select-&gt;fields('n', array('nid', 'title',  'created'));
  $select-&gt;fields('u', array('name'));
  
  
  $select-&gt;condition(db_or()-&gt;condition('n.type', 'forum', '='));
  
  // Return the result in object format.
  return $select-&gt;execute()-&gt;fetchAll();
  
  $fields = array(
  
  'nid' =&gt; $select-&gt;fields('n', array('nid')),
  'uid' =&gt; $select-&gt;fields('n', array('uid')), 
  'subject' =&gt; $select-&gt;fields('n', array('title')),
  'hostname' =&gt;'::1',
  'created' =&gt; $select-&gt;fields('n', array('created')),
  'changed' =&gt; $select-&gt;fields('n', array('created')),
  'status' =&gt; '1',
  'language' =&gt; 'und',
  'thread' =&gt; '01/',
  'name' =&gt; $select-&gt;fields('u', array('name')),
  'mail' =&gt; '',
  'homepage' =&gt; '',);
  
  try {
       $return_value = db_insert('comment')
      -&gt;fields($fields)
      -&gt;execute();
  
    }
  
  catch (Exception $e) {
  drupal_set_message(t('db_insert failed. Message = %message, query= %query',
  array('%message' =&gt; $e-&gt;getMessage(), '%query' =&gt; $e-&gt;query_string)), 'error');
  }
   return $return_value;
  }
  </code></pre>
  
  <p>After search during days in internet, I haven't found any solution for this that seems to be very easy. I don't have a huge experience.
  The second part of the module is to convert the comments of the ex-forum, to the children comments of the new coment that has been created. 
  So I must to group the comments by nid ('the node to wich this comment is a reply'), and all of them except one(the father, old forum ) must to insert the cid ('primary key') of their father comment in the column 'pid' (the comment cid to wich this comment is a reply)</p>
  
  <p>And the third part is to get the id of the node with same term that the forum, and change the nids of the comments affected.</p>
  
  <p>I hope that I will be able to develop the second and the third part , in the same way that the first one.</p>
  
  <p>Thank you :) </p>