Kosmetik: Ausrichtung
[kivitendo-erp.git] / SL / Controller / TaskServer.pm
1 package SL::Controller::TaskServer;
2
3 use strict;
4
5 use parent qw(SL::Controller::Base);
6
7 use SL::Helper::Flash;
8 use SL::System::TaskServer;
9
10 use Rose::Object::MakeMethods::Generic
11 (
12   'scalar --get_set_init' => [ qw(task_server) ],
13 );
14
15 __PACKAGE__->run_before('check_auth');
16
17 #
18 # actions
19 #
20
21 sub action_show {
22   my ($self) = @_;
23
24   $::request->{layout}->use_stylesheet('background_jobs.css');
25
26   flash('warning', $::locale->text('The task server does not appear to be running.')) if !$self->task_server->is_running;
27
28   $self->render('task_server/show',
29                 title               => $::locale->text('Task server status'),
30                 last_command_output => $::auth->get_session_value('TaskServer::last_command_output'));
31 }
32
33 sub action_start {
34   my ($self) = @_;
35
36   if ($self->task_server->is_running) {
37     flash_later('error', $::locale->text('The task server is already running.'));
38
39   } else {
40     if ($self->task_server->start) {
41       flash_later('info', $::locale->text('The task server was started successfully.'));
42     } else {
43       flash_later('error', $::locale->text('Starting the task server failed.'));
44     }
45
46     $::auth->set_session_value('TaskServer::last_command_output' => $self->task_server->last_command_output);
47   }
48
49   $self->redirect_to(action => 'show');
50 }
51
52 sub action_stop {
53   my ($self) = @_;
54
55   if (!$self->task_server->is_running) {
56     flash_later('error', $::locale->text('The task server is not running.'));
57
58   } else {
59     if ($self->task_server->stop) {
60       flash_later('info', $::locale->text('The task server was stopped successfully.'));
61     } else {
62       flash_later('error', $::locale->text('Stopping the task server failed. Output:'));
63     }
64
65     $::auth->set_session_value('TaskServer::last_command_output' => $self->task_server->last_command_output);
66   }
67
68   $self->redirect_to(action => 'show');
69 }
70
71 #
72 # filters
73 #
74
75 sub check_auth {
76   $::auth->assert('admin');
77 }
78
79 #
80 # helpers
81 #
82
83 sub init_task_server {
84   return SL::System::TaskServer->new;
85 }
86
87 1;