When saving forum module entries getting a messages

Undefined property: stdClass::$nid File /var/www/modules/forum/forum.module, line 332(file: /var/www/modules/forum/forum.module, line 332)

This caused by this part in forum module:

    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);
      }
    }

to avoid this we just need have nid property defined. Thi will not cause problems with core, sinse drupal_write_record() verifies NULL properties for fields, which have 'not null' flag.

CommentFileSizeAuthor
notice-when-saving-forum-entry.patch475 bytesgumanist
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikeryan’s picture

Priority: Normal » Minor
Status: Needs review » Needs work

I've reported this as a core bug: #1592962: (tests followup) Notice generated when programmatically creating a forum node.

I'm a little wary of such a global response to such a narrow bug - depending on how other code (hooks, migration plugins, ...) checks the presence of $node->nid (empty/isset/is_null) this may have unwanted effects elsewhere.

mikeryan’s picture

Status: Needs work » Closed (won't fix)

It's not worth hacking Migrate to fix a cosmetic core bug...