Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
UpdateNewsEndpoint | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
configure | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
handle | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace Olz\News\Endpoints; |
4 | |
5 | use Olz\Api\OlzUpdateEntityTypedEndpoint; |
6 | use PhpTypeScriptApi\HttpError; |
7 | |
8 | /** |
9 | * @phpstan-import-type OlzNewsId from NewsEndpointTrait |
10 | * @phpstan-import-type OlzNewsData from NewsEndpointTrait |
11 | * |
12 | * TODO: Those should not be necessary! |
13 | * @phpstan-import-type OlzNewsFormat from NewsEndpointTrait |
14 | * |
15 | * @extends OlzUpdateEntityTypedEndpoint<OlzNewsId, OlzNewsData> |
16 | */ |
17 | class UpdateNewsEndpoint extends OlzUpdateEntityTypedEndpoint { |
18 | use NewsEndpointTrait; |
19 | |
20 | public function configure(): void { |
21 | parent::configure(); |
22 | $this->configureNewsEndpointTrait(); |
23 | $this->phpStanUtils->registerTypeImport(NewsEndpointTrait::class); |
24 | } |
25 | |
26 | protected function handle(mixed $input): mixed { |
27 | $this->checkPermission('any'); |
28 | |
29 | $entity = $this->getEntityById($input['id']); |
30 | |
31 | if (!$this->entityUtils()->canUpdateOlzEntity($entity, $input['meta'], 'news')) { |
32 | throw new HttpError(403, "Kein Zugriff!"); |
33 | } |
34 | |
35 | $this->entityUtils()->updateOlzEntity($entity, $input['meta']); |
36 | $this->updateEntityWithData($entity, $input['data']); |
37 | |
38 | $this->entityManager()->persist($entity); |
39 | $this->entityManager()->flush(); |
40 | $this->persistUploads($entity, $input['data']); |
41 | |
42 | return [ |
43 | 'id' => $entity->getId() ?? 0, |
44 | ]; |
45 | } |
46 | } |