From b3e6b2755c4e0fea99ceda036deadf6caddeb404 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 24 Jul 2015 11:45:49 +0200 Subject: [PATCH] UserBackendConfigForm: Replace isValid- with inspectUserBackend() refs #7588 --- .../forms/Config/UserBackendConfigForm.php | 24 +++++++++---------- .../application/forms/AuthBackendPage.php | 4 +++- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/application/forms/Config/UserBackendConfigForm.php b/application/forms/Config/UserBackendConfigForm.php index 0afc54a44..d811cc16b 100644 --- a/application/forms/Config/UserBackendConfigForm.php +++ b/application/forms/Config/UserBackendConfigForm.php @@ -11,6 +11,7 @@ use Icinga\Exception\IcingaException; use Icinga\Exception\NotFoundError; use Icinga\Data\ConfigObject; use Icinga\Data\Inspectable; +use Icinga\Data\Inspection; use Icinga\Forms\ConfigForm; use Icinga\Forms\Config\UserBackend\ExternalBackendForm; use Icinga\Forms\Config\UserBackend\DbBackendForm; @@ -348,8 +349,9 @@ class UserBackendConfigForm extends ConfigForm } if (($el = $this->getElement('skip_validation')) === null || false === $el->isChecked()) { - $backendForm = $this->getBackendForm($this->getValue('type')); - if (! static::isValidUserBackend($this)) { + $inspection = static::inspectUserBackend($this); + if ($inspection && $inspection->hasError()) { + $this->error($inspection->getError()); if ($el === null) { $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())); if ($backend instanceof Inspectable) { - $inspection = $backend->inspect(); - if ($inspection->hasError()) { - $form->error($inspection->getError()); - return false; - } + return $backend->inspect(); } - - return true; } /** diff --git a/modules/setup/application/forms/AuthBackendPage.php b/modules/setup/application/forms/AuthBackendPage.php index 06a2fec2c..ceeb08ed7 100644 --- a/modules/setup/application/forms/AuthBackendPage.php +++ b/modules/setup/application/forms/AuthBackendPage.php @@ -146,7 +146,9 @@ class AuthBackendPage extends Form 'value' => $this->getResourceConfig() ) ); - if (! UserBackendConfigForm::isValidUserBackend($self)) { + $inspection = UserBackendConfigForm::inspectUserBackend($self); + if ($inspection && $inspection->hasError()) { + $this->error($inspection->getError()); $this->addSkipValidationCheckbox(); return false; }