summaryrefslogtreecommitdiffstats
path: root/library/Icingadb/Setup/RedisPage.php
blob: 3c0a74135d08b70a70376e464b7206b946921b3e (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
<?php

/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Icingadb\Setup;

use Icinga\Module\Icingadb\Forms\RedisConfigForm;
use Icinga\Web\Form;

class RedisPage extends Form
{
    public function init()
    {
        $this->setName('setup_icingadb_redis');
        $this->setTitle(t('Icinga DB Redis'));
        $this->addDescription(t(
            'Please fill out the connection details to access the Icinga DB Redis.'
        ));
        $this->setValidatePartial(true);
    }

    public function createElements(array $formData)
    {
        $redisConfigForm = new RedisConfigForm();
        $redisConfigForm->createElements($formData);
        if (isset($formData['redis_tls']) && $formData['redis_tls']) {
            $redisConfigForm->getElement('redis_ca_pem')->setIgnore(false);
            $redisConfigForm->getElement('redis_cert_pem')->setIgnore(false);
            $redisConfigForm->getElement('redis_key_pem')->setIgnore(false);
        }

        $this->addElements($redisConfigForm->getElements());
        $this->addDisplayGroups($redisConfigForm->getDisplayGroups());
    }

    public function isValid($formData)
    {
        if (! parent::isValid($formData)) {
            return false;
        }

        if (($el = $this->getElement('skip_validation')) === null || ! $el->isChecked()) {
            if (! RedisConfigForm::checkRedis($this)) {
                if ($el === null) {
                    RedisConfigForm::addSkipValidationCheckbox($this);
                    RedisConfigForm::addInsecureCheckboxIfTls($this);
                }

                return false;
            }
        }

        return true;
    }

    public function isValidPartial(array $formData)
    {
        if (! parent::isValidPartial($formData)) {
            return false;
        }

        if (isset($formData['backend_validation'])) {
            return RedisConfigForm::checkRedis($this);
        }

        return true;
    }
}