Commit 179def2d by Luc Didry

Work on #42: cleanbdd command

This commit is dedicated to Schoumi, who is supporting me on Tipeee.
Many thanks :-)
parent 0de43b74
package Lutim::Command::cron::cleanbdd;
use Mojo::Base 'Mojolicious::Command';
use LutimModel;
use Mojo::Util qw(slurp decode);
use Lutim::DB::Image;
use FindBin qw($Bin);
use File::Spec qw(catfile);
......@@ -15,16 +14,15 @@ sub run {
file => File::Spec->catfile($Bin, '..' ,'lutim.conf'),
default => {
keep_ip_during => 365,
dbtype => 'sqlite',
}
});
my $separation = time() - $config->{keep_ip_during} * 86400;
LutimModel->do(
'UPDATE lutim SET created_by = "" WHERE path IS NOT NULL AND created_at < ?',
{},
$separation
);
my $dbi = Lutim::DB::Image->new(app => $c->app);
$dbi->clean_ips_until($separation);
}
=encoding utf8
......
......@@ -15,7 +15,7 @@ sub run {
my $config = $c->app->plugin('Config', {
file => File::Spec->catfile($Bin, '..' ,'lutim.conf'),
default => {
dbtype => 'sqlite',
dbtype => 'sqlite',
}
});
......
......@@ -129,6 +129,20 @@ sub to_hash {
};
}
=head2 clean_ips_until
=over 1
=item B<Usage> : C<$c-E<gt>clean_ips_until($time)>
=item B<Arguments> : unix timestamp
=item B<Purpose> : remove the image's sender information on images created before the given timestamp
=item B<Returns> : the db accessor object
=back
=head2 get_no_longer_viewed_files
=over 1
......
......@@ -13,6 +13,19 @@ sub new {
return $c;
}
sub clean_ips_until {
my $c = shift;
my $time = shift;
Lutim::DB::SQLite->do(
'UPDATE lutim SET created_by = "" WHERE path IS NOT NULL AND created_at < ?',
{},
$time
);
return $c;
}
sub get_no_longer_viewed_files {
my $c = shift;
my $time = shift;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment