summaryrefslogtreecommitdiffstats
path: root/application/controllers/JobsController.php
blob: 0df196be06b8c9ae1e2ddbdb9f717dd24f509bc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
// Icinga Web 2 X.509 Module | (c) 2018 Icinga GmbH | GPLv2

namespace Icinga\Module\X509\Controllers;

use Icinga\Exception\NotFoundError;
use Icinga\Module\X509\Forms\Config\JobConfigForm;
use Icinga\Module\X509\JobsIniRepository;
use Icinga\Web\Controller;
use Icinga\Web\Url;

class JobsController extends Controller
{
    /**
     * List all jobs
     */
    public function indexAction()
    {
        $this->view->tabs = $this->Module()->getConfigTabs()->activate('jobs');

        $repo = new JobsIniRepository();

        $this->view->jobs = $repo->select(array('name'));
    }

    /**
     * Create a job
     */
    public function newAction()
    {
        $form = $this->prepareForm()->add();

        $form->handleRequest();

        $this->renderForm($form, $this->translate('New Job'));
    }

    /**
     * Update a job
     */
    public function updateAction()
    {
        $form = $this->prepareForm()->edit($this->params->getRequired('name'));

        try {
            $form->handleRequest();
        } catch (NotFoundError $_) {
            $this->httpNotFound($this->translate('Job not found'));
        }

        $this->renderForm($form, $this->translate('Update Job'));
    }

    /**
     * Remove a job
     */
    public function removeAction()
    {
        $form = $this->prepareForm()->remove($this->params->getRequired('name'));

        try {
            $form->handleRequest();
        } catch (NotFoundError $_) {
            $this->httpNotFound($this->translate('Job not found'));
        }

        $this->renderForm($form, $this->translate('Remove Job'));
    }

    /**
     * Assert config permission and return a prepared RepositoryForm
     *
     * @return  JobConfigForm
     */
    protected function prepareForm()
    {
        $this->assertPermission('config/x509');

        return (new JobConfigForm())
            ->setRepository(new JobsIniRepository())
            ->setRedirectUrl(Url::fromPath('x509/jobs'));
    }
}