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 03-13-2008, 09:57 AM
MrEyes MrEyes is offline
 
Join Date: Nov 2004
Posts: 380
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Automatically move threads when postcount > X

Hello all,

The thread title no longer matches the question I have, as originally I didn't know how to acheive what I am trying. However after a little fiddling I am almost there. So I suppose the thread title should be different, unfortunately I can't change it now.

Anyway enough waffle, this is what I am trying to do within a VB cron job:
  1. Select all threads from ForumX that were and started in the last X days where postcount is greater than Y and the status is open.
  2. Then for each of the selected threads move them to ForumY, with a non expiring move message left in ForumX
  3. Then get open threads in ForumX that were started before Z days and lock them.

The following code block is how I have managed to acheive this

PHP Code:
<?php
/*
vBulletin Cron Based Auto Move / Lock Threads
A work in progress
*/

error_reporting(E_ALL & ~E_NOTICE);

if (!
is_object($vbulletin->db))
{
    exit;
}

//vars
$checkForum 2;
$targetForum 3;
$threadOpenState 1;
$afterDate TIMENOW - (24 60 60); //7 days
$lockBeforeDate TIMENOW - (14 24 60 60); //14 days
$rssIconId 3;

//select all threads the last 7 days from a specific forum where the reply count
//is > 0 and the thread is marked as fully open (id 1)
$threadsWithReplies $vbulletin->db->query_read("SELECT
            thread.threadid,
             thread.title,
             thread.lastpost,
             thread.forumid,
             thread.replycount,
             thread.postusername,
             thread.postuserid,
             thread.lastposter,
             thread.views,
             thread.iconid
         FROM
             " 
TABLE_PREFIX "thread as thread
         WHERE
             thread.replycount > 0
         AND
             thread.forumid = " 
$checkForum "
         AND
             thread.open = " 
$threadOpenState "
         AND
             thread.dateline > " 
$afterDate ""
         
);
         
//iterate through the resultset from the DB select query and move each of these
//threads to a different forum
while ($threadinfo $vbulletin->db->fetch_array($threadsWithReplies))
{
    
log_cron_action("Moving ["$threadinfo['title'] ."][" $threadinfo['threadid'] . "] from forum  [" $checkForum "] to forum [" $targetForum "]"$nextitem$phrased 0);
    
    
//move the thread
    
$threadman =& datamanager_init('Thread'$vbulletinERRTYPE_STANDARD'threadpost');
    
$threadman->set_info('skip_moderator_log'true);
    
$threadman->set_existing($threadinfo);
    
$threadman->set('title'$threadinfo['title'], truefalse);
    
$threadman->set('forumid'$targetForum);
    
$threadman->set('iconid'$rssIconId);
    
$threadman->save();
    unset(
$threadman);
    
    
//create the "moved" message in the original forum
    
$redirdata = array(
        
'lastpost'     => intval($threadinfo['lastpost']),
        
'forumid'      => intval($threadinfo['forumid']),
        
'pollid'       => intval($threadinfo['threadid']),
        
'open'         => 10,
        
'replycount'   => intval($threadinfo['replycount']),
        
'postusername' => $threadinfo['postusername'],
        
'postuserid'   => intval($threadinfo['postuserid']),
        
'lastposter'   => $threadinfo['lastposter'],
        
'dateline'     => TIMENOW,
        
'views'        => intval($threadinfo['views']),
        
'iconid'       => intval($threadinfo['iconid']),
        
'visible'      => 1);
        
    
$redir =& datamanager_init('Thread'$vbulletinERRTYPE_ARRAY'threadpost');
    foreach (
array_keys($redirdata) AS $field)
    {
        
$redir->setr($field$redirdata["$field"], truefalse);
    }
    
    
//not sure what this if/else statement does, but it is a direct 
    //copy and paste from postings.php so for now it stays ;)
    
if (empty($vbulletin->GPC['redirecttitle']))
    {
        
$redir->set('title'$threadinfo['title'], truefalse);
    }
    else
    {
        
$redir->set('title'unhtmlspecialchars($vbulletin->GPC['redirecttitle']));
    }
    
    
$redir->set('prefixid'$vbulletin->GPC['redirectprefixid']);
    
$redir->save();
    unset(
$redir);
    
    
log_cron_action("Move complete for ["$threadinfo['title'] ."][" $threadinfo['threadid'] . "] from forum  [" $checkForum "] to forum [" $targetForum "]"$nextitem$phrased 0);
    
    
$moveActionPerformed true;
}

unset(
$threadsWithReplies);

if (!isset(
$moveActionPerformed))
{
    
log_cron_action("No items to move"$nextitem$phrased 0);
}

//now lock all threads older than $lockBeforeDate
$oldThreads $vbulletin->db->query_read("SELECT
            thread.threadid,
             thread.title,
             thread.lastpost,
             thread.forumid,
             thread.replycount,
             thread.postusername,
             thread.postuserid,
             thread.lastposter,
             thread.views,
             thread.iconid
         FROM
             " 
TABLE_PREFIX "thread as thread
         WHERE
             thread.forumid = " 
$checkForum "
         AND
             thread.open = " 
$threadOpenState "
         AND
             thread.dateline < " 
$lockBeforeDate ""
         
);

//iterate through the resultset from the DB select query and lock
//each of these threads
while ($threadinfo $vbulletin->db->fetch_array($oldThreads))
{
    
log_cron_action("Locking thread ["$threadinfo['title'] ."][" $threadinfo['threadid'] . "] from forum  [" $checkForum "]"$nextitem$phrased 0);
    
    
//lock the thread
    
$threadman =& datamanager_init('Thread'$vbulletinERRTYPE_STANDARD'threadpost');
    
$threadman->set_info('skip_moderator_log'true);
    
$threadman->set_existing($threadinfo);
    
$threadman->set('open'0);
    
$threadman->save();
    unset(
$threadman);
    
    
$lockActionPerformed true;
}
unset (
$oldThreads);

if (!isset(
$lockActionPerformed))
{
    
log_cron_action("No items to lock"$nextitem$phrased 0);
}

?>
Problem / Question #1
On my test forum I am moving the thread to an empty forum, after the move has been performed the forumdisplay summary still shows the "Last Post" column as never. How do I update this to show the date/time/poster details of the moved thread? However I suppose that in the real world this doesn't matter so much as the target forum is fairly busy so the "Last Post" will probably be a member post on a different thread.

Problem / Question #2
After I have performed the moves/locks do I need to rebuild any counters? If yes this could be a show stopper as I intend to run this script every 15 minutes and a counter rebuild every time would be a massive hit. For the same reasons I need this to be as optimal as possible, can anybody point out areas where I am performing unnecessary actions? Also on the subject of load, this cron script will be added multiple times for multiple forums (around 5) each of which will run every 15 minutes (staggered) is it worth redesigning the select I am doing to support getting all the posts for all the forums in one select and one cron call?

Problem / Question #3
To explain this some background is needed. I have configured an RSS feed to pull data into vBulletin and post threads in an RSS specific forum. Users do not have access to create threads in this forum but they can reply. If a member replies to an RSS post then they have obviously found the item interesting and worth commenting on, and as such it would be great if this could be highlighted to the rest of the community. Hence the reason for moving it to a "normal" forum. Now here is the problem, if the thread is moved I assume the RSS system will think that that item hasn't been retrieved and will therefore repost the item the next time the feed is checked. Is this right? wrong? I have run some tests and this doesn't seem to happen, I would guess that the RSS Feed subsystem checks if the RSS feed item title is already in the feed target forum and if so ignores it. So this should work as I am leaving a non expiring redirect in this forum if the item is moved. Can anybody confirm this?

So I am now at your mercy, does anybody have any answers/suggestions for these problems/questions?
Reply With Quote
  #2  
Old 07-25-2008, 10:01 PM
KevinL KevinL is offline
 
Join Date: Apr 2005
Posts: 1,287
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have been searching for this.

Andreas wrote me a mod for 3.0 way back in the day to do just this (with admin options and everything). Which I still have the mod that he wrote for me (if it can be updated to 3.7.x)

And I'm looking for this once again. Did you ever have any luck with this?

Thanks!
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 06:38 AM.


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.03790 seconds
  • Memory Usage 2,232KB
  • Queries Executed 13 (?)
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_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (2)post_thanks_box
  • (2)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit_info
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)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