vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   HowTo? Move / Delete Threads of one forum after x days (https://vborg.vbsupport.ru/showthread.php?t=325711)

Za4a Tuner 10-26-2017 11:58 AM

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

MarkFL 10-26-2017 05:14 PM

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


Za4a Tuner 10-26-2017 06:33 PM

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

MarkFL 10-26-2017 09:03 PM

Yeah, I'm not sure but I would just leave the array as is because it won't hurt for it to be there. :)

Za4a Tuner 10-26-2017 10:48 PM

ok, i will give it a try

MarkFL 10-29-2017 07:39 PM

Quote:

Originally Posted by Za4a Tuner (Post 2590779)
ok, i will give it a try

Did it work as you want?

Za4a Tuner 10-29-2017 07:50 PM

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

kr Chris

Za4a Tuner 10-30-2017 07:35 PM

1 Attachment(s)
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

MarkFL 10-30-2017 07:43 PM

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.

Za4a Tuner 10-30-2017 08:11 PM

Quote:

Originally Posted by MarkFL (Post 2590846)
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 (Post 2590846)
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.

MarkFL 10-30-2017 10:06 PM

I will run the code on my local dev site to see what I find. :)

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

Okay, this should work:

PHP Code:

global $vbulletin;
require_once(
DIR '/includes/functions_databuild.php');

$deleted 0;
$curtime TIMENOW;
$physicaldel false;
$del_user fetch_userinfo(1);
$del_forumid '4';
$reason 'Thema alt entfernt via cron.';

$delinfo = array(
    
'userid'          => $del_user['userid'],
    
'username'        => $del_user['username'],
    
'reason'          => $reason,
    
'keepattachments' => true
);

$countposts = ($vbulletin->forumcache["$del_forumid"]['options'] & $vbulletin->bf_misc_forumoptions['countposts']);

$query "SELECT thread.* FROM " TABLE_PREFIX "thread AS thread WHERE lastpost <= " . ($curtime 365*86400) . " AND forumid = " $del_forumid;

$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($del_forumid);
}

$move_prefixid 'reportthread_solved';
$source_forumid 10;
$destination_forumid 12;

$vbulletin->db->query_write(
    UPDATE " 
TABLE_PREFIX "thread
        SET forumid = " 
$destination_forumid "
        WHERE forumid = " 
$source_forumid "
        AND lastpost <= " 
. ($curtime 100*86400) . "
        AND prefixid = '" 
$move_prefixid "'
"
);

build_forum_counters($source_forumid);
build_forum_counters($destination_forumid); 

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

I move that these double-post merges go away. :)

Za4a Tuner 10-31-2017 06:39 AM

Thanks for your help and spending time on my problem,
but the code from the post above won't work in my board :(
I used it, as you posted it, or have i to do some changes?

kr Chris

MarkFL 10-31-2017 01:44 PM

It should work exactly as I posted it, but it could be that you have other plugins hooked at "threaddata_delete" that are causing an issue. Do you have any plugins hooked there?

Za4a Tuner 11-01-2017 10:58 AM

Quote:

Originally Posted by MarkFL (Post 2590867)
It should work exactly as I posted it, but it could be that you have other plugins hooked at "threaddata_delete" that are causing an issue. Do you have any plugins hooked there?

in the plug-in list is nothing hooked at "threaddata_delete".

MarkFL 11-01-2017 02:50 PM

When you manually run the daily cleanup, what error(s) do you get?

Za4a Tuner 11-04-2017 06:35 PM

1 Attachment(s)
Hy,
sorry for the late answer, but i wasn't at home till now.

All the shedulded tasks even don't run!
Attachment 156714

The plugin is disabled, and the task for "daily cleanup" run:
Attachment 156715

but when i open the logfile, there is no entry for the task!
Attachment 156716

I don't know whats wrong

MarkFL 11-04-2017 07:02 PM

When you manually run the daily cleanup, what error messages do you get?

Za4a Tuner 11-04-2017 07:10 PM

this is the error message:
PHP Code:

[Sat Nov 04 21:06:43 2017] [error] [client 95.91.250.110PHP Fatal error:  Only variables can be passed by reference in .../includes/cron/dailycleanup.php(126) : eval()'d code on line 12, referer: .../admincp/cronadmin.php?do=modify 



All times are GMT. The time now is 03:28 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.01234 seconds
  • Memory Usage 1,842KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (7)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (18)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete