Hello,
I am trying to insert some forum nodes for a job board through mysql/php. I have ran the following 4 queries:


$query1 = "INSERT INTO `node_revisions` ( `nid` , `vid` , `uid` , `title` , `body` , `teaser` , `log` , `timestamp` , `format` )
VALUES ('$id', '$id', '358', '$title', '$html', '$html', '', '$t', '3')";
mysql_query($query1) or DIE("node revision insert failed");

$query2 ="INSERT INTO `node` ( `nid` , `vid` , `type` , `title` , `uid` , `status` , `created` , `changed` , `comment` , `promote` , `moderate` , `sticky` )
VALUES ('$id', '$id', 'forum', '$title', '1', '1', '$t', '$t', '2', '0', '0', '0')";
mysql_query($query2) or DIE("node insert failed");

$query3 ="INSERT INTO `node_access` ( `nid` , `gid` , `realm` , `grant_view` , `grant_update` , `grant_delete` )
VALUES ('$id', '0', 'tac_lite', '1', '0', '0')";
mysql_query($query3) or DIE("node access insert failed");

$query4="INSERT INTO `forum` ( `nid` , `vid` , `tid` )
VALUES ('$id', '$id', '$tid')";
mysql_query($query4) or DIE("forum insert failed");

All goes well, and looks identical (except for NID/VID to a forum node inserted through the gui. However, only the gui version is displayed. Why is this? I can view/edit the node as usual through admin/content or node/($id). I must be missing some kind of hook or database modification?!

Thanks for any help.

Comments

bdanchilla’s picture

<item>
<title>test</title>
<link>http://localhost/?q=node/84</link>
<description>test</description>
<comments>http://localhost/?q=node/84#comment</comments>
<category domain="http://localhost/?q=taxonomy/term/70">Teaching</category>
<pubDate>Fri, 19 May 2006 14:56:47 -0500</pubDate>
<dc:creator>admin</dc:creator>
<guid isPermaLink="false">84 at http://localhost</guid>
</item>
-
	<item>
<title>whereDo</title>
<link>http://localhost/?q=node/83</link>
<description><p>whereDO</p>
</description>
<comments>http://localhost/?q=node/83#comment</comments>
<category domain="http://localhost/?q=taxonomy/term/70">Teaching</category>
<pubDate>Fri, 19 May 2006 15:00:34 -0500</pubDate>
<dc:creator>admin</dc:creator>
<guid isPermaLink="false">83 at http://localhost</guid>
</item>
</channel>


Both are visible at http://localhost/?q=taxonomy/term/70, but when I click on http://localhost/?q=forum/70, only the second version is shown.

bdanchilla’s picture

as i have posted on http://drupal.org/node/64691,

thanks for everyone who helped steer me in the right direction. In the end, I needed to call node_save,
forum_insert and taxonomy_node_save

$node = new StdClass();
$node->title = 'test insertion';
$node->uid = 1;
$node->comment = 2;
$node->type = 'forum';
$node->body = 'sample body content';
$node->teaser = 'sample teaser';
$node->format = 3;
$node->tid = 70;
$node->status = 1;

node_save($node);
forum_insert($node);
$terms[] = $node->tid;
taxonomy_node_save($node->nid, $terms);

**And for newer drupal users like myself, you need to call the module functions from within a drupal node. Otherwise, you need to include a bunch of files

bdanchilla’s picture

I was given the advice, that I can replace

node_save($node);
forum_insert($node);
$terms[] = $node->tid;
taxonomy_node_save($node->nid, $terms);

with

$node->taxonomy[] = $node->tid;
node_save($node);

since node_save calls forum_insert and taxonomy_node_save

I've tested this and it works!

vasdee’s picture

This is perfect timing, i was just about to start banging my head against the wall when i stumbled onto this.

Cheers for the follow up as well :)

coupet’s picture

API Reference node_save
http://api.drupal.org/api/HEAD/function/node_save

----
Darly