summaryrefslogtreecommitdiffstats
path: root/modules/setup/library/Setup/Requirement/ConfigDirectoryRequirement.php
blob: 7e9044cfb2f51cb7f663e32cb814302b66e10f7e (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
<?php
/* Icinga Web 2 | (c) 2015 Icinga Development Team | GPLv2+ */

namespace Icinga\Module\Setup\Requirement;

use Icinga\Module\Setup\Requirement;

class ConfigDirectoryRequirement extends Requirement
{
    public function getTitle()
    {
        $title = parent::getTitle();
        if ($title === null) {
            return mt('setup', 'Read- and writable configuration directory');
        }

        return $title;
    }

    protected function evaluate()
    {
        $path = $this->getCondition();
        if (file_exists($path)) {
            $readable = is_readable($path);
            if ($readable && is_writable($path)) {
                $this->setStateText(sprintf(mt('setup', 'The directory %s is read- and writable.'), $path));
                return true;
            } else {
                $this->setStateText(sprintf(
                    $readable
                        ? mt('setup', 'The directory %s is not writable.')
                        : mt('setup', 'The directory %s is not readable.'),
                    $path
                ));
                return false;
            }
        } else {
            $this->setStateText(sprintf(mt('setup', 'The directory %s does not exist.'), $path));
            return false;
        }
    }
}