Is there a way to delete attachments by age but keep the post. In the admin area you can delete posts older than x days. How would one delete attachments but leave the posts, other than manually deleting them one by one? Text takes very little storage but attachments add up to a lot of space.
Oct 2, 2002, 4:50 PM
Administrator (9387 posts)
Oct 2, 2002, 4:50 PM
Post #2 of 5
Views: 2022
Hi,
No, there isn't an easy way to do this. You could write a perl script that would go through the attachments directory, look at the age of the file, and then unlink it and update the post table if it's over a ceartain age.
Cheers,
Alex
--
Gossamer Threads Inc.
No, there isn't an easy way to do this. You could write a perl script that would go through the attachments directory, look at the age of the file, and then unlink it and update the post table if it's over a ceartain age.
Cheers,
Alex
--
Gossamer Threads Inc.
Oct 3, 2002, 3:24 PM
Staff / Moderator (2198 posts)
Oct 3, 2002, 3:24 PM
Post #4 of 5
Views: 2015
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
Oct 4, 2002, 11:44 AM
User (57 posts)
Oct 4, 2002, 11:44 AM
Post #5 of 5
Views: 2005
Jagerman
That is a huge help. What I thought I might do it insert your code in the TempAttachment.pm file. That way attachment deletion is triggered by a new attachement. Sort of a pop off push on kind of process. Can you think of a better way or any problems with this?
That is a huge help. What I thought I might do it insert your code in the TempAttachment.pm file. That way attachment deletion is triggered by a new attachement. Sort of a pop off push on kind of process. Can you think of a better way or any problems with this?