| Conditions | 3 |
| Paths | 1 |
| Total Lines | 29 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 18 |
| CRAP Score | 3 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | 1 | public static function build(): iterable |
|
| 15 | { |
||
| 16 | 1 | yield 'deleteUsers' => fn () => [ |
|
| 17 | 1 | 'type' => Type::nonNull(Type::boolean()), |
|
| 18 | 1 | 'description' => 'Delete one or several existing user with all its logs, messages and tags', |
|
| 19 | 1 | 'args' => [ |
|
| 20 | 1 | 'ids' => Type::nonNull(Type::listOf(Type::nonNull(_types()->getId(User::class)))), |
|
| 21 | 1 | ], |
|
| 22 | 1 | 'resolve' => function ($root, array $args): bool { |
|
| 23 | 1 | foreach ($args['ids'] as $id) { |
|
| 24 | /** @var User $user */ |
||
| 25 | 1 | $user = $id->getEntity(); |
|
| 26 | |||
| 27 | // Check ACL |
||
| 28 | 1 | Helper::throwIfDenied($user, 'delete'); |
|
| 29 | |||
| 30 | 1 | $account = $user->getAccount(); |
|
| 31 | 1 | if ($account?->getOwner() === $user) { |
|
| 32 | 1 | $account->setName(_tr('Anonyme %id%', ['id' => '#' . $user->getId()])); |
|
| 33 | 1 | $account->setIban(''); |
|
| 34 | } |
||
| 35 | |||
| 36 | // Do it |
||
| 37 | 1 | _em()->remove($user); |
|
| 38 | } |
||
| 39 | |||
| 40 | 1 | _em()->flush(); |
|
| 41 | |||
| 42 | 1 | return true; |
|
| 43 | 1 | }, |
|
| 47 |