Work on #42: cleanbdd command

This commit is dedicated to Schoumi, who is supporting me on Tipeee.
Many thanks :-)
This commit is contained in:
Luc Didry
2017-05-20 16:39:17 +02:00
parent 0de43b74db
commit 179def2d3e
4 changed files with 33 additions and 8 deletions
+5 -7
View File
@@ -1,7 +1,6 @@
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
+1 -1
View File
@@ -15,7 +15,7 @@ sub run {
my $config = $c->app->plugin('Config', {
file => File::Spec->catfile($Bin, '..' ,'lutim.conf'),
default => {
dbtype => 'sqlite',
dbtype => 'sqlite',
}
});
+14
View File
@@ -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
View File
@@ -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;