From 1f1a2b660f916a7b70c4e08a9d14696049563c9f Mon Sep 17 00:00:00 2001 From: Timothee Date: Fri, 21 Jun 2024 12:36:35 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B07581=20Improve=20error=20message=20reada?= =?UTF-8?q?bility=20during=20object=20creation/modification=20in=20the=20p?= =?UTF-8?q?ortal=20(regression=20introduced=20with=20N=C2=B07545)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CoreCannotSaveObjectException.php | 18 ++++++++++++++++++ .../portal/src/Form/ObjectFormManager.php | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/application/exceptions/CoreCannotSaveObjectException.php b/application/exceptions/CoreCannotSaveObjectException.php index dcbe20ff5..82f8b1945 100644 --- a/application/exceptions/CoreCannotSaveObjectException.php +++ b/application/exceptions/CoreCannotSaveObjectException.php @@ -60,6 +60,24 @@ class CoreCannotSaveObjectException extends CoreException return $sContent; } + public function getTextMessage() + { + $sTitle = Dict::S('UI:Error:SaveFailed'); + $sContent = utils::HtmlEntities($sTitle); + + if (count($this->aIssues) == 1) { + $sIssue = reset($this->aIssues); + $sContent .= utils::HtmlEntities($sIssue); + } else { + foreach ($this->aIssues as $sError) { + $sContent .= " ".utils::HtmlEntities($sError).", "; + } + } + + return $sContent; + } + + public function getIssues() { return $this->aIssues; diff --git a/datamodels/2.x/itop-portal-base/portal/src/Form/ObjectFormManager.php b/datamodels/2.x/itop-portal-base/portal/src/Form/ObjectFormManager.php index 3ffb2933e..915e229e3 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/Form/ObjectFormManager.php +++ b/datamodels/2.x/itop-portal-base/portal/src/Form/ObjectFormManager.php @@ -1167,7 +1167,7 @@ class ObjectFormManager extends FormManager { $this->oObject->DBWrite(); } catch (CoreCannotSaveObjectException $e) { - throw new Exception($e->getHtmlMessage()); + throw new Exception($e->getTextMessage()); } catch (InvalidExternalKeyValueException $e) { ExceptionLog::LogException($e, $e->getContextData()); $bExceptionLogged = true;