I am creating a forum topic via rule, and it seems to be working with one problem. When you go to the root of the forum (ie. /forum), it shows that there is a new forum topic within the correct term. When I go into the specific term though (ie. /forum/5), none of the ones created by rule appear. I am able to load the forum topic without a problem by going to its URL. I have also found that if I go into one of topics that isn't appearing, click edit, and save (with or without making actual changes) that the forum topic will then appear in the topic list.

I had thought I had found an issue that the rule-created forum topics were getting an erroneous tid=0 in the term_node table. However, when I deleted those rows from the database, the topics still did not reappear. I've been searching but haven't come across what might be the cause for this issue.

Is it a bug or am I missing something else?

Comments

yowzer’s picture

Component: Rules Core » Rules Engine

This is definitely a bug. I finally found the data inconsistency that was causing it. If you use a rule to create a new forum topic, there is no new row entered into forum with nid, vid (node version id), and tid (term id). This is the solution I decided to use in my custom utility module.

/**
  * Implementation of hook_nodeapi()
  */
function sw_concepts_nodeapi(&$node, $op, $a3, $a4) {
  switch ($op) {
    case 'insert':
      if ($node->type == 'forum') {
         $containerID = taxonomy_get_term_by_name('Setting Concepts');
				
         db_query('INSERT INTO {forum} (tid, vid, nid) VALUES (%d, %d, %d)', 
            $containerID[0]->tid,
            $node->vid, 
            $node->nid
         );
			}
      break;
   }
}
fago’s picture

Status: Active » Closed (won't fix)

Probably forum module doesn't work correctly on programmatic node saves - not a rules bug though. :/

Cyrandir’s picture

Actually, a change to taxonomy.rules.inc will make this work.

Change this:

/**
 * Action: Assign or remove a term to content.
 */
function rules_action_taxonomy_term_assign_to_content($node, $taxonomy_term, $settings) {
  if (!isset($node->taxonomy[$taxonomy_term->tid])) {
    $node->taxonomy[$taxonomy_term->tid] = $taxonomy_term;
    return array('node' => $node);
  }
}

into this:

/**
 * Action: Assign or remove a term to content.
 */
function rules_action_taxonomy_term_assign_to_content($node, $taxonomy_term, $settings) {
  if (!isset($node->taxonomy[$taxonomy_term->tid])) {
    $node->taxonomy[$taxonomy_term->tid] = $taxonomy_term;
    foreach ($node->taxonomy as $term_id => $term) {
      $node->tid = $term_id;
    }
    return array('node' => $node);
  }
}

and it works for me. The $node->tid field wasn't getting set correctly. It's supposed to be getting set in forum.module, but apparently not working being passed around. This simple workaround fixes it. I have not tested it to see if it screws up other actions tho, I'm only really worried about getting the forum posts to work.

lastent’s picture

How do you assign the created forum topic to a certain forum?