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

Reply
 
Thread Tools Display Modes
  #1  
Old 10-26-2017, 11:58 AM
Za4a Tuner's Avatar
Za4a Tuner Za4a Tuner is offline
 
Join Date: Aug 2005
Location: Germany
Posts: 114
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default HowTo? Move / Delete Threads of one forum after x days

Hello,
i'd like to do two jobs automatically:

1.)
"Delete all threads in forum id=88 after 365 days"

2.)
"Move all threads older than 100 days and the thread-prefix=done from forum-id=10 to forum-id=12"

Can anyone show me a cronjob for this?

kr Chris
Reply With Quote
  #2  
Old 10-26-2017, 05:14 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Create a plugin hooked at "cron_script_cleanup_daily" with the code:

PHP Code:
global $vbulletin$db;
require_once(
DIR '/includes/functions_databuild.php');
$deleted false;
$curtime TIMENOW;
$physicaldel false;
$del_user $fetch_userinfo(1);
$delinfo = array(
    
'userid'          => $del_user['userid'],
    
'username'        => $del_user['username'],
    
'reason'          => 'Thread auto-deleted via cron.',
    
'keepattachments' => true
);
$countposts $vbulletin->forumcache[88]['options'] & $vbulletin->bf_misc_forumoptions['countposts'];

$query "SELECT thread.* FROM " TABLE_PREFIX "thread AS thread WHERE lastpost <= " $curtime 365*86400 " AND forumid = 88";
$threads_delete $vbulletin->db->query_read($query);
$mthread =& datamanager_init('Thread'$vbulletinERRTYPE_SILENT'threadpost');

while (
$thread_delete $vbulletin->db->fetch_array($threads_delete))
{
    if (!
$deleted)
    {
        
$deleted true;
    }

    
$mthread->set_existing($thread_delete);
    
$mthread->delete($countposts$physicaldel$delinfofalse);
}

unset(
$mthread);

if (
$deleted)
{
    
build_forum_counters(88);
}

$vbulletin->db->query_write(
    UPDATE " 
TABLE_PREFIX "thread
        SET forumid = 12
        WHERE forumid = 10
        AND lastpost <= " 
$curtime 100*86400 "
        AND prefixid = 'done'
"
);

build_forum_counters(10);
build_forum_counters(12); 

Note: I have not tested this code. Please test this first on your test installation, and then make a backup of your database before running this code the first time on your live site. I cannot emphasize enough how important this is!

As the code is written, the thread deletion is soft-delete. To use a hard-delete, change the line:

PHP Code:
$physicaldel false
to:

PHP Code:
$physicaldel true
Reply With Quote
2 благодарности(ей) от:
Dave, Za4a Tuner
  #3  
Old 10-26-2017, 06:33 PM
Za4a Tuner's Avatar
Za4a Tuner Za4a Tuner is offline
 
Join Date: Aug 2005
Location: Germany
Posts: 114
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hy,
thank you for the code!
I'll try it on my testboard and will give you feedback.

One question:
If i "hard-delete" the threads, than i won't need the line for the attachments?
PHP Code:
global $vbulletin$db
require_once(
DIR '/includes/functions_databuild.php'); 
$deleted false
$curtime TIMENOW;
$physicaldel true
$del_user $fetch_userinfo(1); 
$delinfo = array( 
    
'userid'          => $del_user['1'], 
    
'username'        => $del_user['Chris'], 
    
'reason'          => 'Thread auto-deleted via cron.'
); 
kr Chris
Reply With Quote
  #4  
Old 10-26-2017, 09:03 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, I'm not sure but I would just leave the array as is because it won't hurt for it to be there.
Reply With Quote
  #5  
Old 10-26-2017, 10:48 PM
Za4a Tuner's Avatar
Za4a Tuner Za4a Tuner is offline
 
Join Date: Aug 2005
Location: Germany
Posts: 114
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ok, i will give it a try
Reply With Quote
  #6  
Old 10-29-2017, 07:39 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Za4a Tuner View Post
ok, i will give it a try
Did it work as you want?
Reply With Quote
  #7  
Old 10-29-2017, 07:50 PM
Za4a Tuner's Avatar
Za4a Tuner Za4a Tuner is offline
 
Join Date: Aug 2005
Location: Germany
Posts: 114
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I was on tour this weekend.
The code is running in my testboard since this afternoon.
Tomorrow i give you my feedback.

kr Chris
Reply With Quote
  #8  
Old 10-30-2017, 07:35 PM
Za4a Tuner's Avatar
Za4a Tuner Za4a Tuner is offline
 
Join Date: Aug 2005
Location: Germany
Posts: 114
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello,
today i found time to test the plugin.

I don't know what's wrong, but it won't work!

When the plugin is active, the cronjob (id 15 - daily clean up) didn't end correct.
Attachment 156708

Is the plugin inactive, evrything is fine with the cornjob:
Attachment 156709

This is the code i use fpr my testboard:

- forum-id = 4 => delete threads after 365 days
- forum-id = 10 => move threads with the prefix "Delete" after 100 days to forum-id = 12
- my User-ID = 1
- my Username = Chris

PHP Code:
global $vbulletin$db;
require_once(
DIR '/includes/functions_databuild.php');
$deleted false;
$curtime TIMENOW;
$physicaldel false;
$del_user $fetch_userinfo(1);
$delinfo = array(
    
'userid'          => $del_user['1'],
    
'username'        => $del_user['Chris'],
    
'reason'          => 'Thema alt entfernt via cron.',
    
'keepattachments' => false
);
$countposts $vbulletin->forumcache[4]['options'] & $vbulletin->bf_misc_forumoptions['countposts'];

$query "SELECT thread.* FROM " TABLE_PREFIX "thread AS thread WHERE lastpost <= " $curtime 365*86400 " AND forumid = 4";
$threads_delete $vbulletin->db->query_read($query);
$mthread =& datamanager_init('Thread'$vbulletinERRTYPE_SILENT'threadpost');

while (
$thread_delete $vbulletin->db->fetch_array($threads_delete))
{
    if (!
$deleted)
    {
        
$deleted true;
    }

    
$mthread->set_existing($thread_delete);
    
$mthread->delete($countposts$physicaldel$delinfofalse);
}

unset(
$mthread);

if (
$deleted)
{
    
build_forum_counters(4);
}

$vbulletin->db->query_write(
    UPDATE " 
TABLE_PREFIX "thread
        SET forumid = 12
        WHERE forumid = 10
        AND lastpost <= " 
$curtime 100*86400 "
        AND prefixid = 'Delete'
"
);

build_forum_counters(10);
build_forum_counters(12); 
kr Chris
Reply With Quote
  #9  
Old 10-30-2017, 07:43 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't read German, so the screenshots aren't of much use to me. Sorry

You don't want to edit the 'userid' and 'username' keys of the $delinfo array...that could be the cause of the issue.
Reply With Quote
  #10  
Old 10-30-2017, 08:11 PM
Za4a Tuner's Avatar
Za4a Tuner Za4a Tuner is offline
 
Join Date: Aug 2005
Location: Germany
Posts: 114
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MarkFL View Post
I don't read German, so the screenshots aren't of much use to me. Sorry
would the screenshots be helpfull if the language is english? I can install the english phrases, this woul'd be not a problem

Quote:
Originally Posted by MarkFL View Post
You don't want to edit the 'userid' and 'username' keys of the $delinfo array...that could be the cause of the issue.
that don't make a difference, i tried it right now.
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 10:26 AM.


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.05258 seconds
  • Memory Usage 2,328KB
  • Queries Executed 14 (?)
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
  • (5)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (2)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (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_postinfo_query
  • fetch_postinfo
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete