Allow to manually validate the configuration in the wizard as well

It's a mess...
This commit is contained in:
Johannes Meyer 2015-07-29 10:52:32 +02:00
parent 83aafe8cda
commit e8af4295b1
6 changed files with 207 additions and 0 deletions

View File

@ -21,6 +21,7 @@ class IdoResourcePage extends Form
$this->addDescription($this->translate( $this->addDescription($this->translate(
'Please fill out the connection details below to access the IDO database of your monitoring environment.' 'Please fill out the connection details below to access the IDO database of your monitoring environment.'
)); ));
$this->setValidatePartial(true);
} }
/** /**
@ -96,6 +97,52 @@ class IdoResourcePage extends Form
return true; return true;
} }
/**
* Run the configured backend's inspection checks and show the result, if necessary
*
* This will only run any validation if the user pushed the 'backend_validation' button.
*
* @param array $formData
*
* @return bool
*/
public function isValidPartial(array $formData)
{
if (isset($formData['backend_validation']) && parent::isValid($formData)) {
$inspection = ResourceConfigForm::inspectResource($this);
if ($inspection !== null) {
$join = function ($e) use (& $join) {
return is_string($e) ? $e : join("\n", array_map($join, $e));
};
$this->addElement(
'note',
'inspection_output',
array(
'order' => 0,
'value' => '<strong>' . $this->translate('Validation Log') . "</strong>\n\n"
. join("\n", array_map($join, $inspection->toArray())),
'decorators' => array(
'ViewHelper',
array('HtmlTag', array('tag' => 'pre', 'class' => 'log-output')),
)
)
);
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.'));
}
return true;
}
/** /**
* Add a checkbox to the form by which the user can skip the resource validation * Add a checkbox to the form by which the user can skip the resource validation
* *

View File

@ -114,6 +114,19 @@ class MonitoringWizard extends Wizard implements SetupWizard
mt('monitoring', 'Setup the monitoring module for Icinga Web 2', 'setup.summary.btn.finish') mt('monitoring', 'Setup the monitoring module for Icinga Web 2', 'setup.summary.btn.finish')
); );
} }
if ($page->getName() === 'setup_monitoring_ido') {
$page->addElement(
'submit',
'backend_validation',
array(
'ignore' => true,
'label' => t('Validate Configuration'),
'decorators' => array('ViewHelper')
)
);
$page->getDisplayGroup('buttons')->addElement($page->getElement('backend_validation'));
}
} }
/** /**

View File

@ -30,6 +30,7 @@ class AuthBackendPage extends Form
{ {
$this->setName('setup_authentication_backend'); $this->setName('setup_authentication_backend');
$this->setTitle($this->translate('Authentication Backend', 'setup.page.title')); $this->setTitle($this->translate('Authentication Backend', 'setup.page.title'));
$this->setValidatePartial(true);
} }
/** /**
@ -150,6 +151,54 @@ class AuthBackendPage extends Form
return true; return true;
} }
/**
* Run the configured backend's inspection checks and show the result, if necessary
*
* This will only run any validation if the user pushed the 'backend_validation' button.
*
* @param array $formData
*
* @return bool
*/
public function isValidPartial(array $formData)
{
if (isset($formData['backend_validation']) && parent::isValid($formData)) {
$self = clone $this;
$self->getSubForm('backend_form')->getElement('resource')->setIgnore(false);
$inspection = UserBackendConfigForm::inspectUserBackend($self);
if ($inspection !== null) {
$join = function ($e) use (& $join) {
return is_string($e) ? $e : join("\n", array_map($join, $e));
};
$this->addElement(
'note',
'inspection_output',
array(
'order' => 0,
'value' => '<strong>' . $this->translate('Validation Log') . "</strong>\n\n"
. join("\n", array_map($join, $inspection->toArray())),
'decorators' => array(
'ViewHelper',
array('HtmlTag', array('tag' => 'pre', 'class' => 'log-output')),
)
)
);
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.'));
}
return true;
}
/** /**
* Add a checkbox to this form by which the user can skip the authentication validation * Add a checkbox to this form by which the user can skip the authentication validation
*/ */

View File

@ -23,6 +23,7 @@ class DbResourcePage extends Form
'Now please configure your database resource. Note that the database itself does not need to' 'Now please configure your database resource. Note that the database itself does not need to'
. ' exist at this time as it is going to be created once the wizard is about to be finished.' . ' exist at this time as it is going to be created once the wizard is about to be finished.'
)); ));
$this->setValidatePartial(true);
} }
/** /**
@ -84,6 +85,35 @@ class DbResourcePage extends Form
return true; return true;
} }
/**
* Check whether it's possible to connect to the database server
*
* This will only run the check if the user pushed the 'backend_validation' button.
*
* @param array $formData
*
* @return bool
*/
public function isValidPartial(array $formData)
{
if (isset($formData['backend_validation']) && parent::isValid($formData)) {
try {
$db = new DbTool($this->getValues());
$db->checkConnectivity();
} catch (PDOException $e) {
$this->warning(sprintf(
$this->translate('Failed to successfully validate the configuration: %s'),
$e->getMessage()
));
return false;
}
$this->info($this->translate('The configuration has been successfully validated.'));
}
return true;
}
/** /**
* 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 connection validation
*/ */

View File

@ -23,6 +23,7 @@ class LdapResourcePage extends Form
'Now please configure your AD/LDAP resource. This will later ' 'Now please configure your AD/LDAP resource. This will later '
. 'be used to authenticate users logging in to Icinga Web 2.' . 'be used to authenticate users logging in to Icinga Web 2.'
)); ));
$this->setValidatePartial(true);
} }
/** /**
@ -82,6 +83,52 @@ class LdapResourcePage extends Form
return true; return true;
} }
/**
* Run the configured backend's inspection checks and show the result, if necessary
*
* This will only run any validation if the user pushed the 'backend_validation' button.
*
* @param array $formData
*
* @return bool
*/
public function isValidPartial(array $formData)
{
if (isset($formData['backend_validation']) && parent::isValid($formData)) {
$inspection = ResourceConfigForm::inspectResource($this);
if ($inspection !== null) {
$join = function ($e) use (& $join) {
return is_string($e) ? $e : join("\n", array_map($join, $e));
};
$this->addElement(
'note',
'inspection_output',
array(
'order' => 0,
'value' => '<strong>' . $this->translate('Validation Log') . "</strong>\n\n"
. join("\n", array_map($join, $inspection->toArray())),
'decorators' => array(
'ViewHelper',
array('HtmlTag', array('tag' => 'pre', 'class' => 'log-output')),
)
)
);
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.'));
}
return true;
}
/** /**
* 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 connection validation
*/ */

View File

@ -296,6 +296,27 @@ class WebWizard extends Wizard implements SetupWizard
} elseif ($index === count($pages) - 1) { } elseif ($index === count($pages) - 1) {
$page->getElement(static::BTN_NEXT)->setLabel(mt('setup', 'Setup Icinga Web 2', 'setup.summary.btn.finish')); $page->getElement(static::BTN_NEXT)->setLabel(mt('setup', 'Setup Icinga Web 2', 'setup.summary.btn.finish'));
} }
$authData = $this->getPageData('setup_authentication_type');
$veto = $page->getName() === 'setup_authentication_backend' && $authData['type'] === 'db';
if (! $veto && in_array($page->getName(), array(
'setup_authentication_backend',
'setup_auth_db_resource',
'setup_config_db_resource',
'setup_ldap_resource',
'setup_monitoring_ido'
))) {
$page->addElement(
'submit',
'backend_validation',
array(
'ignore' => true,
'label' => t('Validate Configuration'),
'decorators' => array('ViewHelper')
)
);
$page->getDisplayGroup('buttons')->addElement($page->getElement('backend_validation'));
}
} }
/** /**