UserBackendConfigForm: Replace isValid- with inspectUserBackend()

refs #7588
This commit is contained in:
Johannes Meyer 2015-07-24 11:45:49 +02:00
parent e06281a427
commit b3e6b2755c
2 changed files with 14 additions and 14 deletions

View File

@ -11,6 +11,7 @@ use Icinga\Exception\IcingaException;
use Icinga\Exception\NotFoundError; use Icinga\Exception\NotFoundError;
use Icinga\Data\ConfigObject; use Icinga\Data\ConfigObject;
use Icinga\Data\Inspectable; use Icinga\Data\Inspectable;
use Icinga\Data\Inspection;
use Icinga\Forms\ConfigForm; use Icinga\Forms\ConfigForm;
use Icinga\Forms\Config\UserBackend\ExternalBackendForm; use Icinga\Forms\Config\UserBackend\ExternalBackendForm;
use Icinga\Forms\Config\UserBackend\DbBackendForm; use Icinga\Forms\Config\UserBackend\DbBackendForm;
@ -348,8 +349,9 @@ class UserBackendConfigForm extends ConfigForm
} }
if (($el = $this->getElement('skip_validation')) === null || false === $el->isChecked()) { if (($el = $this->getElement('skip_validation')) === null || false === $el->isChecked()) {
$backendForm = $this->getBackendForm($this->getValue('type')); $inspection = static::inspectUserBackend($this);
if (! static::isValidUserBackend($this)) { if ($inspection && $inspection->hasError()) {
$this->error($inspection->getError());
if ($el === null) { if ($el === null) {
$this->addSkipValidationCheckbox(); $this->addSkipValidationCheckbox();
} }
@ -362,24 +364,20 @@ class UserBackendConfigForm extends ConfigForm
} }
/** /**
* Validate the configuration by creating a backend and running its inspection checks * Create a user backend by using the given form's values and return its inspection results
* *
* @param Form $form The form to fetch the configuration values from * Returns null for non-inspectable backends.
* *
* @return bool Whether inspection succeeded or not * @param Form $form
*
* @return Inspection|null
*/ */
public static function isValidUserBackend(Form $form) public static function inspectUserBackend(Form $form)
{ {
$backend = UserBackend::create(null, new ConfigObject($form->getValues())); $backend = UserBackend::create(null, new ConfigObject($form->getValues()));
if ($backend instanceof Inspectable) { if ($backend instanceof Inspectable) {
$inspection = $backend->inspect(); return $backend->inspect();
if ($inspection->hasError()) {
$form->error($inspection->getError());
return false;
}
} }
return true;
} }
/** /**

View File

@ -146,7 +146,9 @@ class AuthBackendPage extends Form
'value' => $this->getResourceConfig() 'value' => $this->getResourceConfig()
) )
); );
if (! UserBackendConfigForm::isValidUserBackend($self)) { $inspection = UserBackendConfigForm::inspectUserBackend($self);
if ($inspection && $inspection->hasError()) {
$this->error($inspection->getError());
$this->addSkipValidationCheckbox(); $this->addSkipValidationCheckbox();
return false; return false;
} }