running Drupal 4.7.00, mySQL 4.0.25, PHP 4.3.

If I submit a forum post, and then edit it and change the author, I get the following type of error message:

user warning: Duplicate entry '249' for key 1 query: INSERT INTO forum (nid, vid, tid) VALUES (249, 677, 37) in /home/prince/public_html/includes/database.mysql.inc on line 120.

I get the same type of error then if I try to revert the post back to the original.

What's worse (and why I labeled this critical) the forum posting no longer shows up in the forum, but it does show up in the "active forum topics" block.

CommentFileSizeAuthor
#6 forum_update.patch.txt648 byteskilles@www.drop.org
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pwolanin’s picture

Title: Cannot change author of forum post » Changing author of forum post causes database errors

trying to make the title more accurate: in fact the author does get changed, but other things break as described above.

pwolanin’s picture

Also, this database error may be the casue (or one of the causes) of the PHP error described here: http://drupal.org/node/63392

Since changing the author on two forum posts, I'm getting much more frequent errors in the log during cron runs:

Invalid argument supplied for foreach() in /home/prince/public_html/modules/taxonomy.module on line 1199.
pwolanin’s picture

Ok, I think this may be a problem with the structure of the forum table. In the forum table 'nid' is set as the PRIMARY. In contrast, in the book table, 'vid' is set as PRIMARY, and I think this should be true for the forum table as well. OR, altrernatively, forum_update() and forum_load() need to be changed.

With the current version of it doesn't look as though revisions are properly handled either in this sense: In the book table, the information about nid, vid, and parent is stored. So if I reverted to a certain vid, I'd also recover the parent that was set at that revision. With forum module, if you changed the forum assignment of a post that would not be recovered currently. However, I'm guessing this is a broader problem/feature with taxonomy.

pwolanin’s picture

After looking at the code some more, I'm at a loss to see why there needs to be a forum table at all? All the information is already present in the term_node table. Did there used to be more in the forum table? Are there other modules that add to this table?

killes@www.drop.org’s picture

The table is there to keep track of moved topics.

I don't understand the code in forum_update:

function forum_update($node) {
if ($node->is_new || $node->revision) {
db_query("INSERT INTO {forum} (nid, vid, tid) VALUES (%d, %d, %d)", $node->nid, $node->vid, $node->tid);
}
else {
db_query('UPDATE {forum} SET tid = %d WHERE vid = %d', $node->tid, $node->vid);
}
}

Why does it make an insert if the node is new? forum_insert already does this.

killes@www.drop.org’s picture

Status: Active » Needs review
FileSize
648 bytes

here's a patch that needs testing.

pwolanin’s picture

Ok, will test and try to make my own patch, but I think this needs a schema change, since I'm seeing the errros on updates, not new nodes.

pwolanin’s picture

Title: Changing author of forum post causes database errors » Unused case in forum_update()
Priority: Critical » Minor

The patch seems to work fine (obviously, since this hook is never called on insertion of a new node). I tested it with mySQl 4.025, PHP Version 4.4.2.

However, in comparing the book and forum module code to the API example code:

http://api.drupal.org/api/4.7/function/node_example_update

I'm wondering why they don't just call hook_insert() from hook_update() if $node->revision is true?

Also, sorry about posting the rest as an issue. Not solving the SQL error part of this sooner is just a mark of my own ignorance. We started building our site using 4.7beta1, and at some point we must have missed an update and our forum table had the wrong structure.

The dump of the structure of the forum table we were using is:


--
-- Table structure for table `forum`
--

DROP TABLE IF EXISTS forum;
CREATE TABLE forum (
  nid int(10) unsigned NOT NULL default '0',
  vid int(10) unsigned NOT NULL default '0',
  tid int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (nid),
  KEY vid (vid),
  KEY tid (tid)
) TYPE=MyISAM;

However, the correct schema (from 4.7.0 or 4.7.1) is:

--
-- Table structure for table 'forum'
--

CREATE TABLE forum (
  nid int(10) unsigned NOT NULL default '0',
  vid int(10) unsigned NOT NULL default '0',
  tid int(10) unsigned NOT NULL default '0',
  PRIMARY KEY (vid),
  KEY nid (nid),
  KEY tid (tid)
);
drumm’s picture

Category: bug » support
Status: Needs review » Closed (won't fix)

I can't reproduce the error using the instructions in #1.

pwolanin’s picture

Category: support » bug
Status: Closed (won't fix) » Needs review

@drumm- See the patch above http://drupal.org/node/65024#comment-102588

Maybe I should have posted a new issue. The instructions at the top should be ignored- my database schema missed a step somewhere between 4.7beta and 4.7.0, but there is still an issue with some stray code in forum.module.

drumm’s picture

Status: Needs review » Fixed

Tested and committed to HEAD.

Anonymous’s picture

Status: Fixed » Closed (fixed)