Skip to content

Commit

Permalink
Apply suggestion by covering all the relational types and improve exc…
Browse files Browse the repository at this point in the history
…eption message
  • Loading branch information
kingjia90 committed Feb 19, 2024
1 parent b76286c commit 72d32e9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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']
)
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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']
)
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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']
)
);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/GraphQL/DataObjectInputProcessor/ManyToManyRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
)
);
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/GraphQL/DataObjectInputProcessor/ManyToOneRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
});
}
Expand Down

0 comments on commit 72d32e9

Please sign in to comment.