From 4f4672e33647ecc90a4f17a2647303ce60e9e97b Mon Sep 17 00:00:00 2001 From: robertSt7 Date: Thu, 14 Dec 2023 15:43:33 +0100 Subject: [PATCH 1/5] Fix: throw error message --- src/GraphQL/DataObjectInputProcessor/ManyToManyRelation.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/GraphQL/DataObjectInputProcessor/ManyToManyRelation.php b/src/GraphQL/DataObjectInputProcessor/ManyToManyRelation.php index 2826ba76..b09499ad 100644 --- a/src/GraphQL/DataObjectInputProcessor/ManyToManyRelation.php +++ b/src/GraphQL/DataObjectInputProcessor/ManyToManyRelation.php @@ -20,6 +20,7 @@ use Pimcore\Bundle\DataHubBundle\GraphQL\Traits\ElementIdentificationTrait; use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Fieldcollection\Data\AbstractData; +use Pimcore\Model\Exception\NotFoundException; class ManyToManyRelation extends Base { @@ -45,6 +46,10 @@ public function process($object, $newValue, $args, $context, ResolveInfo $info) if ($element) { $result[] = $element; + } else { + throw new NotFoundException( + "Doesn't found element: " . $newValueItemValue['fullpath'] ?? $newValueItemValue['id'] + ); } } } From b76286cc0ade02e027eafe4a9e33c9e735ada7bf Mon Sep 17 00:00:00 2001 From: robertSt7 Date: Thu, 14 Dec 2023 15:49:44 +0100 Subject: [PATCH 2/5] Fix: throw error message --- src/GraphQL/DataObjectInputProcessor/ManyToManyRelation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GraphQL/DataObjectInputProcessor/ManyToManyRelation.php b/src/GraphQL/DataObjectInputProcessor/ManyToManyRelation.php index b09499ad..16d9e7ef 100644 --- a/src/GraphQL/DataObjectInputProcessor/ManyToManyRelation.php +++ b/src/GraphQL/DataObjectInputProcessor/ManyToManyRelation.php @@ -48,7 +48,7 @@ public function process($object, $newValue, $args, $context, ResolveInfo $info) $result[] = $element; } else { throw new NotFoundException( - "Doesn't found element: " . $newValueItemValue['fullpath'] ?? $newValueItemValue['id'] + "Doesn't found element: " . $newValueItemValue['fullpath'] ); } } From 72d32e91180a5ee43513dedbd944278ca16e06e6 Mon Sep 17 00:00:00 2001 From: jiajia Date: Mon, 19 Feb 2024 15:06:00 +0100 Subject: [PATCH 3/5] Apply suggestion by covering all the relational types and improve exception message --- .../AdvancedManyToManyObjectRelation.php | 8 ++++++++ .../AdvancedManyToManyRelation.php | 8 ++++++++ .../ManyToManyObjectRelation.php | 8 ++++++++ .../DataObjectInputProcessor/ManyToManyRelation.php | 5 ++++- .../DataObjectInputProcessor/ManyToOneRelation.php | 11 +++++++++++ 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/GraphQL/DataObjectInputProcessor/AdvancedManyToManyObjectRelation.php b/src/GraphQL/DataObjectInputProcessor/AdvancedManyToManyObjectRelation.php index accf7abc..b64091e4 100644 --- a/src/GraphQL/DataObjectInputProcessor/AdvancedManyToManyObjectRelation.php +++ b/src/GraphQL/DataObjectInputProcessor/AdvancedManyToManyObjectRelation.php @@ -21,6 +21,7 @@ use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Data\ObjectMetadata; use Pimcore\Model\DataObject\Fieldcollection\Data\AbstractData; +use Pimcore\Model\Exception\NotFoundException; class AdvancedManyToManyObjectRelation extends Base { @@ -58,6 +59,13 @@ public function process($object, $newValue, $args, $context, ResolveInfo $info) $item->setData($data); } $result[] = $item; + } else { + throw new NotFoundException( + sprintf('Element with id %s or fullpath %s not found', + $newValueItemValue['id'], + $newValueItemValue['fullpath'] + ) + ); } } } diff --git a/src/GraphQL/DataObjectInputProcessor/AdvancedManyToManyRelation.php b/src/GraphQL/DataObjectInputProcessor/AdvancedManyToManyRelation.php index fbc35d28..ee0752ea 100644 --- a/src/GraphQL/DataObjectInputProcessor/AdvancedManyToManyRelation.php +++ b/src/GraphQL/DataObjectInputProcessor/AdvancedManyToManyRelation.php @@ -21,6 +21,7 @@ use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Data\ElementMetadata; use Pimcore\Model\DataObject\Fieldcollection\Data\AbstractData; +use Pimcore\Model\Exception\NotFoundException; class AdvancedManyToManyRelation extends Base { @@ -57,6 +58,13 @@ public function process($object, $newValue, $args, $context, ResolveInfo $info) $item->setData($data); } $result[] = $item; + } else { + throw new NotFoundException( + sprintf('Element with id %s or fullpath %s not found', + $newValueItemValue['id'], + $newValueItemValue['fullpath'] + ) + ); } } } diff --git a/src/GraphQL/DataObjectInputProcessor/ManyToManyObjectRelation.php b/src/GraphQL/DataObjectInputProcessor/ManyToManyObjectRelation.php index 3d3b3dc6..a441bda6 100644 --- a/src/GraphQL/DataObjectInputProcessor/ManyToManyObjectRelation.php +++ b/src/GraphQL/DataObjectInputProcessor/ManyToManyObjectRelation.php @@ -21,6 +21,7 @@ use Pimcore\Bundle\DataHubBundle\GraphQL\Traits\ElementIdentificationTrait; use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Fieldcollection\Data\AbstractData; +use Pimcore\Model\Exception\NotFoundException; class ManyToManyObjectRelation extends Base { @@ -50,6 +51,13 @@ public function process($object, $newValue, $args, $context, ResolveInfo $info) if ($element) { $result[] = $element; + } else { + throw new NotFoundException( + sprintf('Element with id %s or fullpath %s not found', + $newValueItemValue['id'], + $newValueItemValue['fullpath'] + ) + ); } } } diff --git a/src/GraphQL/DataObjectInputProcessor/ManyToManyRelation.php b/src/GraphQL/DataObjectInputProcessor/ManyToManyRelation.php index 16d9e7ef..0f5e39f6 100644 --- a/src/GraphQL/DataObjectInputProcessor/ManyToManyRelation.php +++ b/src/GraphQL/DataObjectInputProcessor/ManyToManyRelation.php @@ -48,7 +48,10 @@ public function process($object, $newValue, $args, $context, ResolveInfo $info) $result[] = $element; } else { throw new NotFoundException( - "Doesn't found element: " . $newValueItemValue['fullpath'] + sprintf('Element with id %s or fullpath %s not found', + $newValueItemValue['id'], + $newValueItemValue['fullpath'] + ) ); } } diff --git a/src/GraphQL/DataObjectInputProcessor/ManyToOneRelation.php b/src/GraphQL/DataObjectInputProcessor/ManyToOneRelation.php index a722cdbb..a11b029b 100644 --- a/src/GraphQL/DataObjectInputProcessor/ManyToOneRelation.php +++ b/src/GraphQL/DataObjectInputProcessor/ManyToOneRelation.php @@ -20,6 +20,7 @@ use Pimcore\Bundle\DataHubBundle\GraphQL\Traits\ElementIdentificationTrait; use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Fieldcollection\Data\AbstractData; +use Pimcore\Model\Exception\NotFoundException; class ManyToOneRelation extends Base { @@ -40,10 +41,20 @@ public function process($object, $newValue, $args, $context, ResolveInfo $info): $me = $this; Service::setValue($object, $attribute, function ($container, $setter) use ($newValue) { $element = null; + if (is_array($newValue)) { $element = $this->getElementByTypeAndIdOrPath($newValue); } + if (!$element) { + throw new NotFoundException( + sprintf('Element with id %s or fullpath %s not found', + $newValue['id'], + $newValue['fullpath'] + ) + ); + } + return $container->$setter($element); }); } From 8a85a359b3bfa55f000d3afe3ba87ccc8fbba0c5 Mon Sep 17 00:00:00 2001 From: JiaJia Ji Date: Mon, 19 Feb 2024 15:08:03 +0100 Subject: [PATCH 4/5] Update ManyToOneRelation.php --- .../ManyToOneRelation.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/GraphQL/DataObjectInputProcessor/ManyToOneRelation.php b/src/GraphQL/DataObjectInputProcessor/ManyToOneRelation.php index a11b029b..a423e7a6 100644 --- a/src/GraphQL/DataObjectInputProcessor/ManyToOneRelation.php +++ b/src/GraphQL/DataObjectInputProcessor/ManyToOneRelation.php @@ -44,15 +44,15 @@ public function process($object, $newValue, $args, $context, ResolveInfo $info): if (is_array($newValue)) { $element = $this->getElementByTypeAndIdOrPath($newValue); - } - - if (!$element) { - throw new NotFoundException( - sprintf('Element with id %s or fullpath %s not found', - $newValue['id'], - $newValue['fullpath'] - ) - ); + + if (!$element) { + throw new NotFoundException( + sprintf('Element with id %s or fullpath %s not found', + $newValue['id'], + $newValue['fullpath'] + ) + ); + } } return $container->$setter($element); From 82cb3da4df01c167bc9d4f9bcb193bf87eeea832 Mon Sep 17 00:00:00 2001 From: kingjia90 Date: Mon, 19 Feb 2024 14:08:23 +0000 Subject: [PATCH 5/5] Apply php-cs-fixer changes --- src/GraphQL/DataObjectInputProcessor/ManyToOneRelation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GraphQL/DataObjectInputProcessor/ManyToOneRelation.php b/src/GraphQL/DataObjectInputProcessor/ManyToOneRelation.php index a423e7a6..aba68702 100644 --- a/src/GraphQL/DataObjectInputProcessor/ManyToOneRelation.php +++ b/src/GraphQL/DataObjectInputProcessor/ManyToOneRelation.php @@ -44,7 +44,7 @@ public function process($object, $newValue, $args, $context, ResolveInfo $info): if (is_array($newValue)) { $element = $this->getElementByTypeAndIdOrPath($newValue); - + if (!$element) { throw new NotFoundException( sprintf('Element with id %s or fullpath %s not found',