ynloultratech /
graphql-bundle
| 1 | <?php |
||||
| 2 | /******************************************************************************* |
||||
| 3 | * This file is part of the GraphQL Bundle package. |
||||
| 4 | * |
||||
| 5 | * (c) YnloUltratech <[email protected]> |
||||
| 6 | * |
||||
| 7 | * For the full copyright and license information, please view the LICENSE |
||||
| 8 | * file that was distributed with this source code. |
||||
| 9 | ******************************************************************************/ |
||||
| 10 | |||||
| 11 | namespace Ynlo\GraphQLBundle\Mutation; |
||||
| 12 | |||||
| 13 | use Symfony\Component\Form\FormEvent; |
||||
| 14 | use Ynlo\GraphQLBundle\Exception\Controlled\NotFoundError; |
||||
| 15 | use Ynlo\GraphQLBundle\Model\NodeInterface; |
||||
| 16 | use Ynlo\GraphQLBundle\Validator\ConstraintViolationList; |
||||
| 17 | |||||
| 18 | /** |
||||
| 19 | * Class DeleteNodeMutation |
||||
| 20 | */ |
||||
| 21 | class DeleteNode extends AbstractMutationResolver |
||||
| 22 | { |
||||
| 23 | /** |
||||
| 24 | * @var NodeInterface |
||||
| 25 | */ |
||||
| 26 | protected $deletedNode; |
||||
| 27 | |||||
| 28 | /** |
||||
| 29 | * {@inheritdoc} |
||||
| 30 | */ |
||||
| 31 | public function process(&$data) |
||||
| 32 | { |
||||
| 33 | $this->preDelete($data); |
||||
| 34 | foreach ($this->extensions as $extension) { |
||||
| 35 | $extension->preDelete($data, $this, $this->context); |
||||
| 36 | } |
||||
| 37 | |||||
| 38 | $this->deletedNode = clone $data; //clone required to avoid node without id after delete |
||||
| 39 | |||||
| 40 | $this->getManager()->remove($data); |
||||
| 41 | $this->getManager()->flush(); |
||||
| 42 | |||||
| 43 | $this->postDelete($this->deletedNode); |
||||
| 44 | foreach ($this->extensions as $extension) { |
||||
| 45 | $extension->postDelete($this->deletedNode, $this, $this->context); |
||||
| 46 | } |
||||
| 47 | } |
||||
| 48 | |||||
| 49 | /** |
||||
| 50 | * {@inheritdoc} |
||||
| 51 | */ |
||||
| 52 | public function returnPayload($data, ConstraintViolationList $violations, $inputSource) |
||||
| 53 | { |
||||
| 54 | $class = $this->getPayloadClass(); |
||||
| 55 | |||||
| 56 | return new $class( |
||||
| 57 | $this->deletedNode, |
||||
| 58 | $inputSource['clientMutationId'] ?? null |
||||
| 59 | ); |
||||
| 60 | } |
||||
| 61 | |||||
| 62 | /** |
||||
| 63 | * {@inheritDoc} |
||||
| 64 | */ |
||||
| 65 | public function onSubmit(FormEvent $event) |
||||
| 66 | { |
||||
| 67 | $node = $this->context->getDefinition()->getNode(); |
||||
| 68 | $class = $this->context->getEndpoint()->getClassForType($node); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 69 | |||||
| 70 | if (!$event->getData() instanceof NodeInterface || !$event->getData()->getId() || !is_a($event->getData(), $class)) { |
||||
| 71 | throw new NotFoundError(); |
||||
| 72 | } |
||||
| 73 | } |
||||
| 74 | |||||
| 75 | /** |
||||
| 76 | * @param NodeInterface $node |
||||
| 77 | */ |
||||
| 78 | protected function preDelete(NodeInterface $node) |
||||
|
0 ignored issues
–
show
The parameter
$node is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 79 | { |
||||
| 80 | //override |
||||
| 81 | } |
||||
| 82 | |||||
| 83 | /** |
||||
| 84 | * @param NodeInterface $node |
||||
| 85 | */ |
||||
| 86 | protected function postDelete(NodeInterface $node) |
||||
|
0 ignored issues
–
show
The parameter
$node is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 87 | { |
||||
| 88 | //override |
||||
| 89 | } |
||||
| 90 | } |
||||
| 91 |