mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 08:14:04 +02:00
Merge branch 'bugfix/form-handling-13583'
This commit is contained in:
commit
ae6c73b947
@ -53,6 +53,7 @@ abstract class DirectorObjectForm extends QuickForm
|
|||||||
'imports',
|
'imports',
|
||||||
'check_command',
|
'check_command',
|
||||||
'check_command_id',
|
'check_command_id',
|
||||||
|
'has_agent',
|
||||||
'command',
|
'command',
|
||||||
'command_id',
|
'command_id',
|
||||||
'event_command',
|
'event_command',
|
||||||
@ -83,12 +84,13 @@ abstract class DirectorObjectForm extends QuickForm
|
|||||||
*
|
*
|
||||||
* @return DbObject|DbObjectWithSettings|IcingaObject
|
* @return DbObject|DbObjectWithSettings|IcingaObject
|
||||||
*/
|
*/
|
||||||
protected function object($values = array())
|
protected function object()
|
||||||
{
|
{
|
||||||
if ($this->object === null) {
|
if ($this->object === null) {
|
||||||
|
$values = array();
|
||||||
/** @var DbObject|IcingaObject $class */
|
/** @var DbObject|IcingaObject $class */
|
||||||
$class = $this->getObjectClassname();
|
$class = $this->getObjectClassname();
|
||||||
if ($this->preferredObjectType && ! array_key_exists('object_type', $values)) {
|
if ($this->preferredObjectType) {
|
||||||
$values['object_type'] = $this->preferredObjectType;
|
$values['object_type'] = $this->preferredObjectType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +104,6 @@ abstract class DirectorObjectForm extends QuickForm
|
|||||||
if (! $this->object->hasConnection()) {
|
if (! $this->object->hasConnection()) {
|
||||||
$this->object->setConnection($this->db);
|
$this->object->setConnection($this->db);
|
||||||
}
|
}
|
||||||
$this->object->setProperties($values);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->object;
|
return $this->object;
|
||||||
@ -130,13 +131,15 @@ abstract class DirectorObjectForm extends QuickForm
|
|||||||
if ($el = $this->getElement($key)) {
|
if ($el = $this->getElement($key)) {
|
||||||
if (array_key_exists($key, $post)) {
|
if (array_key_exists($key, $post)) {
|
||||||
$this->populate(array($key => $post[$key]));
|
$this->populate(array($key => $post[$key]));
|
||||||
|
$old = null;
|
||||||
try {
|
try {
|
||||||
$old = $object->get($key);
|
$old = $object->get($key);
|
||||||
$object->set($key, $el->getValue());
|
$object->set($key, $el->getValue());
|
||||||
$object->resolveUnresolvedRelatedProperties();
|
$object->resolveUnresolvedRelatedProperties();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$object->set($key, $old);
|
if ($old !== null) {
|
||||||
|
$object->set($key, $old);
|
||||||
|
}
|
||||||
$this->addException($e, $key);
|
$this->addException($e, $key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -258,42 +261,27 @@ abstract class DirectorObjectForm extends QuickForm
|
|||||||
|
|
||||||
protected function handleProperties(DbObject $object, & $values)
|
protected function handleProperties(DbObject $object, & $values)
|
||||||
{
|
{
|
||||||
$resolve = $this->assertResolvedImports();
|
|
||||||
if ($this->hasBeenSent()) {
|
if ($this->hasBeenSent()) {
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
if (in_array($key, $this->earlyProperties) || substr($key, 0, 4) === 'var_') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$object->set($key, $value);
|
if ($object->hasProperty($key)) {
|
||||||
if ($object instanceof IcingaObject) {
|
$object->set($key, $value);
|
||||||
$object->resolveUnresolvedRelatedProperties();
|
if ($object instanceof IcingaObject) {
|
||||||
|
$object->resolveUnresolvedRelatedProperties();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->addException($e, $key);
|
$this->addException($e, $key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($object instanceof IcingaObject) {
|
protected function loadInheritedProperties()
|
||||||
$props = (array) $object->toPlainObject(
|
{
|
||||||
false,
|
if ($this->assertResolvedImports()) {
|
||||||
false,
|
|
||||||
null,
|
|
||||||
true // is default//false // Do not resolve IDs
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$props = $object->getProperties();
|
|
||||||
unset($props['vars']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->setDefaults($this->removeEmptyProperties($props));
|
|
||||||
|
|
||||||
if ($resolve) {
|
|
||||||
try {
|
try {
|
||||||
$this->showInheritedProperties($object);
|
$this->showInheritedProperties($this->object());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->addException($e);
|
$this->addException($e);
|
||||||
}
|
}
|
||||||
@ -636,37 +624,51 @@ abstract class DirectorObjectForm extends QuickForm
|
|||||||
|
|
||||||
protected function onRequest()
|
protected function onRequest()
|
||||||
{
|
{
|
||||||
$values = array();
|
|
||||||
|
|
||||||
$object = $this->object();
|
$object = $this->object();
|
||||||
|
$this->setDefaultsFromObject($object);
|
||||||
$this->prepareFields($object);
|
$this->prepareFields($object);
|
||||||
if ($this->hasBeenSent()) {
|
if ($this->hasBeenSent()) {
|
||||||
|
$this->handlePost();
|
||||||
if ($this->shouldBeDeleted()) {
|
|
||||||
$this->deleteObject($object);
|
|
||||||
}
|
|
||||||
|
|
||||||
$post = $this->getRequest()->getPost();
|
|
||||||
$this->populate($post);
|
|
||||||
$values = $this->getValues();
|
|
||||||
|
|
||||||
if ($object instanceof IcingaObject) {
|
|
||||||
$this->setCustomVarValues($object, $post);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$this->loadInheritedProperties();
|
||||||
$this->addFields();
|
$this->addFields();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function handlePost()
|
||||||
|
{
|
||||||
|
$object = $this->object();
|
||||||
|
if ($this->shouldBeDeleted()) {
|
||||||
|
$this->deleteObject($object);
|
||||||
|
}
|
||||||
|
|
||||||
|
$post = $this->getRequest()->getPost();
|
||||||
|
$this->populate($post);
|
||||||
|
$values = $this->getValues();
|
||||||
|
|
||||||
|
if ($object instanceof IcingaObject) {
|
||||||
|
$this->setCustomVarValues($object, $post);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->handleProperties($object, $values);
|
||||||
|
|
||||||
|
// TODO: get rid of this
|
||||||
if ($object instanceof IcingaObject) {
|
if ($object instanceof IcingaObject) {
|
||||||
$this->handleRanges($object, $values);
|
$this->handleRanges($object, $values);
|
||||||
}
|
}
|
||||||
$this->handleProperties($object, $values);
|
}
|
||||||
|
|
||||||
/*
|
protected function setDefaultsFromObject(DbObject $object)
|
||||||
// TODO: something like this could be used to remember unstored changes
|
{
|
||||||
if ($object->hasBeenModified()) {
|
/** @var ZfElement $element */
|
||||||
$this->addHtmlHint($this->translate('Object has been modified'));
|
foreach ($this->getElements() as $element) {
|
||||||
|
$key = $element->getName();
|
||||||
|
if ($object->hasProperty($key)) {
|
||||||
|
$value = $object->get($key);
|
||||||
|
if ($value !== null) {
|
||||||
|
$element->setValue($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function deleteObject($object)
|
protected function deleteObject($object)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user