When I import Private messages, I get more messages than were viewable in phpbb. This is a good thing. (Feature: find lost PM's!)

However, those messages that can be seen in phpbb have two entries for them after import to Drupal.

In short, a check is needed to make sure that duplicate entries are not saved.

Comments

naheemsays’s picture

Just had a good nose around and it seems It seems that phpbb saves each message twice - once for the recipient and once for the user. Privatemsg saves one message and has columns which show if either user has deleted it or not.

The rows for each duplicate message are consecutive, unless one of the users has deleted their copy.

Only way I can see to stop duplications is a comparison of where sender, recipient, timestamp AND body match for an already imported message. Any better ideas?

PS this bug will probably appear in all versions of the phpbb2drupal module that has a pm import feature.

naheemsays’s picture

Can someone help me with the sql statement for this? I think we do not need to match the body, just the authior, recipient and timestamp. What I have so far(not working):

$dupe = db_result(db_query('SELECT COUNT(*) from {privatemsg} WHERE author = %d AND (recipient = %d AND timestamp =%d)', $message->author, $message->recipient, $message->timestamp));
      if ($dupe > 0) {
      //do not import - it is a dupe
      }else{  
        $result = drupal_write_record('privatemsg', $message);
      }
naheemsays’s picture

Status: Active » Fixed

The following code works for drupal 6:

  //check for duplicate messages
  $dupe = db_result(db_query('SELECT COUNT(*) FROM {privatemsg} WHERE timestamp = %d AND (recipient = %d AND author = %d)', $pm->privmsgs_date, $to, $from));
  if (!($dupe >0)) {
    $result = drupal_write_record('privatemsg', $message);
}
naheemsays’s picture

Title: PM import issues (duplicate messages). » Do not import duplicate Private Messages
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.