diff --git a/lib/Lutim/Command/cron/cleanbdd.pm b/lib/Lutim/Command/cron/cleanbdd.pm index 4257755..c1c5f28 100644 --- a/lib/Lutim/Command/cron/cleanbdd.pm +++ b/lib/Lutim/Command/cron/cleanbdd.pm @@ -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 diff --git a/lib/Lutim/Command/cron/cleanfiles.pm b/lib/Lutim/Command/cron/cleanfiles.pm index ffc5d66..a2e7d76 100644 --- a/lib/Lutim/Command/cron/cleanfiles.pm +++ b/lib/Lutim/Command/cron/cleanfiles.pm @@ -15,7 +15,7 @@ sub run { my $config = $c->app->plugin('Config', { file => File::Spec->catfile($Bin, '..' ,'lutim.conf'), default => { - dbtype => 'sqlite', + dbtype => 'sqlite', } }); diff --git a/lib/Lutim/DB/Image.pm b/lib/Lutim/DB/Image.pm index 682b982..a035dd4 100644 --- a/lib/Lutim/DB/Image.pm +++ b/lib/Lutim/DB/Image.pm @@ -129,6 +129,20 @@ sub to_hash { }; } +=head2 clean_ips_until + +=over 1 + +=item B : C<$c-Eclean_ips_until($time)> + +=item B : unix timestamp + +=item B : remove the image's sender information on images created before the given timestamp + +=item B : the db accessor object + +=back + =head2 get_no_longer_viewed_files =over 1 diff --git a/lib/Lutim/DB/Image/SQLite.pm b/lib/Lutim/DB/Image/SQLite.pm index e45eada..472e78d 100644 --- a/lib/Lutim/DB/Image/SQLite.pm +++ b/lib/Lutim/DB/Image/SQLite.pm @@ -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;