Merge branch 'master' of vc.linet-services.de:public/lx-office-erp
[kivitendo-erp.git] / SL / Controller / BackgroundJobHistory.pm
1 package SL::Controller::BackgroundJobHistory;
2
3 use strict;
4
5 use parent qw(SL::Controller::Base);
6
7 use SL::Controller::Helper::GetModels;
8 use SL::Controller::Helper::Paginated;
9 use SL::Controller::Helper::Sorted;
10 use SL::DB::BackgroundJobHistory;
11 use SL::Helper::Flash;
12 use SL::System::TaskServer;
13
14 use Rose::Object::MakeMethods::Generic
15 (
16   scalar                  => [ qw(history) ],
17   'scalar --get_set_init' => [ qw(task_server) ],
18 );
19
20 __PACKAGE__->run_before('check_auth');
21 __PACKAGE__->run_before('add_stylesheet');
22 __PACKAGE__->run_before('check_task_server');
23
24 __PACKAGE__->make_paginated(ONLY => [ qw(list) ]);
25
26 __PACKAGE__->make_sorted(
27   ONLY         => [ qw(list) ],
28
29   package_name => $::locale->text('Package name'),
30   run_at       => $::locale->text('Run at'),
31   status       => $::locale->text('Execution status'),
32   result       => $::locale->text('Result'),
33   error        => $::locale->text('Error'),
34 );
35
36 #
37 # actions
38 #
39
40 sub action_list {
41   my ($self) = @_;
42
43   $self->render('background_job_history/list',
44                 title   => $::locale->text('Background job history'),
45                 ENTRIES => $self->get_models);
46 }
47
48 sub action_show {
49   my ($self) = @_;
50
51   my $back_to = $::form->{back_to} || $self->url_for(action => 'list');
52
53   $self->history(SL::DB::BackgroundJobHistory->new(id => $::form->{id})->load);
54   $self->render('background_job_history/show',
55                 title   => $::locale->text('View background job execution result'),
56                 back_to => $back_to);
57 }
58
59 #
60 # filters
61 #
62
63 sub check_auth {
64   $::auth->assert('admin');
65 }
66
67 #
68 # helpers
69 #
70
71 sub init_task_server {
72   return SL::System::TaskServer->new;
73 }
74
75 sub check_task_server {
76   my ($self) = @_;
77   flash('warning', $::locale->text('The task server does not appear to be running.')) if !$self->task_server->is_running;
78 }
79
80 sub add_stylesheet {
81   $::form->use_stylesheet('lx-office-erp/background_jobs.css');
82 }
83
84 1;