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.
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.
Comment | File | Size | Author |
---|---|---|---|
#6 | forum_update.patch.txt | 648 bytes | killes@www.drop.org |
Comments
Comment #1
pwolanin CreditAttribution: pwolanin commentedtrying to make the title more accurate: in fact the author does get changed, but other things break as described above.
Comment #2
pwolanin CreditAttribution: pwolanin commentedAlso, 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:
Comment #3
pwolanin CreditAttribution: pwolanin commentedOk, 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.
Comment #4
pwolanin CreditAttribution: pwolanin commentedAfter 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?
Comment #5
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedThe 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.
Comment #6
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedhere's a patch that needs testing.
Comment #7
pwolanin CreditAttribution: pwolanin commentedOk, 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.
Comment #8
pwolanin CreditAttribution: pwolanin commentedThe 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:
However, the correct schema (from 4.7.0 or 4.7.1) is:
Comment #9
drummI can't reproduce the error using the instructions in #1.
Comment #10
pwolanin CreditAttribution: pwolanin commented@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.
Comment #11
drummTested and committed to HEAD.
Comment #12
(not verified) CreditAttribution: commented