summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2012-10-11 22:00:18 (GMT)
committer webchick2012-10-11 22:00:18 (GMT)
commitebe67a14baa52f96f82c01a6e9671e43cbd76990 (patch)
treef59c665e32253d037ad5a9b9924d1b76064e5951
parentbab96265a7a5c25510ac9b217b21a5b27687125c (diff)
Issue #1592962 by mikeryan: Fixed Notice generated when programmatically creating a forum node.
-rw-r--r--modules/forum/forum.module10
-rw-r--r--modules/forum/forum.test8
2 files changed, 14 insertions, 4 deletions
diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index 8083233..fe0ef79 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 d78d962..6937c62 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);
}
/**