Cron task to delete expired images

This commit is contained in:
Luc Didry
2014-02-24 20:12:10 +01:00
parent 9787a7210a
commit e014bc229b
2 changed files with 43 additions and 1 deletions
+7 -1
View File
@@ -5,7 +5,7 @@ It means Let's Upload That Image.
##What does it do?
It stores images and allows you to see them or download them.
Images are indefinitly stored unless you request that they will be deleted at first view or after 24 hours.
Images are indefinitly stored unless you request that they will be deleted at first view or after 24 hours / one week / one month / one year.
##License
LUTIm is licensed under the terms of the AGPL. See the LICENSE file.
@@ -114,6 +114,12 @@ To automatically delete the IP addresses of image's senders after a configurable
carton exec script/lutim cron cleanbdd
```
###Delete expired files
To automatically delete files which availability delay is over (when you choose that your image will be deleted after 24h / one week / etc.)
```shell
carton exec script/lutim cron cleanfiles
```
###Watch the size of the files directory
To execute an action when the files directory is heavier than `max_total_size`.
The available actions are `warn` and `stop-upload`:
@@ -0,0 +1,36 @@
package Mojolicious::Command::cron::cleanfiles;
use Mojo::Base 'Mojolicious::Command';
use LutimModel;
use Mojo::Util qw(slurp decode);
use Mojolicious::Plugin::Config;
has description => 'Delete expired files.';
has usage => sub { shift->extract_usage };
sub run {
my $c = shift;
my $config = Mojolicious::Plugin::Config->parse(decode('UTF-8', slurp 'lutim.conf'), 'lutim.conf');
my $time = time();
my @images = LutimModel::Lutim->select('WHERE enabled = 1 AND (delete_at_day * 86400) < (? - created_at) AND delete_at_day != 0', $time);
for my $image (@images) {
$image->update(enabled => 0);
unlink $image->path();
}
}
=encoding utf8
=head1 NAME
Mojolicious::Command::cron::cleanfiles - Delete expired files
=head1 SYNOPSIS
Usage: script/lutim cron cleanfiles
=cut
1;