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.
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
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