Log in

View Full Version : automating thread moves between forums


jsharper
07-20-2005, 05:01 AM
I need to create some sort of scheduled task or cron job to move all of the threads from one forum to another forum on a daily basis... any suggestions on the best way to approach it? custom sql queries? custom php code that uses vB functions?

vB 3.0.7

Thanks
Jason

Marco van Herwaarden
07-20-2005, 06:09 AM
Based on what rules these moves should be done?

jsharper
07-20-2005, 06:11 AM
I have forum A that is publically viewable. I have forum B that is only viewable by admins. at midnight every night, I need to move ALL threads in forum A to forum B. So, the only rule to identify threads to be moved is that forum=A

Marco van Herwaarden
07-20-2005, 06:21 AM
A relative easy cronjob should be able to do that. So you will have to write a short php-script that can perform the task.

Andreas
07-20-2005, 06:39 AM
<?php

error_reporting(E_ALL & ~E_NOTICE);

if (!is_object($DB_site))
{
exit;
}

$DB_site->query("UPDATE " . TABLE_PREFIX . "thread SET forumid = B WHERE forumid = A");

require_once('./includes/functions_databuild.php');
build_forum_counters(A);
build_forum_counters(B);

log_cron_action('Threads moved from Forum A to Forum B', $nextitem);

?>


Please note that this (very easy) Script will not bother updating users postcounts/titles.

jsharper
07-23-2005, 08:06 PM
Kirby, that was perfect -- Thanks! It worked great in my test site and will hopefully run on my prod site at midnight tonight.

Fortunately, Forum A has "Count Posts Made in this Forum Towards User Post Counts" set to No, so that works out well. This is basically our venting forum.. it allows users to say things they might not otherwise say, knowing that everything will get "purged" daily.

Thanks again.

aciurczak
09-28-2005, 01:38 AM
I think I'm looking for the same thing; the only difference is adding 1 parameter to see if the thread should be moved.

I'd like to move all threads in one forum with at least 1 reply (2 posts within thread) to be auto-moved to another forum.

Do I just need to add an "AND replycount >=1" clause?

UPDATE:

Working like a charm. If anyone needs the code, the bottom snippet moves all threads with replies from forum id #17 over to forum id #2. I have it running as a cron job once an hour.

<?php

error_reporting(E_ALL & ~E_NOTICE);

if (!is_object($DB_site))
{
exit;
}

$DB_site->query("UPDATE " . TABLE_PREFIX . "thread SET forumid = 2 WHERE forumid = 17 AND replycount >= 1");

require_once('./includes/functions_databuild.php');
build_forum_counters(2);
build_forum_counters(17);

log_cron_action('Threads with replies moved from Forum 17 to Forum 2', $nextitem);

?>

D-Railer
10-06-2005, 06:33 PM
I love you. I'm clearly going to be using this. w00t!

Ambie
04-07-2006, 02:12 AM
I used this code and a cron job to auto move threads from my news forum in 3.09. Since I upgraded to 3.5.4, it no longer works. Anyone know why?

aciurczak
04-08-2006, 05:42 PM
Minor change in the function names for accessing the db in 3.5.X:

<?php

error_reporting(E_ALL & ~E_NOTICE);
if (!is_object($vbulletin->db))
{
exit;
}

$vbulletin->db->query("UPDATE " . TABLE_PREFIX . "thread SET forumid = 2 WHERE forumid = 17 AND replycount >= 1");
require_once(DIR . '/includes/functions_databuild.php');
build_forum_counters(2);
build_forum_counters(17);

log_cron_action('Threads with replies moved from 17 to 2', $nextitem);

?>

Ambie
04-08-2006, 07:10 PM
Thank you very much! It works again.:)

chikkoo
09-26-2006, 07:40 PM
Does this works in vb 3.6.1?

aciurczak
09-26-2006, 08:13 PM
Works fine in 3.6.1. Only glitch I've found (which isn't new to 3.6.1, it is been this way through quite a few versions) is when dealing with the new post flag.

If I read the thread in the news forum, and post a reply, it is marked as read. Then it gets moved over to my discussion forum. When I click on the forum, the thread appears to be read already, but at the forumhome page, there appears to be new posts within the discussion forum. Sometimes this goes away by clicking on that thread again, but sometimes it appears not to clear the new post flag until I hit "mark all posts read" at the bottom of the main page.

I wonder if there is another maintenance function that would be useful in addition to "build forumcounters".

EDIT: At first glance, it looks like "build_thread_counters($threadid)" would be the function to clean up this last (minor) issue, but unfortunately it requiers the $threadid parameter, which we don't touch in the code above; just changing all forum id's at once for certain threads in the THREAD table; not then calling each one of those particular threads to build counters after making the switch.

SCRIPT3R
09-26-2006, 08:36 PM
i think that's because your forum cleanup hasn't been run yet.

aciurczak
09-26-2006, 08:44 PM
i think that's because your forum cleanup hasn't been run yet.

That's actually a very good suggestion. I'll reorder the cron jobs so the forum cleanup occurs 1 minute after the thread moves and see if this behavior is less noticeable...

Amavisca
11-29-2006, 06:19 AM
oh, how do I copy thread to another forum instead of move thread. And also have a condition to move only threads that are 2 weeks old. Thanx a bunch

MiriamS
02-19-2009, 02:46 PM
I know this is an old topic, but I want to know if I can use this code on vB 3.8

My next question is, where to put the code? Do I have to make a special page?

Lynne
02-19-2009, 04:16 PM
That is a cron job/scheduled task. So, you would make a page with that php in it and put it somewhere (/includes/cron ?) and then run it as a scheduled task. I have no idea if it works for 3.8. I suppose you could try it on a test forum.

MiriamS
02-19-2009, 04:24 PM
Thanks Lynne, I will try it on a local test forum. I thought it would be something like this, but now I know it for sure. ;)

gdguide
04-22-2009, 04:10 AM
We've tried this code, but it doesn't seem to do anything. Is there anyone that knows how to rewrite it for 3.7.x?

Lynne
04-22-2009, 02:07 PM
We've tried this code, but it doesn't seem to do anything. Is there anyone that knows how to rewrite it for 3.7.x?
I hope you modified the code to be specific for your forum. Since you didn't post exactly what you did, we are unable to help you in anyway.