Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
general-topic
Import issue - reorder id by date
Avatar
Chris Smith
Member
Free Members
sp_UserOfflineSmall Offline
Jan 26, 2013 - 3:15 pm

I have recently done an import of a vbulletin forum into simple:press. Everything seems to be working except that the the order of the topics seems to be incorrect. It gives the most recent topic being one that is 2 months old, and there are many others that are newer. I have figured out the reason this occurs is because in the import the post_ids are not necessarily in order of date. This is not a problem for most things except for in the sp-list-topic-class.php file the order of the topics is determined by the following code:

$spdb->orderby    = SFTOPICS.'.post_id DESC';

I was wondering if there was a way to instead have the order be determined by the post_date information in the SFPOSTS table? If not is their a way to reorder the posts in order to get their ids to be sequential? Thanks.

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Jan 26, 2013 - 3:28 pm

you should be be able to hook into our filter on the query and change the orderby... beware that ordering by date may be a significant performance penalty... mysql just isnt set up to handle that efficiently... where as ordering by the ID (which is the same as the date in simple press) is quite efficient in mysql...

do you understand filters?

for the code you posted, a few lines lower is a filter on the $spdb object... you can just change the orderby element and return the object to sort how you like...

Avatar
Chris Smith
Member
Free Members
sp_UserOfflineSmall Offline
Jan 26, 2013 - 3:47 pm

Thanks for your response. I tried to do that by adding SFPOSTS.post_date to the fields and have:

$spdb->orderby = SFPOSTS.' post_date DESC';

but it didn't work. It kept saying it was an invalid database query.

I agree that it would be better to have it done by id. Is there a way to redo the ids of the posts table (and subsequently the topic table) so that the ids are in the same order as the date?

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Jan 26, 2013 - 5:36 pm

can you post the code you used?

you would want something like the following in your spFunctions.php file...

add_filter('sph_topicview_query', 'my_topic_query', 2);
function my_topic_query($spdb, $obj) {
    $spdb->orderby = 'post_pinned DESC, '.spdb_zone_datetime('post_date').' DESC';
    return $spdb;
}

now, I have not tried this...

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Jan 27, 2013 - 4:07 am

You shouldn't need to wrap it in the spdb_zone_datetime() function as the ordering will still be the same whether it is manipulated for local time zone or not. May as well save the extra overhead.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Jan 27, 2013 - 11:30 am

ah, good point...

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online: Maria Sarkar
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 619
Members: 17362
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10127
Posts: 79625