1<?php
2/* Icinga Web 2 | (c) 2020 Icinga GmbH | GPLv2+ */
3
4namespace Icinga\Module\Setup\Requirement;
5
6use Icinga\Application\Icinga;
7use Icinga\Module\Setup\Requirement;
8
9class WebModuleRequirement extends Requirement
10{
11    protected function evaluate()
12    {
13        list($name, $op, $version) = $this->getCondition();
14
15        $mm = Icinga::app()->getModuleManager();
16        if (! $mm->hasInstalled($name)) {
17            $this->setStateText(sprintf(mt('setup', '%s is not installed'), $this->getAlias()));
18            return false;
19        }
20
21        $module = $mm->getModule($name, false);
22
23        $moduleVersion = $module->getVersion();
24        if ($moduleVersion[0] === 'v') {
25            $moduleVersion = substr($moduleVersion, 1);
26        }
27
28        $this->setStateText(sprintf(mt('setup', '%s version: %s'), $this->getAlias(), $moduleVersion));
29        return version_compare($moduleVersion, $version, $op);
30    }
31}
32