From d001c791676ec85371465f557cf21e72b09319a4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 16 Nov 2012 11:37:33 +0100 Subject: [PATCH] =?utf8?q?cleanup=20Methode=20und=20Manager=20f=C3=BCr=20C?= =?utf8?q?svImportReport?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Auth.pm | 11 +++++++++ SL/BackgroundJob/CsvImport.pm | 6 ----- SL/DB/CsvImportReport.pm | 2 +- SL/DB/Manager/CsvImportReport.pm | 38 ++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 SL/DB/Manager/CsvImportReport.pm diff --git a/SL/Auth.pm b/SL/Auth.pm index d0e8c9ab3..3ef266065 100644 --- a/SL/Auth.pm +++ b/SL/Auth.pm @@ -713,6 +713,17 @@ sub destroy_session { $main::lxdebug->leave_sub(); } +sub active_session_ids { + my $self = shift; + my $dbh = $self->dbconnect; + + my $query = qq|SELECT id FROM auth.session|; + + my @ids = selectall_array_query($::form, $dbh, $query); + + return @ids; +} + sub expire_sessions { $main::lxdebug->enter_sub(); diff --git a/SL/BackgroundJob/CsvImport.pm b/SL/BackgroundJob/CsvImport.pm index 98aed9c37..5471addb5 100644 --- a/SL/BackgroundJob/CsvImport.pm +++ b/SL/BackgroundJob/CsvImport.pm @@ -51,8 +51,6 @@ sub run { $self->{db_obj} = shift; $self->do_import; - - $self->cleanup; } sub do_import { @@ -110,10 +108,6 @@ sub track_progress { $self->{db_obj}->save; } -sub cleanup { - -} - 1; __END__ diff --git a/SL/DB/CsvImportReport.pm b/SL/DB/CsvImportReport.pm index 1271c56ae..5b7acd25b 100644 --- a/SL/DB/CsvImportReport.pm +++ b/SL/DB/CsvImportReport.pm @@ -7,6 +7,7 @@ use strict; use SL::DBUtils; use SL::DB::MetaSetup::CsvImportReport; +use SL::DB::Manager::CsvImportReport; __PACKAGE__->meta->add_relationships( rows => { @@ -21,7 +22,6 @@ __PACKAGE__->meta->add_relationships( }, ); -__PACKAGE__->meta->make_manager_class; __PACKAGE__->meta->initialize; sub folded_rows { diff --git a/SL/DB/Manager/CsvImportReport.pm b/SL/DB/Manager/CsvImportReport.pm new file mode 100644 index 000000000..370a6c97f --- /dev/null +++ b/SL/DB/Manager/CsvImportReport.pm @@ -0,0 +1,38 @@ +package SL::DB::Manager::CsvImportReport; + +use strict; + +use base qw(SL::DB::Helper::Manager); + +sub object_class { 'SL::DB::CsvImportReport' } + +__PACKAGE__->make_manager_methods; + +sub cleanup { + my ($self) = @_; + + $::auth->active_session_ids; + + # get expired reports + my $objects = $self->get_all(query => [ + session_id => [ + not => [ $::auth->active_session_ids ] + ] + ]); + + $_->destroy for @$objects; + + # get reports for the active session that aren't the latest + $objects = $self->get_all( + query => [ session_id => $::auth->get_session_id, ], + order_by => [ 'id' ], + ); + + # skip the last one + for (0 .. $#$objects - 1) { + $objects->[$_]->destroy; + } +} + +1; + -- 2.20.1