summaryrefslogtreecommitdiffstats
path: root/modules/setup/application/controllers/IndexController.php
blob: b75643cc9539b324783a00747cb81922430d9df8 (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
84
85
86
87
88
89
90
91
<?php
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */

namespace Icinga\Module\Setup\Controllers;

use Icinga\Module\Setup\WebWizard;
use Icinga\Web\Controller;
use Icinga\Web\Form;
use Icinga\Web\Url;

class IndexController extends Controller
{
    /**
     * Whether the controller requires the user to be authenticated
     *
     * FALSE as the wizard uses token authentication
     *
     * @var bool
     */
    protected $requiresAuthentication = false;

    /**
     * {@inheritdoc}
     */
    protected $innerLayout = 'inline';

    /**
     * Show the web wizard and run the configuration once finished
     */
    public function indexAction()
    {
        $wizard = new WebWizard();

        if ($wizard->isFinished()) {
            $setup = $wizard->getSetup();
            $success = $setup->run();
            if ($success) {
                $wizard->clearSession();
            } else {
                $wizard->setIsFinished(false);
            }

            $this->view->success = $success;
            $this->view->report = $setup->getReport();
        } else {
            $wizard->handleRequest();

            $restartForm = new Form();
            $restartForm->setUidDisabled();
            $restartForm->setName('setup_restart_form');
            $restartForm->setAction(Url::fromPath('setup/index/restart'));
            $restartForm->setAttrib('class', 'restart-form');
            $restartForm->addElement(
                'button',
                'btn_submit',
                array(
                    'type'          => 'submit',
                    'value'         => 'btn_submit',
                    'escape'        => false,
                    'label'         => $this->view->icon('reply-all'),
                    'title'         => $this->translate('Restart the setup'),
                    'decorators'    => array('ViewHelper')
                )
            );

            $this->view->restartForm = $restartForm;
        }

        $this->view->wizard = $wizard;
        $this->view->title = $this->translate('Setup') . ' :: ' . $this->view->defaultTitle;
    }

    /**
     * Reset session and restart the wizard
     */
    public function restartAction()
    {
        $this->assertHttpMethod('POST');

        $form = new Form(array(
            'onSuccess' => function () {
                $wizard = new WebWizard();
                $wizard->clearSession(false);
            }
        ));
        $form->setUidDisabled();
        $form->setRedirectUrl('setup');
        $form->setSubmitLabel('btn_submit');
        $form->handleRequest();
    }
}