IdoResourcePage: Validate the version of a PostgreSQL server
refs #9460
This commit is contained in:
parent
9282e1bce2
commit
b7a389601d
|
@ -8,6 +8,7 @@ use Icinga\Forms\Config\ResourceConfigForm;
|
|||
use Icinga\Forms\Config\Resource\DbResourceForm;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Module\Monitoring\Forms\Config\BackendConfigForm;
|
||||
use Icinga\Module\Setup\Utils\DbTool;
|
||||
|
||||
class IdoResourcePage extends Form
|
||||
{
|
||||
|
@ -73,23 +74,8 @@ class IdoResourcePage extends Form
|
|||
}
|
||||
|
||||
if (! isset($formData['skip_validation']) || !$formData['skip_validation']) {
|
||||
$inspection = ResourceConfigForm::inspectResource($this);
|
||||
if ($inspection !== null && $inspection->hasError()) {
|
||||
$this->error($inspection->getError());
|
||||
$this->addSkipValidationCheckbox($this->translate(
|
||||
'Check this to not to validate connectivity with the given database server.'
|
||||
));
|
||||
return false;
|
||||
}
|
||||
|
||||
$configObject = new ConfigObject($this->getValues());
|
||||
if (
|
||||
! BackendConfigForm::isValidIdoSchema($this, $configObject)
|
||||
|| !BackendConfigForm::isValidIdoInstance($this, $configObject)
|
||||
) {
|
||||
$this->addSkipValidationCheckbox($this->translate(
|
||||
'Check this to not to validate the IDO schema in the given database.'
|
||||
));
|
||||
if (! $this->validateConfiguration()) {
|
||||
$this->addSkipValidationCheckbox();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -109,8 +95,31 @@ class IdoResourcePage extends Form
|
|||
public function isValidPartial(array $formData)
|
||||
{
|
||||
if (isset($formData['backend_validation']) && parent::isValid($formData)) {
|
||||
$inspection = ResourceConfigForm::inspectResource($this);
|
||||
if ($inspection !== null) {
|
||||
if (! $this->validateConfiguration(true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->info($this->translate('The configuration has been successfully validated.'));
|
||||
} elseif (! isset($formData['backend_validation'])) {
|
||||
// This is usually done by isValid(Partial), but as we're not calling any of these...
|
||||
$this->populate($formData);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the configuration is valid
|
||||
*
|
||||
* @param bool $showLog Whether to show the validation log
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function validateConfiguration($showLog = false)
|
||||
{
|
||||
$inspection = ResourceConfigForm::inspectResource($this);
|
||||
if ($inspection !== null) {
|
||||
if ($showLog) {
|
||||
$join = function ($e) use (& $join) {
|
||||
return is_string($e) ? $e : join("\n", array_map($join, $e));
|
||||
};
|
||||
|
@ -127,45 +136,53 @@ class IdoResourcePage extends Form
|
|||
)
|
||||
)
|
||||
);
|
||||
|
||||
if ($inspection->hasError()) {
|
||||
$this->warning(sprintf(
|
||||
$this->translate('Failed to successfully validate the configuration: %s'),
|
||||
$inspection->getError()
|
||||
));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->info($this->translate('The configuration has been successfully validated.'));
|
||||
} elseif (! isset($formData['backend_validation'])) {
|
||||
// This is usually done by isValid(Partial), but as we're not calling any of these...
|
||||
$this->populate($formData);
|
||||
if ($inspection->hasError()) {
|
||||
$this->error(sprintf(
|
||||
$this->translate('Failed to successfully validate the configuration: %s'),
|
||||
$inspection->getError()
|
||||
));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$configObject = new ConfigObject($this->getValues());
|
||||
if (
|
||||
! BackendConfigForm::isValidIdoSchema($this, $configObject)
|
||||
|| !BackendConfigForm::isValidIdoInstance($this, $configObject)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->getValue('db') === 'pgsql') {
|
||||
$db = new DbTool($this->getValues());
|
||||
$version = $db->connectToDb()->getServerVersion();
|
||||
if (version_compare($version, '9.1', '<')) {
|
||||
$this->error($this->translate(sprintf(
|
||||
'The server\'s version %s is too old. The minimum required version is %s.',
|
||||
$version,
|
||||
'9.1'
|
||||
)));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a checkbox to the form by which the user can skip the resource validation
|
||||
*
|
||||
* @param string $description
|
||||
* Add a checkbox to the form by which the user can skip the configuration validation
|
||||
*/
|
||||
protected function addSkipValidationCheckbox($description = null)
|
||||
protected function addSkipValidationCheckbox()
|
||||
{
|
||||
if (empty($description)) {
|
||||
$description = $this->translate(
|
||||
'Proceed without any further (custom) validation.'
|
||||
);
|
||||
}
|
||||
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
'skip_validation',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => $this->translate('Skip Validation'),
|
||||
'description' => $description
|
||||
'description' => $this->translate('Check this to not to validate the configuration')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ class DbResourcePage extends Form
|
|||
}
|
||||
|
||||
/**
|
||||
* Add a checkbox to the form by which the user can skip the connection validation
|
||||
* Add a checkbox to the form by which the user can skip the configuration validation
|
||||
*/
|
||||
protected function addSkipValidationCheckbox()
|
||||
{
|
||||
|
@ -161,9 +161,7 @@ class DbResourcePage extends Form
|
|||
array(
|
||||
'required' => true,
|
||||
'label' => $this->translate('Skip Validation'),
|
||||
'description' => $this->translate(
|
||||
'Check this to not to validate connectivity with the given database server'
|
||||
)
|
||||
'description' => $this->translate('Check this to not to validate the configuration')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue