From: Sven Schöling Date: Fri, 16 Nov 2012 10:37:33 +0000 (+0100) Subject: cleanup Methode und Manager für CsvImportReport X-Git-Tag: release-3.1.0beta1~727 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=d001c791676ec85371465f557cf21e72b09319a4;p=kivitendo-erp.git cleanup Methode und Manager für CsvImportReport --- 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; +