From ebe67a14baa52f96f82c01a6e9671e43cbd76990 Mon Sep 17 00:00:00 2001 From: webchick Date: Thu, 11 Oct 2012 15:00:18 -0700 Subject: Issue #1592962 by mikeryan: Fixed Notice generated when programmatically creating a forum node. --- modules/forum/forum.module | 10 ++++++---- modules/forum/forum.test | 8 ++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'modules/forum') diff --git a/modules/forum/forum.module b/modules/forum/forum.module index 80832331b..fe0ef7920 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -330,10 +330,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 d78d962de..6937c623d 100644 --- a/modules/forum/forum.test +++ b/modules/forum/forum.test @@ -197,6 +197,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); } /** -- cgit v1.2.3