Forums uses the last_modified attribute of the acs_object for the parent forums_message of a thread as the last posting date. When you migrate, all the objects are created on the same day. So we need to update the last_modified back to the last posting date.

This requires a little surgery in psql.

First drop the last_modified trigger or this trigger will modify your modification of last_modified.

drop trigger acs_objects_last_mod_update_tr on acs_objects;
Create a view to make the queries easier.
create view forums_objects as 
select o.object_id, o.last_modified, m.message_id, m.parent_id, m.posting_date from acs_objects o, forums_messages m 
where o.object_id=m.message_id;
And a rule so you can update it.
create rule forums_objects_upd as on update to forums_objects do instead
update acs_objects
set last_modified = new.last_modified
where object_id = new.object_id;
Update single message threads
update forums_objects set last_modified = posting_date where parent_id is null;     
I haven;t figured out a faster one for this yet:
update acs_objects set last_modified = 
(select max(posting_date) from forums_messages where parent_id=object_id) 
where object_id in (select distinct parent_id from forums_messages);
Update the last posting date for the forums_forum object:
update acs_objects set last_modified = 
(select max(posting_date) from forums_messages where forum_id=object_id) 
where object_id in (select distinct forum_id from forums_messages);
You should then add the trigger back
create trigger acs_objects_last_mod_update_tr before update on acs_objects
for each row execute procedure acs_objects_last_mod_update_tr ();
---------- I am leaving this old stuff for historical purposes. Do Not use. --DaveB ---------- Next update all the multiple posting threads:
update acs_objects set last_modified = 
(select max(posting_date) from forums_messages where parent_id=object_id) 
where object_id in (select distinct parent_id from forums_messages);
Then update all the single posting threads. Parent_id is null is these messages. If you can think of a query that does it in one shot, let me know.
update acs_objects set last_modified = 
(select posting_date from forums_messages where message_id=object_id) 
where object_id in 
(select message_id from forums_messages where parent_id is null);
Update the last posting date for the forums_forum object:
openacs.org-dev=# update acs_objects set last_modified = 
(select max(posting_date) from forums_messages where forum_id=object_id) 
where object_id in (select distinct forum_id from forums_messages);
You should then add the trigger back
create trigger acs_objects_last_mod_update_tr before update on acs_objects
for each row execute procedure acs_objects_last_mod_update_tr ();