mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-27 15:54:03 +02:00
ImportModifiers: friendlier errors on PHP 7.x
This commit is contained in:
parent
81053e4efa
commit
53432c6d5c
@ -27,9 +27,14 @@ class ImportRowModifierForm extends DirectorObjectForm
|
||||
$this->addElement('select', 'property_name', array(
|
||||
'label' => $this->translate('Property'),
|
||||
'description' => $this->translate('This must be an import source column (property)'),
|
||||
'multiOptions' => $this->optionalEnum($this->enumSourceColumns()),
|
||||
'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(
|
||||
'label' => $this->translate('Target property'),
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Icinga\Module\Director\Objects;
|
||||
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Module\Director\Data\Db\DbObjectWithSettings;
|
||||
use Icinga\Module\Director\Hook\PropertyModifierHook;
|
||||
use Icinga\Module\Director\Objects\Extension\PriorityColumn;
|
||||
@ -37,6 +38,9 @@ class ImportRowModifier extends DbObjectWithSettings
|
||||
if ($this->hookInstance === null) {
|
||||
$class = $this->get('provider_class');
|
||||
/** @var PropertyModifierHook $obj */
|
||||
if (! class_exists($class)) {
|
||||
throw new ConfigurationError('Cannot instantiate Property modifier %s', $class);
|
||||
}
|
||||
$obj = new $class;
|
||||
$obj->setSettings($this->getSettings());
|
||||
$obj->setTargetProperty($this->get('target_property'));
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use Error;
|
||||
use Exception;
|
||||
use Icinga\Module\Director\Hook\ImportSourceHook;
|
||||
use Icinga\Module\Director\Objects\ImportSource;
|
||||
@ -73,11 +74,9 @@ class PropertymodifierTable extends ZfQueryBasedTable
|
||||
$hook = new $class;
|
||||
$caption .= ': ' . $hook->getName();
|
||||
} catch (Exception $e) {
|
||||
$caption = [
|
||||
$caption,
|
||||
': ',
|
||||
$this::tag('span', ['class' => 'error'], $e->getMessage())
|
||||
];
|
||||
$caption = $this->createErrorCaption($caption, $e);
|
||||
} catch (Error $e) {
|
||||
$caption = $this->createErrorCaption($caption, $e);
|
||||
}
|
||||
} else {
|
||||
$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()
|
||||
{
|
||||
return [
|
||||
|
Loading…
x
Reference in New Issue
Block a user