Skip to content

Commit

Permalink
Fix overwritte default-values in forms and connection validation
Browse files Browse the repository at this point in the history
refs #6141
  • Loading branch information
majentsch committed May 28, 2014
1 parent 5e1729d commit ec096c3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
5 changes: 3 additions & 2 deletions application/forms/Config/Resource/DbResourceForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ public function getConfig()
*
* @return bool
*/
public function isValidResource($data)
public function isValidResource()
{
try {
$config = $this->createConfig($data);
$config = $this->getConfig();
/*
* It should be possible to run icingaweb without the pgsql or mysql extension or Zend-Pdo-Classes,
* in case they aren't actually used. When the user tries to create a resource that depends on an
Expand All @@ -164,5 +164,6 @@ public function isValidResource($data)
$this->addErrorMessage(t('Connectivity validation failed, connection to the given resource not possible.'));
return false;
}
return true;
}
}
1 change: 1 addition & 0 deletions application/forms/Config/Resource/FileResourceForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
namespace Icinga\Form\Config\Resource;

use Icinga\Web\Form;
use Zend_Config;

/**
* Contains the properties needed to create a basic LDAP resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Exception;
use Icinga\Web\Form;
use Zend_Config;
use Icinga\Data\ResourceFactory;

/**
* Contains the properties needed to create a basic LDAP resource.
Expand Down
16 changes: 14 additions & 2 deletions application/forms/Config/Resource/ResourceBaseForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Icinga\Data\ResourceFactory;
use Icinga\Web\Form;
use Zend_Config;
use Exception;

class ResourceBaseForm extends Form {

Expand Down Expand Up @@ -75,15 +76,26 @@ public function getConfig()
return new Zend_Config($result);
}

public function isValid($data)
{
foreach ($this->getElements() as $key => $element) {
// Initialize all empty elements with their default values.
if (!isset($data[$key])) {
$data[$key] = $element->getValue();
}
}
return parent::isValid($data);
}

/**
* Return if this resource is usable by icingaweb
*
* For abstract resources, this will perform a simple connectivity test
*
* @return bool
*/
public function isValidResource($data) {
$config = $this->createConfig($data);
public function isValidResource() {
$config = $this->getConfig();
try {
$resource = ResourceFactory::createResource($config);
$resource->connect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function isValidResource()
);
return false;
}
return true;
}

public function getConfig()
Expand Down
4 changes: 2 additions & 2 deletions application/forms/Config/ResourceForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ public function isValid($data)
if (isset($data['resource_force_creation']) && $data['resource_force_creation']) {
return true;
}
var_dump($data);
if ($data['resource_type_old'] === $data['resource_type']) {
if (!$this->isValidResource($data)) {
$this->addForceCreationCheckbox();
Expand All @@ -295,8 +296,7 @@ public function isValid($data)
*/
public function isValidResource()
{
$data = $this->getValues();
$valid = $this->resourceSubForm->isValidResource($data);
$valid = $this->resourceSubForm->isValidResource();
$this->addErrorMessages($this->resourceSubForm->getErrorMessages());
return $valid;
}
Expand Down

0 comments on commit ec096c3

Please sign in to comment.