Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 10-05-2016, 08:54 AM
Zylantex Zylantex is offline
 
Join Date: Sep 2009
Location: France
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Rebuild Thread and Forum Tables from Post Table

I am trying to migrate from phpBB 3.1.9 to vBulletin and the process has been somewhat successful. I first migrated to vB 3.8.9 then upgraded to vB 4.2.2
However there are outstanding issues that I am sure others have encountered and overcome and I would be grateful for any help you can offer.

My primary concern is that all threads are lacking dates. Naturally this means the latest posts in forums are also dateless with the result that all forums show no recent content. Zero dates all show as 31 Dec 1969 11:00pm. If I expand the forum search to show threads from the beginning all threads show up. Albeit with the wrong date and wrong number of replies/views. The number of post per page parameter is also being ignored but that might resolve itself if the previously mentioned issues are fixed.

The good news every post has a date and valid thread so it must be possible to rebuild the thread and forum information from them.

I have almost zero SQL experience so the chances of me re-writing the tables without help is almost nil.

I have tried to step through the post table and rewrite the thread table but without knowledge of how to use indexes properly I'm picking up the wrong values.

Basically what is required is a block of code to rewrite chunks of the thread and forum tables from the post table. Does an utility such as this exist already?
How such an glaring gap in data could have arisen is beyond me!

The concerned fields in the tables are as follows:

Table: post
Field: postid - contains valid data
Field: threadid - contains valid data
Field: username : contains valid data
Field: userid - contains valid data
Field: dateline - contains valid data

Table: thread
Field: firstpostid - all zeroes
Field: lastpostid - all zeroes
Field: lastpost - all zeroes - should be a date I believe
Field: forumid - contains valid data
Field: dateline - contains valid data

Table: forum
Field: lastpost - all zeroes
Field: lastpostid - all zeroes
Field: lastthreadid - contains valid data
Field: lastposter - all zeroes
Field: lastposterid - all zeroes

Mod - I raised this issue in a zombie thread but I think it needs a thread of its own as the scope of the issues is more widespread than I previously thought.
Reply With Quote
  #2  
Old 10-05-2016, 10:52 AM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try the following. (Best to try on a backup first to make sure it works well)

Update firstpostid in thread:
PHP Code:
UPDATE thread SET firstpostid = (SELECT postid FROM post WHERE threadid thread.threadid ORDER BY postid ASC LIMIT 0,1
Update lastpostid in thread:
PHP Code:
UPDATE thread SET firstpostid = (SELECT postid FROM post WHERE threadid thread.threadid ORDER BY postid DESCLIMIT 0,1
Update date in thread:
PHP Code:
UPDATE thread SET lastpost = (SELECT dateline FROM post WHERE threadid thread.threadid ORDER BY postid DESC LIMIT 0,1
Update lastpost in forum:
PHP Code:
UPDATE forum SET lastpost = (SELECT b.dateline FROM thread AS a INNER JOIN post AS b ON a.threadid b.threadid WHERE a.forumid forum.forumid ORDER BY b.postid DESC LIMIT 0,1
Update lastpostid in forum:
PHP Code:
UPDATE forum SET lastpostid = (SELECT b.postid FROM thread AS a INNER JOIN post AS b ON a.threadid b.threadid WHERE a.forumid forum.forumid ORDER BY b.postid DESC LIMIT 0,1
Update lastposter in forum:
PHP Code:
UPDATE forum SET lastposter = (SELECT b.username FROM thread AS a INNER JOIN post AS b ON a.threadid b.threadid WHERE a.forumid forum.forumid ORDER BY b.postid DESC LIMIT 0,1
Update lastposterid in forum:
PHP Code:
UPDATE forum SET lastposterid = (SELECT b.userid FROM thread AS a INNER JOIN post AS b ON a.threadid b.threadid WHERE a.forumid forum.forumid ORDER BY b.postid DESC LIMIT 0,1
Reply With Quote
Благодарность от:
RichieBoy67
  #3  
Old 10-05-2016, 11:44 AM
Zylantex Zylantex is offline
 
Join Date: Sep 2009
Location: France
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Dave,

That is amazing. I'm genuinely overwhelmed at your kindness. Thank you.

--------------- Added [DATE]1475677791[/DATE] at [TIME]1475677791[/TIME] ---------------

I added a little, I'm just putting it all together here in case it's useful to anyone else.

Code:
These all work perfectly - DO NOT EDIT

UPDATE thread SET firstpostid = (SELECT postid FROM post WHERE threadid = thread.threadid ORDER BY postid ASC LIMIT 0,1)  

UPDATE thread SET lastpostid = (SELECT postid FROM post WHERE threadid = thread.threadid ORDER BY postid DESC LIMIT 0,1) 

UPDATE thread SET lastpost = (SELECT dateline FROM post WHERE threadid = thread.threadid ORDER BY postid DESC LIMIT 0,1) 

UPDATE thread SET lastposterid = (SELECT userid FROM post WHERE threadid = thread.threadid ORDER BY postid DESC LIMIT 0,1) 

UPDATE thread SET lastposter = (SELECT postusername FROM post WHERE threadid = thread.threadid ORDER BY postid DESC LIMIT 0,1)

UPDATE thread SET replycount = ((SELECT COUNT(threadid) AS count FROM post WHERE threadid = thread.threadid ORDER BY postid ASC LIMIT 0,1) - 1 )

UPDATE forum SET lastpost = (SELECT b.dateline FROM thread AS a INNER JOIN post AS b ON a.threadid = b.threadid WHERE a.forumid = forum.forumid ORDER BY b.postid DESC LIMIT 0,1) 

UPDATE forum SET lastpostid = (SELECT b.postid FROM thread AS a INNER JOIN post AS b ON a.threadid = b.threadid WHERE a.forumid = forum.forumid ORDER BY b.postid DESC LIMIT 0,1) 

UPDATE forum SET lastpostid = (SELECT b.postid FROM thread AS a INNER JOIN post AS b ON a.threadid = b.threadid WHERE a.forumid = forum.forumid ORDER BY b.postid DESC LIMIT 0,1) 

UPDATE forum SET lastpostid = (SELECT b.postid FROM thread AS a INNER JOIN post AS b ON a.threadid = b.threadid WHERE a.forumid = forum.forumid ORDER BY b.postid DESC LIMIT 0,1)
I just need to find out how to reset the number of replies and I'm pretty much there.

I think the lack of number of replies is what is causing the "display number of posts per page" to fall over. Zero replies means no need to calculate pages.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:57 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.16450 seconds
  • Memory Usage 2,205KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (7)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (3)post_thanks_box
  • (1)post_thanks_box_bit
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete