Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug][Data loss]: if passing an invalid asset.id, fullpath to object mutation GraphQL query, the assets are silently discarded #825

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 8 additions & 0 deletions src/GraphQL/DataObjectInputProcessor/ManyToManyRelation.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 ManyToManyRelation extends Base
{
Expand All @@ -45,6 +46,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
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,8 +41,18 @@ 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