private messages import later causes key violations
PMunn - November 8, 2006 - 14:49
| Project: | phpBB2Drupal |
| Version: | HEAD |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | PMunn |
| Status: | closed |
Description
I haven't dug deeper into this yet, but it seems that the phpbb2drupal porting of private messages leaves the key or internal Drupal sequence for the privatemsg table in a state that causes key violations when some users write new messages.
I sent a private message to a user, and when he attempted to submit his response he got a key violation.
pg_query() [function.pg-query]: Query failed: ERROR: duplicate key violates unique constraint "privatemsg_pkey" in /www/drupal/live-4.7.4/includes/database.pgsql.inc on line 94.Here is the query, with data cut short and the IP address replaced to protect the innocent.
query: INSERT INTO privatemsg (author, recipient, subject, message, timestamp, newmsg, hostname, format) VALUES ('3', '2', 'subject goes here', 'body goes here', '1162925246', '1', 'ip.address.goes.here', '0') in /www/drupal/live-4.7.4/includes/database.pgsql.inc on line 113.
#1
The module was writing in the private message's IDs in the phpBB database table and writing them directly into the privatemsg table without updating the sequence (in PostgreSQL).
This patch uses the ID-fetching call recommended by the How to write database-independent code article in the dev handbook.
I ran it on my dev environment successfully, importing my phpBB database (along with this thread-sorting patch) and then separated out the small fix from the other fixes.
Line 958 is where the only change is, which is the call to db_next_id:
$result = db_query ($query, db_next_id('{privatemsg}_id'), $from, $to, substr($pm->privmsgs_subject,0,64), $pm->privmsgs_text, $pm->privmsgs_date, $pm->newmsg, substr($pm->privmsgs_ip,0,255), $format);#2
Thanks for the detailed description. I committed this patch.
The privatemsg.module does not use the {sequence} table, itself but relies on the mysql AUTO_INCREMENT function:
http://drupal.org/node/98280
http://cvs.drupal.org/viewcvs/drupal/contributions/modules/privatemsg/pr...
Are you sure that it works with postgresql this way?
#3
Yes. I have a 4.7.4 development environment with the phpbb2drupal configured and ready-to-execute, and a corresponding phpBB2 database to pull from, both backed up from PostgreSQL, the only database I run. I have a bash script that restores them and lets me re-test changes.
I ran the conversion with the patch, checked the IDs and the sequence, and it worked.
#4
ok. Thanks for the feedback.
I am away this week end. I'll check your other patch early next week.
#5