ImportModifiers: friendlier errors on PHP 7.x

This commit is contained in:
Thomas Gelf 2018-01-25 13:13:42 +01:00
parent 81053e4efa
commit 53432c6d5c
3 changed files with 29 additions and 7 deletions

View File

@ -27,9 +27,14 @@ class ImportRowModifierForm extends DirectorObjectForm
$this->addElement('select', 'property_name', array( $this->addElement('select', 'property_name', array(
'label' => $this->translate('Property'), 'label' => $this->translate('Property'),
'description' => $this->translate('This must be an import source column (property)'), 'description' => $this->translate('This must be an import source column (property)'),
'multiOptions' => $this->optionalEnum($this->enumSourceColumns()),
'required' => true, 'required' => true,
)); ));
try {
$sourceColumns = $this->enumSourceColumns();
$this->getElement('property_name')->multiOptions = $this->optionalEnum($sourceColumns);
} catch (Exception $e) {
$this->getElement('property_name')->addError($e->getMessage());
}
$this->addElement('text', 'target_property', array( $this->addElement('text', 'target_property', array(
'label' => $this->translate('Target property'), 'label' => $this->translate('Target property'),
@ -57,7 +62,7 @@ class ImportRowModifierForm extends DirectorObjectForm
$error = $e->getMessage(); $error = $e->getMessage();
$mods = $this->optionalEnum(array()); $mods = $this->optionalEnum(array());
} }
$this->addElement('select', 'provider_class', array( $this->addElement('select', 'provider_class', array(
'label' => $this->translate('Modifier'), 'label' => $this->translate('Modifier'),
'required' => true, 'required' => true,

View File

@ -2,6 +2,7 @@
namespace Icinga\Module\Director\Objects; namespace Icinga\Module\Director\Objects;
use Icinga\Exception\ConfigurationError;
use Icinga\Module\Director\Data\Db\DbObjectWithSettings; use Icinga\Module\Director\Data\Db\DbObjectWithSettings;
use Icinga\Module\Director\Hook\PropertyModifierHook; use Icinga\Module\Director\Hook\PropertyModifierHook;
use Icinga\Module\Director\Objects\Extension\PriorityColumn; use Icinga\Module\Director\Objects\Extension\PriorityColumn;
@ -37,6 +38,9 @@ class ImportRowModifier extends DbObjectWithSettings
if ($this->hookInstance === null) { if ($this->hookInstance === null) {
$class = $this->get('provider_class'); $class = $this->get('provider_class');
/** @var PropertyModifierHook $obj */ /** @var PropertyModifierHook $obj */
if (! class_exists($class)) {
throw new ConfigurationError('Cannot instantiate Property modifier %s', $class);
}
$obj = new $class; $obj = new $class;
$obj->setSettings($this->getSettings()); $obj->setSettings($this->getSettings());
$obj->setTargetProperty($this->get('target_property')); $obj->setTargetProperty($this->get('target_property'));

View File

@ -2,6 +2,7 @@
namespace Icinga\Module\Director\Web\Table; namespace Icinga\Module\Director\Web\Table;
use Error;
use Exception; use Exception;
use Icinga\Module\Director\Hook\ImportSourceHook; use Icinga\Module\Director\Hook\ImportSourceHook;
use Icinga\Module\Director\Objects\ImportSource; use Icinga\Module\Director\Objects\ImportSource;
@ -73,11 +74,9 @@ class PropertymodifierTable extends ZfQueryBasedTable
$hook = new $class; $hook = new $class;
$caption .= ': ' . $hook->getName(); $caption .= ': ' . $hook->getName();
} catch (Exception $e) { } catch (Exception $e) {
$caption = [ $caption = $this->createErrorCaption($caption, $e);
$caption, } catch (Error $e) {
': ', $caption = $this->createErrorCaption($caption, $e);
$this::tag('span', ['class' => 'error'], $e->getMessage())
];
} }
} else { } else {
$caption .= ': ' . $row->description; $caption .= ': ' . $row->description;
@ -94,6 +93,20 @@ class PropertymodifierTable extends ZfQueryBasedTable
); );
} }
/**
* @param $caption
* @param Exception|Error $e
* @return array
*/
protected function createErrorCaption($caption, $e)
{
return [
$caption,
': ',
$this::tag('span', ['class' => 'error'], $e->getMessage())
];
}
public function getColumnsToBeRendered() public function getColumnsToBeRendered()
{ {
return [ return [