1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Application\Api\Field\Mutation; |
6
|
|
|
|
7
|
|
|
use Application\Api\Helper; |
8
|
|
|
use Application\Model\Card; |
9
|
|
|
use Application\Model\Change; |
10
|
|
|
use Application\Repository\ChangeRepository; |
11
|
|
|
use Ecodev\Felix\Api\Exception; |
12
|
|
|
use Ecodev\Felix\Api\Field\FieldInterface; |
13
|
|
|
use GraphQL\Type\Definition\Type; |
14
|
|
|
|
15
|
|
|
class SuggestUpdate implements FieldInterface |
16
|
|
|
{ |
17
|
1 |
|
public static function build(): array |
18
|
|
|
{ |
19
|
1 |
|
return [ |
20
|
1 |
|
'name' => 'suggestUpdate', |
21
|
1 |
|
'type' => Type::nonNull(_types()->getOutput(Change::class)), |
22
|
1 |
|
'description' => 'Suggest the update of an existing image', |
23
|
1 |
|
'args' => [ |
24
|
1 |
|
'id' => Type::nonNull(_types()->getId(Card::class)), |
25
|
1 |
|
'request' => Type::nonNull(Type::string()), |
26
|
1 |
|
], |
27
|
1 |
|
'resolve' => function (array $root, array $args): Change { |
28
|
1 |
|
$site = $root['site']; |
29
|
|
|
|
30
|
1 |
|
$suggestion = $args['id']->getEntity(); |
31
|
1 |
|
$original = $suggestion->getOriginal(); |
32
|
|
|
|
33
|
1 |
|
if (!$original) { |
34
|
|
|
throw new Exception('An suggestion must have an original defined'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** @var ChangeRepository $changeRepository */ |
38
|
1 |
|
$changeRepository = _em()->getRepository(Change::class); |
39
|
1 |
|
$change = $changeRepository->getOrCreate(Change::TYPE_UPDATE, $suggestion, $args['request'], $site); |
40
|
1 |
|
Helper::throwIfDenied($change, 'create'); |
41
|
|
|
|
42
|
1 |
|
if (!$change->getId()) { |
|
|
|
|
43
|
1 |
|
_em()->flush(); |
44
|
|
|
} |
45
|
|
|
|
46
|
1 |
|
return $change; |
47
|
1 |
|
}, |
48
|
1 |
|
]; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: