Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

Re: [Eric P] Deleting Attachments

Quote Reply
Re: [Eric P] Deleting Attachments In reply to
Hi Eric,

I think the easiest way to go about it would not be to look at the actual modification time of the file, but rather the date of the post. In this way, all posts older than (for example) 30 days will have their attachments removed. It makes the work a little easier, and the case where someone uploads a new attachment to a 30-day-old post is quite rare.

This code snippit should delete the attachments from any posts older than 30 days UNLESS they have been selected as "kept". The attachments are automatically deleted from disk.

Code:

my $days_old = 30;my $post = $DB->table('Post');
my $patt = $DB->table('PostAttachment');my $cond = GT::SQL::Condition->new(
post_keep => '=' => 0,
post_time => '<' => time - 24 * 60 * 60 * $days_old,
post_has_attachments => '>=' => 1
);my $sth = $post->select(post_id => $cond);
while (my $post_id = $sth->fetchrow) {
$patt->delete({ post_id_fk => $post_id });
}

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Subject Author Views Date
Thread Deleting Attachments Eric P 1852 Oct 2, 2002, 12:05 PM
Thread Re: [Eric P] Deleting Attachments
Alex 1804 Oct 2, 2002, 4:50 PM
Thread Re: [Alex] Deleting Attachments
Eric P 1793 Oct 2, 2002, 9:56 PM
Thread Re: [Eric P] Deleting Attachments
Jagerman 1797 Oct 3, 2002, 3:24 PM
Post Re: [Jagerman] Deleting Attachments
Eric P 1787 Oct 4, 2002, 11:44 AM