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

Reply
 
Thread Tools Display Modes
  #1  
Old 09-10-2007, 06:49 AM
Newtonhead1 Newtonhead1 is offline
 
Join Date: Apr 2007
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Query to split thread by post date

Greetings everyone,

I manage several mid sized forums with established threads that need to be regularly split to keep them to manageable size. Manually selecting hundreds of posts to be move is a time consuming job, so I'm looking to speed up the process.

I would sincerely appreciate if someone could provide a mysql query that would allow me to move posts from one thread to another by post date range.

In other words, I would like to run a query wherein I would enter the source and target thread id's and a start and end date range for the posts to be moved.

FYI, In case it makes a difference, I'm currently in vb 3.0.6, although I'm planning the upgrade to the latest version as soon as we finish documenting all of our telpmate mods.

Thanks,

Newtonhead1
Reply With Quote
  #2  
Old 09-11-2007, 04:25 AM
Eikinskjaldi's Avatar
Eikinskjaldi Eikinskjaldi is offline
 
Join Date: Feb 2006
Location: Hell, never looked better
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, well lets assume you have start_date and end_date in sql format, for example

start_date = '2007-08-07'

the query would then be

update post set threadid=new_thread_id where threadid=old_thread_id
and dateline between (unix_timestamp(start_date), unix_timestamp(end_date))

Of course, given that the thread table has all sorts of co-dependencies related to lastpost and first post, I have absolutely no idea how the posts will view in the new thread.

If I was going to do this, and first I'd have to wrap my head around the concept of a thread needing to be of manageable size, I'd be doing it in code with the data managers.

EDIT: I am going off 3.5+ database structure. I have no idea if 3.0.x has the same tables and or fields.
Reply With Quote
  #3  
Old 09-11-2007, 06:08 AM
Newtonhead1 Newtonhead1 is offline
 
Join Date: Apr 2007
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Eikinskjaldi,

I sincerely appreciate your input. Due to my obvious concern to get the syntax of the query exactly correct, would the following be in correct format?

update post set threadid=NEW thread id where threadid=OLD thread id and dateline between (unix_timestamp(start_date), unix_timestamp(end_date))

Sample:

update post set threadid=123456 where threadid=654321 and dateline between (unix_timestamp(2006-01-01), unix_timestamp(2006-12-31))

Am I missing any apostrophes or commas in the above? For example...

update post set threadid='123456' where threadid='654321' and dateline between (unix_timestamp('2006-01-01'), unix_timestamp('2006-12-31'))

Am I missing any formatting requirements, especially in the date formats?

FYI, I am planning to test this on a test forum before I run it on my production forum.

Thanks,

Newtonhead1
Reply With Quote
  #4  
Old 09-11-2007, 10:16 AM
Eikinskjaldi's Avatar
Eikinskjaldi Eikinskjaldi is offline
 
Join Date: Feb 2006
Location: Hell, never looked better
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

THis is correct

Quote:
Originally Posted by Newtonhead1 View Post

update post set threadid=123456 where threadid=654321 and dateline between (unix_timestamp('2006-01-01'), unix_timestamp('2006-12-31'))

assuming new threadid is 123456 and old thread id is 654321
Reply With Quote
  #5  
Old 09-13-2007, 03:47 AM
Newtonhead1 Newtonhead1 is offline
 
Join Date: Apr 2007
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Eikinskjaldi,

Of course, I have updated my example query.

update post set threadid=NEW thread id where threadid=OLD thread id and dateline between (unix_timestamp('start_date'), unix_timestamp('end_date'))

Thanks,

Newtonhead1
Reply With Quote
  #6  
Old 09-13-2007, 09:25 PM
Eikinskjaldi's Avatar
Eikinskjaldi Eikinskjaldi is offline
 
Join Date: Feb 2006
Location: Hell, never looked better
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Right, except the dates are quoted, as per y previous post.
Reply With Quote
  #7  
Old 09-17-2007, 05:19 PM
Newtonhead1 Newtonhead1 is offline
 
Join Date: Apr 2007
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Greetings everyone,

I ran the following query:

update post set threadid=5355 where threadid=3558 and dateline between (unix_timestamp('2006-01-01'), unix_timestamp('2006-01-31'))

Upon which vB returned the following error:

error number: 1064
error desc: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Any ideas as to what's not correct in the query?

Thanks,

Newntonhead1
Reply With Quote
  #8  
Old 09-20-2007, 11:39 PM
Eikinskjaldi's Avatar
Eikinskjaldi Eikinskjaldi is offline
 
Join Date: Feb 2006
Location: Hell, never looked better
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Newtonhead1 View Post
Greetings everyone,

I ran the following query:

update post set threadid=5355 where threadid=3558 and dateline between (unix_timestamp('2006-01-01'), unix_timestamp('2006-01-31'))

Upon which vB returned the following error:

error number: 1064
error desc: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Any ideas as to what's not correct in the query?

Thanks,

Newntonhead1
Sorry, my bad. The correct syntax is
update post set threadid=5355 where threadid=3558 and dateline between unix_timestamp('2006-01-01') AND unix_timestamp('2006-01-31')
Reply With Quote
  #9  
Old 10-01-2007, 03:05 AM
Newtonhead1 Newtonhead1 is offline
 
Join Date: Apr 2007
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Greetings Everyone,

Eikinskjaldi, the revised query worked perfectly and has saved me dozens of hours. Many thanks.

FYI: After running the script I obviously needed to update thread info to tighten up several dependencies.

Okay, now I've got to ask for one further modification. Can anyone please provide the modifications to the script that will only change the thread ID on posts that DO NOT have a file attachment?

Just so everybody doesn't think I'm crazy, the reason I need this is because my forum has a number of Photo Gallery threads wherein members post numerous comments about the photos, and thus I get a lot of complaints that said Photo Gallery threads are being diluted with the non-photo posts. The easiest solution is to periodically move all the comments (posts without attachments) to a "Photo Gallery Comments" thread.

Thanks,

NewtonHead
Reply With Quote
  #10  
Old 10-01-2007, 07:54 AM
Eikinskjaldi's Avatar
Eikinskjaldi Eikinskjaldi is offline
 
Join Date: Feb 2006
Location: Hell, never looked better
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think posts with attachments have the attach field of the post table set to the number of attachments

update post set threadid=5355 where threadid=3558 and attach=0 and dateline between unix_timestamp('2006-01-01') AND unix_timestamp('2006-01-31')

Note that that attach field is not indexed, so the query is not optimised. Perhaps you should consider indexing it.
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 11:39 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04304 seconds
  • Memory Usage 2,256KB
  • 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
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete