Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 43 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
OlzEntityEndpointTrait | |
0.00% |
0 / 43 |
|
0.00% |
0 / 6 |
132 | |
0.00% |
0 / 1 |
persistOlzImages | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
editOlzImages | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
deleteOlzImages | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
persistOlzFiles | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
editOlzFiles | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
deleteOlzFiles | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Olz\Api; |
4 | |
5 | use Olz\Entity\Common\DataStorageInterface; |
6 | |
7 | /** |
8 | * @phpstan-type OlzMetaData array{ |
9 | * ownerUserId: ?int, |
10 | * ownerRoleId: ?int, |
11 | * onOff: bool, |
12 | * } |
13 | */ |
14 | trait OlzEntityEndpointTrait { |
15 | /** @param ?array<string> $image_ids */ |
16 | protected function persistOlzImages(DataStorageInterface $entity, ?array $image_ids): void { |
17 | $data_path = $this->envUtils()->getDataPath(); |
18 | $entity_name = $entity::getEntityNameForStorage(); |
19 | $entity_id = $entity->getEntityIdForStorage(); |
20 | |
21 | $entity_img_path = "{$data_path}img/{$entity_name}/{$entity_id}/"; |
22 | if (!is_dir("{$entity_img_path}img/")) { |
23 | mkdir("{$entity_img_path}img/", 0o777, true); |
24 | } |
25 | if (!is_dir("{$entity_img_path}thumb/")) { |
26 | mkdir("{$entity_img_path}thumb/", 0o777, true); |
27 | } |
28 | $this->uploadUtils()->overwriteUploads($image_ids, "{$entity_img_path}img/"); |
29 | $this->imageUtils()->generateThumbnails($image_ids ?? [], $entity_img_path); |
30 | } |
31 | |
32 | /** @param ?array<string> $image_ids */ |
33 | protected function editOlzImages(DataStorageInterface $entity, ?array $image_ids): void { |
34 | $data_path = $this->envUtils()->getDataPath(); |
35 | $entity_name = $entity::getEntityNameForStorage(); |
36 | $entity_id = $entity->getEntityIdForStorage(); |
37 | |
38 | $entity_img_path = "{$data_path}img/{$entity_name}/{$entity_id}/"; |
39 | $this->uploadUtils()->editUploads($image_ids, "{$entity_img_path}img/"); |
40 | } |
41 | |
42 | protected function deleteOlzImages(DataStorageInterface $entity): void { |
43 | $data_path = $this->envUtils()->getDataPath(); |
44 | $entity_name = $entity::getEntityNameForStorage(); |
45 | $entity_id = $entity->getEntityIdForStorage(); |
46 | |
47 | $entity_img_path = "{$data_path}img/{$entity_name}/{$entity_id}/"; |
48 | $this->generalUtils()->removeRecursive($entity_img_path); |
49 | } |
50 | |
51 | /** @param ?array<string> $file_ids */ |
52 | protected function persistOlzFiles(DataStorageInterface $entity, ?array $file_ids): void { |
53 | $data_path = $this->envUtils()->getDataPath(); |
54 | $entity_name = $entity::getEntityNameForStorage(); |
55 | $entity_id = $entity->getEntityIdForStorage(); |
56 | |
57 | $entity_files_path = "{$data_path}files/{$entity_name}/{$entity_id}/"; |
58 | if (!is_dir("{$entity_files_path}")) { |
59 | mkdir("{$entity_files_path}", 0o777, true); |
60 | } |
61 | $this->uploadUtils()->overwriteUploads($file_ids, $entity_files_path); |
62 | } |
63 | |
64 | protected function editOlzFiles(DataStorageInterface $entity): void { |
65 | $data_path = $this->envUtils()->getDataPath(); |
66 | $entity_name = $entity::getEntityNameForStorage(); |
67 | $entity_id = $entity->getEntityIdForStorage(); |
68 | |
69 | $entity_files_path = "{$data_path}files/{$entity_name}/{$entity_id}/"; |
70 | if (!is_dir("{$entity_files_path}")) { |
71 | mkdir("{$entity_files_path}", 0o777, true); |
72 | } |
73 | $file_ids = $this->uploadUtils()->getStoredUploadIds($entity_files_path); |
74 | foreach ($file_ids as $file_id) { |
75 | $file_path = "{$entity_files_path}{$file_id}"; |
76 | $temp_path = "{$data_path}temp/{$file_id}"; |
77 | copy($file_path, $temp_path); |
78 | } |
79 | } |
80 | |
81 | protected function deleteOlzFiles(DataStorageInterface $entity): void { |
82 | $data_path = $this->envUtils()->getDataPath(); |
83 | $entity_name = $entity::getEntityNameForStorage(); |
84 | $entity_id = $entity->getEntityIdForStorage(); |
85 | |
86 | $entity_files_path = "{$data_path}files/{$entity_name}/{$entity_id}/"; |
87 | $this->generalUtils()->removeRecursive($entity_files_path); |
88 | } |
89 | } |