This is related to another unanswered post of mine http://drupal.org/node/64520.

Basically what is the way to add a node directly to the database so that it shows up in a forum?
I have inserted/altered data in the node, node_revisions, node_access, forum, and sequences tables.
The node displays properly if I directly access it but is not shown in the table. Why is this?

How do I hook the node to a table? Am I missing changing one of the tables?

Comments

pwolanin’s picture

The forums depend on taxonomy, so I'd think that to plug it directly into the database you also need to put the right entries in the taxonomy tables.

---
Work: BioRAFT

bdanchilla’s picture

do you know of any other table that would need to be updated?

pwolanin’s picture

Not off hand, but if you look at the code in forum.module, it should all be layed out there in hook_insert(), etc. A quick perusal sugggests that you're covering all the tables. Do you have any access control module enabled?

---
Work: BioRAFT

bdanchilla’s picture

I am using taxonomy lite access on one of my sites, and another site has none. The one with taxonomy lite I modified the node_access table to have realm=tac_lite.

Heine’s picture

Is there a specific reason you want to work directly on the database? If not, you'll find it much easier to first build a node object, then save it to the database with a call to node_save. This will automatically call modules that need to save extra information about the node.

--
When your problem is solved, please post a follow-up to the thread you started.

nevets’s picture

If you are using code to add to the database the better way is to construct a node in code and then call node_save(). That way has long as you provide the correct information things get added to the tables correctly and any sequence numbers are also updated. If the details change on what node_save() does your code keeps working.

bdanchilla’s picture

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

Heine’s picture

node_save should call forum_insert & taxonomy_node_save automatcally, via hook_insert and hook_nodeapi respectively. You may need to fill $node->taxonomy though for that to work.
--
When your problem is solved, please post a follow-up to the thread you started.

bdanchilla’s picture

node_save alone does not work. what values are stored in $node->taxonomy?

nevets’s picture

$node->taxonomy is an array of taxonomy term id's (tids) so you set it like this

$edit->taxonomy[] = $tid;

where $tid is the term id you want associated with the node. In your case it would also be the forum id.

bdanchilla’s picture

that was the field I was missing to get the nodes to be visible calling only node_save() .
Thanks!