Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
notice-when-saving-forum-entry.patch | 475 bytes | gumanist | |
Comments
Comment #1
mikeryanI'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.
Comment #2
mikeryanIt's not worth hacking Migrate to fix a cosmetic core bug...