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