The phpbb2drupal_comment_save function builds thread IDs in a dangerous way:

        // Next, we increase this value by one.  Note that we can't
        // use 1, 2, 3, ... 9, 10, 11 because we order by string and
        // 10 would be right after 1.  We use 1, 2, 3, ..., 9, 91,
        // 92, 93, ... instead.  Ugly but fast.

It's ugly in more ways than just looks.

The resulting forum cannot sort comments added to ported-over nodes properly. Here's the behavior:

A sample post has the following comment IDs generated by the module at transfer time:

1/
2/
3/
4/
5/
6/
7/
8/
9/
90/
91/
92/
93/
94/
95/
96/
97/
98/
99/
990/

I go to the post, hit reply on the post (not a comment below it), and that comment gets this ID:

191/

Of course in the string sort this lands between /1 and /2, the first two comments of the post. The comment module doesn't understand the numbering scheme. So much so that adding a second comment to the post gives it the SAME thread ID again, further mucking up sorting.

This module needs to be changed to either do it the slow and correct way and/or use the internal mechanism for adding comments. I've just diagnosed this problem on my own site and am going to cook up a custom script to reset comment thread IDs and then test it out before I take the time to troubleshoot this fiasco in the module.

How much slower would it have been to pad the number to become a 4-digit number with leading zeroes, and just increment that? The phpBB forum does not allow posts from posts the way Drupal allows comments on comments. It just allows posts on topics, so you should never really have to deal with dots in thread IDs when importing.

Comments

PMunn’s picture

A bit of research.

The comment.module (API page) uses int2vancode and vancode2int functions to generate the thread ID. I wonder if these would be available to this module.

PMunn’s picture

StatusFileSize
new8.67 KB

I managed to put together a class that regenerates the comment thread IDs using copies of the aforementioned vancode functions. It does this in two steps: regenerating thread IDs for comments from phpBB and then regenerating thread IDs for comments added in Drupal.

1. regenerate all thread IDs for comments with a blank name, sorted by thread ID. Comments from phpBB have a blank name. This includes recursively altering thread IDs for any comments (with name or not, but they will all have names) linked to this comment, replacing the first segment of the dotted thread ID (e.g. the first segment of "02.00" is "02").

Initially I didn't do this recursively but testing showed me how that was necessary. The "pid" of a comment row is the parent, and a comment parent can be comment of another parent.

Given that phpbb doesn't permit posts linked to posts, only posts linked to topics, all comments on comments in drupal have valid second or later segment IDs because the comment.module made them, not the phpbb2drupal module. This simplifies the process.

2. regenerate all thread IDs for comments with a nonblank name, sorting these by timestamp. This takes care of comments added after the phpbb conversion to drupal forum.

For fun, I'm attaching the script I used to do this job. Next I'll take a look at the module.

PMunn’s picture

Status: Active » Needs review
StatusFileSize
new2.26 KB

Here is a patch that uses the int2vancode and vancode2int functions in the comments module to correctly number the posts as they come in.

beginner’s picture

Status: Needs review » Active

Patch committed, thanks.

What script did you use to update your comments that had already been imported?
I noticed this problem in my forum, too, and others who've used the module before might need it, too.

PMunn’s picture

See the threadfixer.sample.php.txt posted above.

beginner’s picture

Status: Active » Fixed

Oh! thank you very much.

I made a note on the module home page, so that other users who have migrated before may find it, too.
Thanks a lot for your contributions.

Anonymous’s picture

Status: Fixed » Closed (fixed)
millerl’s picture

This is really amazing!

I've been plagued with this problem for months and months!

PMunn if you have a paypal account or something like it I would love to throw some money your way as a thanks, this is great!!!

I changed my DB type to mysql, entered my DB info and opened it in my browser... boom. No more problems!

AlexisWilke’s picture

There is a bug in Drupal Core related to that. That's where it should be fixed and not in sub-modules (although until Core fixes itself...)

http://drupal.org/node/122098#comment-3112214