In the drupal 6 porting issue I wrote this:

...the forums listing shows the wrong time for the last post in that forum (but the stuff inside is correct and so is the comment time...), but that can probably be ignored.

This is much more serious than I thought and also happens on Drupal5.

What really happens:

1. Topics are imported with correct timestamp.
2. Forum orders topics correctly, but (I think) the forum main page will give wrong time for last post - even though in the details it is correct.
3. comments import properly, giving the last post time correctly too. This actually re orders the topics putting them in the correct place.
4. Those topics without comments are not reordered - they stay at the top.

In short the final ordering is:

1. Sticky topics
2. topics with zero comments, ordered by reverse creation date.
3. Topics with posts ordered by reverse creation date.

I think the problem is that node_save sets the timestamp as of the time for when the import of that node occurs. It will need to be over ridden.

Comments

naheemsays’s picture

http://drupal.org/node/172904 has got a fix for after the horse has bolted (a query to type into phpmyadmin to fix everything).

The proper solutions that I can think of atm are:

1. Get a new function phpbb2drupal_node_save, which is a simplified version of node_save and will use the correct changed time. Pretty simple and we already do this for poll_save and comment_save.
2. Get a patch into core where changed time is only set as current if there is no changed time already set - but this may not get in as it affects all node updates, but is only useful in special cases such as node import.
3. Add a hack to replace the changed time in the database after the node has been saved.

I will go with one, add a patch to the issue queue for 2 and let others decide wether it should go in or not.

naheemsays’s picture

Seems like I got ahead of myself. $node->changed does not seem to be the problem.

naheemsays’s picture

Status: Active » Fixed

Option 3 works. Adding the following code in a couple of places (once for topics, once for polls) fixes things:

	//hack to keep the topics in correct order
	db_query('UPDATE {node_comment_statistics} SET last_comment_timestamp = %d WHERE nid = %d', $node->created, $node->nid);

($node->changed IS the problem, but this fix works...)

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

Fogg’s picture

I still had this issue with the latest release of the module for phpbb2.

I fixed it by downloading the creation time from the phpbb tables and uploading them manually to the drupal table. Here is what I have done.

select drupal_phpbb2drupal_temp_topic.nid, min(bbposts.post_time), bbtopics.topic_views from bbposts, drupal_phpbb2drupal_temp_topic, bbtopics WHERE bbtopics.topic_id = bbposts.topic_id AND bbposts.topic_id = drupal_phpbb2drupal_temp_topic.topic_id group by bbposts.topic_id

Download this output to local disk, then reformat it so that every line looks like this

update drupal_node set created=1270132414 where nid=16915;

I did that using OpenOffice, but Excel will do the same trick.

I know that the whole part would be possible in one query, but my SQL knowledge is probably not advanced enough ;)

Now all node have the proper creation date, but still the sorting does not work, as it sorts on last comment and there is no comment. So we will fake this by copying the values from node to node statistics using this query:

update drupal_node_comment_statistics,drupal_node, drupal_users set last_comment_name = drupal_users.name, last_comment_uid = drupal_node.uid, last_comment_timestamp = drupal_node.created where drupal_node_comment_statistics.nid = drupal_node.nid and drupal_node.uid = drupal_users.uid;

Et voilà, now my sorting is just fine ;)

Fogg’s picture

Hmm, was not completly correct. The last query will update all records and therefor remove the so far correct entries if there where comments already.

This can be fixed again with this query:

update drupal_node_comment_statistics stat inner join drupal_comments c on stat.nid = c.nid set last_comment_uid = c.uid, last_comment_timestamp = timestamp;