diff --git a/modules/forum/forum.module b/modules/forum/forum.module index eddac79..7ef8aad 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -329,10 +329,12 @@ function forum_node_presave($node) { $langcode = key($node->taxonomy_forums); if (!empty($node->taxonomy_forums[$langcode])) { $node->forum_tid = $node->taxonomy_forums[$langcode][0]['tid']; - $old_tid = db_query_range("SELECT f.tid FROM {forum} f INNER JOIN {node} n ON f.vid = n.vid WHERE n.nid = :nid ORDER BY f.vid DESC", 0, 1, array(':nid' => $node->nid))->fetchField(); - if ($old_tid && isset($node->forum_tid) && ($node->forum_tid != $old_tid) && !empty($node->shadow)) { - // A shadow copy needs to be created. Retain new term and add old term. - $node->taxonomy_forums[$langcode][] = array('tid' => $old_tid); + if (isset($node->nid)) { + $old_tid = db_query_range("SELECT f.tid FROM {forum} f INNER JOIN {node} n ON f.vid = n.vid WHERE n.nid = :nid ORDER BY f.vid DESC", 0, 1, array(':nid' => $node->nid))->fetchField(); + if ($old_tid && isset($node->forum_tid) && ($node->forum_tid != $old_tid) && !empty($node->shadow)) { + // A shadow copy needs to be created. Retain new term and add old term. + $node->taxonomy_forums[$langcode][] = array('tid' => $old_tid); + } } } } diff --git a/modules/forum/forum.test b/modules/forum/forum.test index 612b09c..826c342 100644 --- a/modules/forum/forum.test +++ b/modules/forum/forum.test @@ -165,6 +165,14 @@ class ForumTestCase extends DrupalWebTestCase { $this->drupalGet('forum/' . $this->forum['tid']); $this->drupalPost("node/$node->nid/edit", array(), t('Save')); $this->assertResponse(200); + + // Make sure constructing a forum node programmatically produces no notices. + $node = new stdClass; + $node->type = 'forum'; + $node->title = 'Test forum notices'; + $node->uid = 1; + $node->taxonomy_forums[LANGUAGE_NONE][0]['tid'] = $this->root_forum['tid']; + node_save($node); } /**