From 08e8d15d78e97452eb57d9cbfd5a02cea43952d2 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Mon, 4 Dec 2023 22:28:26 +0100 Subject: [PATCH 1/3] =?UTF-8?q?N=C2=B07023=20-=20Fix=20check=20to=20write?= =?UTF-8?q?=20error=20when=20adding=20a=20contact=20on=20a=20new=20user=20?= =?UTF-8?q?request=20on=20the=20end-users=20portal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/dbobject.class.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/dbobject.class.php b/core/dbobject.class.php index fdf8ddba3..d4f2535cb 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -2297,15 +2297,19 @@ abstract class DBObject implements iDisplay continue; } - /** @noinspection NotOptimalIfConditionsInspection */ - /** @noinspection TypeUnsafeComparisonInspection */ if (utils::IsNullOrEmptyString($sRemoteObjectClass) || utils::IsNullOrEmptyString($sRemoteObjectKey) - || ($sRemoteObjectKey == 0) // non-strict comparison as we might have bad surprises ) { continue; } + // 0 : Undefined ext. key (EG. non-mandatory and no value provided) + // < 0 : Non yet persisted object + /** @noinspection TypeUnsafeComparisonInspection Non-strict comparison as object ID can be string */ + if ($sRemoteObjectKey <= 0) { + continue; + } + if (false === $oIsObjectLoadableCallback($sRemoteObjectClass, $sRemoteObjectKey)) { throw new InvalidExternalKeyValueException($this, $sAttDefCode); } From c9bb628c3078b609d05c89dc8390434a5bd411d5 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Mon, 4 Dec 2023 22:31:56 +0100 Subject: [PATCH 2/3] =?UTF-8?q?N=C2=B07023=20-=20Improve=20debug=20message?= =?UTF-8?q?=20on=20portal=20\DBObject::CheckChangedExtKeysValues()=20call?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../itop-portal-base/portal/src/Form/ObjectFormManager.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 43350b0f2..b2bb6b643 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 @@ -1157,7 +1157,10 @@ class ObjectFormManager extends FormManager } catch (CoreCannotSaveObjectException $e) { throw new Exception($e->getHtmlMessage()); } catch (InvalidExternalKeyValueException $e) { - throw new Exception($e->getIssue()); + $sExceptionMessage = $e->getIssue(); + $sExceptionMessage .= var_export($e->getContextData(), true); + + throw new Exception($sExceptionMessage); } catch (Exception $e) { if ($bIsNew) { throw new Exception(Dict::S('Portal:Error:ObjectCannotBeCreated')); From 99d69493d13acd87c8e543a9d886e10c643908df Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Mon, 4 Dec 2023 16:35:12 +0100 Subject: [PATCH 3/3] =?UTF-8?q?N=C2=B07023=20-=20Update=20tests=20so=20tha?= =?UTF-8?q?t=20we=20are=20now=20checking=20negative=20ext.=20keys?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/php-unit-tests/unitary-tests/core/DBObjectTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php b/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php index 06d8f41e9..8b81f3925 100644 --- a/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php +++ b/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php @@ -244,6 +244,7 @@ class DBObjectTest extends ItopDataTestCase $oPersonLinks = \DBObjectSet::FromScratch(lnkPersonToTeam::class); $oPersonLinks->AddObject(MetaModel::NewObject(lnkPersonToTeam::class, [ 'person_id' => self::INVALID_OBJECT_KEY, + 'team_id' => $oTeam->GetKey(), ])); $oTeam->Set('persons_list', $oPersonLinks); @@ -268,6 +269,7 @@ class DBObjectTest extends ItopDataTestCase $oPersonLinks = \DBObjectSet::FromScratch(lnkPersonToTeam::class); $oPersonLinks->AddObject(MetaModel::NewObject(lnkPersonToTeam::class, [ 'person_id' => $oPersonOnDemoOrg->GetKey(), + 'team_id' => $oTeam->GetKey(), ])); $oTeam->Set('persons_list', $oPersonLinks); @@ -289,6 +291,7 @@ class DBObjectTest extends ItopDataTestCase $oPersonLinks = \DBObjectSet::FromScratch(lnkPersonToTeam::class); $oPersonLinks->AddObject(MetaModel::NewObject(lnkPersonToTeam::class, [ 'person_id' => $oPersonOnItDepartmentOrg->GetKey(), + 'team_id' => $oTeam->GetKey(), ])); $oTeam->Set('persons_list', $oPersonLinks);