The Site > Site Suggestions & Support

new chat feature. (show the love)

<< < (9/9)

Amber:
Wow.  *bows to your awesome*

iago:
Some parts of this can (and should) be done more elegantly, but this is the script.


--- Code: ---#!/usr/local/bin/perl

$time = time();
$timeago90 = $time - ( 24*60*60*90 ) ; # 90 days ago
$timeago360 = $time - ( 24*60*60*360 ) ; # 360 days ago
$boards90 = "41,42,1,40,28,39,37,36"; # comma delimited list of board IDs that have a 90 day expiration
$boards360 = "22";

# ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
# $year -= 1;
# $timeago = timelocal($sec,$min,$hour,$mday,$mon,$year);

use DBI;

# Replace with your connect information

$dbh = DBI->connect("DBI:mysql:DATABASENAME:localhost","DATABASEUSER","DATABASEPASSWORD");

# The prefix for my boards is "jbc_". Yours is likely different. You'd need to change that prefix wherever you find it below.

print "Beginning 90 day scan\n\n";

$sth = $dbh->prepare(qq(
        select b.id_topic, m.subject, m.posterTime
        from jbc_topics b, jbc_messages m
        where b.id_last_msg = m.id_msg
        and b.id_board IN ( $boards90 )
        and b.isSticky = 0
        and m.posterTime < $timeago90
));

$rv = $sth->execute;

while ( $row = $sth->fetchrow_hashref ) {
        push(@topics,$row->{id_topic});
        print "$row->{id_topic} ($row->{subject}) " . scalar(localtime($row->{posterTime})) . "\n";
}

print "\n\nBeginning 360 day scan\n\n";

$sth = $dbh->prepare(qq(
        select b.id_topic, m.subject, m.posterTime
        from jbc_topics b, jbc_messages m
        where b.id_last_msg = m.id_msg
        and b.id_board IN ( $boards360 )
        and b.isSticky = 0
        and m.posterTime < $timeago360
));


$rv = $sth->execute;

while ( $row = $sth->fetchrow_hashref ) {
        push(@topics,$row->{id_topic});
        print "$row->{id_topic} ($row->{subject}) " . scalar(localtime($row->{posterTime})) . "\n";
}

print $#topics + 1, " topics found\n\n";

print "\n\nBEGINNING TERMINATION in 5 seconds\n\n";

# Pause five seconds so you can kill the script from actually deleting topics. Point of no return after the break...

sleep 5;

foreach $topic ( @topics ) {

        print "Expunging topic $topic\n";

        $sth = $dbh->prepare(qq(
                delete from jbc_messages where id_topic = $topic
        ));

        $rv = $sth->execute;

        $sth = $dbh->prepare(qq(
                delete from jbc_topics where id_topic = $topic
        ));

        $rv = $sth->execute;

}


print "Now that this is done, you need to 'Recount all forum stats' to get the boards to look right!\n";

--- End code ---

Shecky:

--- Quote from: iago on June 02, 2010, 08:23:50 PM ---Some parts of this can (and should) be done more elegantly, but this is the script.

--- End quote ---

CODE MONKEY ALERT! RAISE SHIELDS!

Navigation

[0] Message Index

[*] Previous page

Go to full version