Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
UpdateSnippetEndpoint
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 handle
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace Olz\Snippets\Endpoints;
4
5use Olz\Api\OlzUpdateEntityTypedEndpoint;
6use PhpTypeScriptApi\HttpError;
7
8/**
9 * @phpstan-import-type OlzSnippetId from SnippetEndpointTrait
10 * @phpstan-import-type OlzSnippetData from SnippetEndpointTrait
11 *
12 * @extends OlzUpdateEntityTypedEndpoint<OlzSnippetId, OlzSnippetData>
13 */
14class UpdateSnippetEndpoint extends OlzUpdateEntityTypedEndpoint {
15    use SnippetEndpointTrait;
16
17    protected function handle(mixed $input): mixed {
18        $id = $input['id'];
19        $this->checkPermission("snippet_{$id}");
20
21        $entity = $this->getEntityById($id);
22
23        if (!$this->entityUtils()->canUpdateOlzEntity($entity, $input['meta'], "snippet_{$id}")) {
24            throw new HttpError(403, "Kein Zugriff!");
25        }
26
27        $this->entityUtils()->updateOlzEntity($entity, $input['meta']);
28        $this->updateEntityWithData($entity, $input['data']);
29
30        $this->entityManager()->persist($entity);
31        $this->entityManager()->flush();
32        $this->persistUploads($entity, $input['data']);
33
34        return [
35            'id' => $entity->getId() ?? 0,
36        ];
37    }
38}