cleanup Methode und Manager für CsvImportReport
authorSven Schöling <s.schoeling@linet-services.de>
Fri, 16 Nov 2012 10:37:33 +0000 (11:37 +0100)
committerSven Schöling <s.schoeling@linet-services.de>
Fri, 11 Jan 2013 12:57:43 +0000 (13:57 +0100)
SL/Auth.pm
SL/BackgroundJob/CsvImport.pm
SL/DB/CsvImportReport.pm
SL/DB/Manager/CsvImportReport.pm [new file with mode: 0644]

index d0e8c9a..3ef2660 100644 (file)
@@ -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();
 
index 98aed9c..5471add 100644 (file)
@@ -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__
index 1271c56..5b7acd2 100644 (file)
@@ -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 (file)
index 0000000..370a6c9
--- /dev/null
@@ -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;
+