cleanup Methode und Manager für CsvImportReport
[kivitendo-erp.git] / SL / DB / Manager / CsvImportReport.pm
1 package SL::DB::Manager::CsvImportReport;
2
3 use strict;
4
5 use base qw(SL::DB::Helper::Manager);
6
7 sub object_class { 'SL::DB::CsvImportReport' }
8
9 __PACKAGE__->make_manager_methods;
10
11 sub cleanup {
12   my ($self) = @_;
13
14   $::auth->active_session_ids;
15
16   # get expired reports
17   my $objects = $self->get_all(query => [
18     session_id => [
19       not => [ $::auth->active_session_ids ]
20     ]
21   ]);
22
23   $_->destroy for @$objects;
24
25   # get reports for the active session that aren't the latest
26   $objects = $self->get_all(
27     query => [ session_id => $::auth->get_session_id, ],
28     order_by => [ 'id' ],
29   );
30
31   # skip the last one
32   for (0 .. $#$objects - 1) {
33     $objects->[$_]->destroy;
34   }
35 }
36
37 1;
38