| Code Coverage
| Lines | Functions and Methods | Classes and Traits
Total | 0.00% covered (danger) | 0.00% | 0 / 138 | 0.00% covered (danger) | 0.00% | 0 / 31 | CRAP | 0.00% covered (danger) | 0.00% | 0 / 1
SeedDMS_Core_Storage_File | 0.00% covered (danger) | 0.00% | 0 / 138 | 0.00% covered (danger) | 0.00% | 0 / 31 | 2550 | 0.00% covered (danger) | 0.00% | 0 / 1
__construct | 0.00% covered (danger) | 0.00% | 0 / 6 | 0.00% covered (danger) | 0.00% | 0 / 1 | 6 |
info | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |
deleteContentDir | 0.00% covered (danger) | 0.00% | 0 / 5 | 0.00% covered (danger) | 0.00% | 0 / 1 | 6 |
getDocDir | 0.00% covered (danger) | 0.00% | 0 / 4 | 0.00% covered (danger) | 0.00% | 0 / 1 | 6 |
deleteDocDir | 0.00% covered (danger) | 0.00% | 0 / 5 | 0.00% covered (danger) | 0.00% | 0 / 1 | 6 |
saveAttachment | 0.00% covered (danger) | 0.00% | 0 / 7 | 0.00% covered (danger) | 0.00% | 0 / 1 | 12 |
deleteAttachment | 0.00% covered (danger) | 0.00% | 0 / 6 | 0.00% covered (danger) | 0.00% | 0 / 1 | 6 |
hasAttachment | 0.00% covered (danger) | 0.00% | 0 / 4 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |
getAttachment | 0.00% covered (danger) | 0.00% | 0 / 6 | 0.00% covered (danger) | 0.00% | 0 / 1 | 6 |
getAttachmentName | 0.00% covered (danger) | 0.00% | 0 / 2 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |
getAttachmentFilesize | 0.00% covered (danger) | 0.00% | 0 / 3 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |
getAttachmentMimeType | 0.00% covered (danger) | 0.00% | 0 / 3 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |
saveContent | 0.00% covered (danger) | 0.00% | 0 / 11 | 0.00% covered (danger) | 0.00% | 0 / 1 | 20 |
setFileType | 0.00% covered (danger) | 0.00% | 0 / 7 | 0.00% covered (danger) | 0.00% | 0 / 1 | 6 |
replaceContent | 0.00% covered (danger) | 0.00% | 0 / 5 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |
deleteContent | 0.00% covered (danger) | 0.00% | 0 / 5 | 0.00% covered (danger) | 0.00% | 0 / 1 | 6 |
getContent | 0.00% covered (danger) | 0.00% | 0 / 5 | 0.00% covered (danger) | 0.00% | 0 / 1 | 6 |
hasContent | 0.00% covered (danger) | 0.00% | 0 / 3 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |
getContentName | 0.00% covered (danger) | 0.00% | 0 / 2 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |
getContentStream | 0.00% covered (danger) | 0.00% | 0 / 5 | 0.00% covered (danger) | 0.00% | 0 / 1 | 6 |
getContentFilesize | 0.00% covered (danger) | 0.00% | 0 / 3 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |
getContentMimetype | 0.00% covered (danger) | 0.00% | 0 / 3 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |
getContentChecksum | 0.00% covered (danger) | 0.00% | 0 / 3 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |
saveReview | 0.00% covered (danger) | 0.00% | 0 / 3 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |
deleteReview | 0.00% covered (danger) | 0.00% | 0 / 6 | 0.00% covered (danger) | 0.00% | 0 / 1 | 6 |
getReview | 0.00% covered (danger) | 0.00% | 0 / 6 | 0.00% covered (danger) | 0.00% | 0 / 1 | 6 |
getReviewName | 0.00% covered (danger) | 0.00% | 0 / 2 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |
saveApproval | 0.00% covered (danger) | 0.00% | 0 / 3 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |
deleteApproval | 0.00% covered (danger) | 0.00% | 0 / 6 | 0.00% covered (danger) | 0.00% | 0 / 1 | 6 |
getApproval | 0.00% covered (danger) | 0.00% | 0 / 6 | 0.00% covered (danger) | 0.00% | 0 / 1 | 6 |
getApprovalName | 0.00% covered (danger) | 0.00% | 0 / 2 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |

1 | <?php
2 | declare(strict_types=1);
3 |
4 | /**
5 | * Implementation of document storage
6 | *
7 | * @category DMS
8 | * @package SeedDMS_Core
9 | * @license GPL 2
10 | * @author Uwe Steinmann <uwe@steinmann.cx>
11 | * @copyright Copyright (C) 2010-2024 Uwe Steinmann
12 | */
13 |
14 | /**
15 | * Class with operations to put documents into the storage
16 | *
17 | * Use the methods to access the document storage
18 | *
19 | * @category DMS
20 | * @package SeedDMS_Core
21 | * @author Uwe Steinmann <uwe@steinmann.cx>
22 | * @copyright Copyright (C) 2010-2024 Uwe Steinmann
23 | */
24 | class SeedDMS_Core_Storage_File implements SeedDMS_Core_Storage {
25 |
26 | protected $basedir;
27 |
28 | protected $maxdirid;
29 |
30 | protected $forcerename;
31 |
32 | protected $forcelink;
33 |
34 | public function __construct($basedir, $maxdirid = 0, $forcerename = false, $forcelink = false) { /* {{{ */
35 | $this->forcerename = $forcerename;
36 | $this->forcelink = $forcelink;
37 | if (substr($basedir, -1) == DIRECTORY_SEPARATOR)
38 | $this->basedir = $basedir;
39 | else
40 | $this->basedir = $basedir.DIRECTORY_SEPARATOR;
41 | $this->maxdirid = $maxdirid;
42 | } /* }}} */
43 |
44 | public function info() { /* {{{ */
45 | return 'Storage File';
46 | } /* }}} */
47 |
48 | public function deleteContentDir() { /* {{{ */
49 | $err = true;
50 | $dir = $this->basedir;
51 | if (SeedDMS_Core_File::file_exists($dir))
52 | $err = SeedDMS_Core_File::removeDir($dir);
53 | return $err;
54 | } /* }}} */
55 |
56 | protected function getDocDir($document) { /* {{{ */
57 | if ($this->maxdirid) {
58 | $dirid = (int) (($document->getId()-1) / $this->maxdirid) + 1;
59 | return $dirid.DIRECTORY_SEPARATOR.$document->getId().DIRECTORY_SEPARATOR;
60 | } else {
61 | return $document->getId().DIRECTORY_SEPARATOR;
62 | }
63 | } /* }}} */
64 |
65 | public function deleteDocDir($document) { /* {{{ */
66 | $err = true;
67 | $dir = $this->basedir . $this->getDocDir($document);
68 | if (SeedDMS_Core_File::file_exists($dir))
69 | $err = SeedDMS_Core_File::removeDir($dir);
70 | return $err;
71 | } /* }}} */
72 |
73 | public function saveAttachment($document, $attachment, $tmpFile) { /* {{{ */
74 | $dir = $this->basedir . $this->getDocDir($document);
75 | $fileType = $attachment->getFileType();
76 | if (!SeedDMS_Core_File::makeDir($dir)) return false;
77 | if ($this->forcerename)
78 | $err = SeedDMS_Core_File::renameFile($tmpFile, $dir . "f" .$attachment->getId() . $fileType);
79 | else
80 | $err = SeedDMS_Core_File::copyFile($tmpFile, $dir . "f" .$attachment->getId() . $fileType);
81 |
82 | return $err;
83 | } /* }}} */
84 |
85 | public function deleteAttachment($document, $attachment) { /* {{{ */
86 | $err = true;
87 | $dir = $this->basedir . $this->getDocDir($document);
88 | $fileType = $attachment->getFileType();
89 | if (SeedDMS_Core_File::file_exists($dir . "f" . $attachment->getId() . $fileType)) {
90 | $err = SeedDMS_Core_File::removeFile($dir . "f" . $attachment->getId() . $fileType);
91 | }
92 | return $err;
93 | } /* }}} */
94 |
95 | public function hasAttachment($document, $attachment) { /* {{{ */
96 | $err = true;
97 | $dir = $this->basedir . $this->getDocDir($document);
98 | $fileType = $attachment->getFileType();
99 | return SeedDMS_Core_File::file_exists($dir . "f" . $attachment->getId() . $fileType);
100 | } /* }}} */
101 |
102 | public function getAttachment($document, $attachment) { /* {{{ */
103 | $err = true;
104 | $dir = $this->basedir . $this->getDocDir($document);
105 | $fileType = $attachment->getFileType();
106 | if (SeedDMS_Core_File::file_exists($dir . "f" . $attachment->getId() . $fileType)) {
107 | $err = file_get_contents($dir . "f" . $attachment->getId() . $fileType);
108 | }
109 | return $err;
110 | } /* }}} */
111 |
112 | public function getAttachmentName($document, $attachment) { /* {{{ */
113 | $dir = $this->basedir . $this->getDocDir($document);
114 | return dir.'f'.$attachment->getId().$attachment->getFileType();
115 | } /* }}} */
116 |
117 | public function getAttachmentFilesize($document, $attachment) { /* {{{ */
118 | $dir = $this->basedir . $this->getDocDir($document);
119 | $filesize = SeedDMS_Core_File::fileSize($dir . "f" . $attachment->getId());
120 | return $filesize;
121 | } /* }}} */
122 |
123 | public function getAttachmentMimeType($document, $attachment) { /* {{{ */
124 | $dir = $this->basedir . $this->getDocDir($document);
125 | $filesize = SeedDMS_Core_File::fileSize($dir . "f" . $attachment->getId());
126 | return $filesize;
127 | } /* }}} */
128 |
129 | public function saveContent($document, $content, $tmpFile) { /* {{{ */
130 | $dir = $this->basedir . $this->getDocDir($document);
131 | $version = $content->getVersion();
132 | $fileType = $content->getFileType();
133 | if (!SeedDMS_Core_File::makeDir($dir)) {
134 | return false;
135 | }
136 | if ($this->forcerename)
137 | $err = SeedDMS_Core_File::renameFile($tmpFile, $dir . $version . $fileType);
138 | elseif ($this->forcelink)
139 | $err = SeedDMS_Core_File::linkFile($tmpFile, $dir . $version . $fileType);
140 | else
141 | $err = SeedDMS_Core_File::copyFile($tmpFile, $dir . $version . $fileType);
142 |
143 | return $err;
144 | } /* }}} */
145 |
146 | public function setFileType($document, $content, $newfiletype) { /* {{{ */
147 | $dir = $this->basedir . $this->getDocDir($document);
148 | $version = $content->getVersion();
149 | $fileType = $content->getFileType();
150 | if (!SeedDMS_Core_File::makeDir($dir)) {
151 | return false;
152 | }
153 | $err = SeedDMS_Core_File::renameFile($dir . $version . $fileType, $dir . $version . $newfiletype);
154 |
155 | return $err;
156 | } /* }}} */
157 |
158 | public function replaceContent($document, $content, $tmpFile) { /* {{{ */
159 | $dir = $this->basedir . $this->getDocDir($document);
160 | $version = $content->getVersion();
161 | $fileType = $content->getFileType();
162 | $err = SeedDMS_Core_File::copyFile($tmpFile, $dir . $version . $fileType);
163 | return $err;
164 | } /* }}} */
165 |
166 | public function deleteContent($document, $content) { /* {{{ */
167 | $err = true;
168 | $dir = $this->basedir . $this->getDocDir($document);
169 | if (SeedDMS_Core_File::file_exists($dir . $content->getVersion() . $content->getFileType()))
170 | $err = SeedDMS_Core_File::removeFile($dir . $content->getVersion() . $content->getFileType());
171 | return $err;
172 | } /* }}} */
173 |
174 | public function getContent($document, $content) { /* {{{ */
175 | $err = true;
176 | $dir = $this->basedir . $this->getDocDir($document);
177 | if (SeedDMS_Core_File::file_exists($dir . $content->getVersion() . $content->getFileType()))
178 | $err = file_get_contents($dir . $content->getVersion() . $content->getFileType());
179 | return $err;
180 | } /* }}} */
181 |
182 | public function hasContent($document, $content) { /* {{{ */
183 | $err = true;
184 | $dir = $this->basedir . $this->getDocDir($document);
185 | return SeedDMS_Core_File::file_exists($dir . $content->getVersion() . $content->getFileType());
186 | } /* }}} */
187 |
188 | public function getContentName($document, $content) { /* {{{ */
189 | $dir = $this->basedir . $this->getDocDir($document);
190 | return dir.$content->getVersion().$content->getFileType();
191 | } /* }}} */
192 |
193 | public function getContentStream($document, $content) { /* {{{ */
194 | $err = true;
195 | $dir = $this->basedir . $this->getDocDir($document);
196 | if (SeedDMS_Core_File::file_exists($dir . $content->getVersion() . $content->getFileType()))
197 | $err = fopen($dir . $content->getVersion() . $content->getFileType(), 'r');
198 | return $err;
199 | } /* }}} */
200 |
201 | public function getContentFilesize($document, $content) { /* {{{ */
202 | $dir = $this->basedir . $this->getDocDir($document);
203 | $filesize = SeedDMS_Core_File::fileSize($dir . $content->getVersion() . $content->getFileType());
204 | return $filesize;
205 | } /* }}} */
206 |
207 | public function getContentMimetype($document, $content) { /* {{{ */
208 | $dir = $this->basedir . $this->getDocDir($document);
209 | $filesize = SeedDMS_Core_File::mimetype($dir . $content->getVersion() . $content->getFileType());
210 | return $filesize;
211 | } /* }}} */
212 |
213 | public function getContentChecksum($document, $content) { /* {{{ */
214 | $dir = $this->basedir . $this->getDocDir($document);
215 | $filesize = SeedDMS_Core_File::checksum($dir . $content->getVersion() . $content->getFileType());
216 | return $filesize;
217 | } /* }}} */
218 |
219 | public function saveReview($document, $id, $tmpFile) { /* {{{ */
220 | $dir = $this->basedir . $this->getDocDir($document);
221 | $file = dir.'r'.$id;
222 | return SeedDMS_Core_File::copyFile($tmpFile, $file);
223 | } /* }}} */
224 |
225 | public function deleteReview($document, $id) { /* {{{ */
226 | $err = true;
227 | $dir = $this->basedir . $this->getDocDir($document);
228 | $file = dir.'r'.$id;
229 | if (SeedDMS_Core_File::file_exists($file))
230 | $err = SeedDMS_Core_File::removeFile($file);
231 | return $err;
232 | } /* }}} */
233 |
234 | public function getReview($document, $id) { /* {{{ */
235 | $err = true;
236 | $dir = $this->basedir . $this->getDocDir($document);
237 | $file = dir.'r'.$id;
238 | if (SeedDMS_Core_File::file_exists($file))
239 | $err = file_get_contents($file);
240 | return $err;
241 | } /* }}} */
242 |
243 | public function getReviewName($document, $id) { /* {{{ */
244 | $dir = $this->basedir . $this->getDocDir($document);
245 | return dir.'r'.$id;
246 | } /* }}} */
247 |
248 | public function saveApproval($document, $id, $tmpFile) { /* {{{ */
249 | $dir = $this->basedir . $this->getDocDir($document);
250 | $file = dir.'a'.$id;
251 | return SeedDMS_Core_File::copyFile($tmpFile, $file);
252 | } /* }}} */
253 |
254 | public function deleteApproval($document, $id) { /* {{{ */
255 | $err = true;
256 | $dir = $this->basedir . $this->getDocDir($document);
257 | $file = dir.'a'.$id;
258 | if (SeedDMS_Core_File::file_exists($file))
259 | $err = SeedDMS_Core_File::removeFile($file);
260 | return $err;
261 | } /* }}} */
262 |
263 | public function getApproval($document, $id) { /* {{{ */
264 | $err = true;
265 | $dir = $this->basedir . $this->getDocDir($document);
266 | $file = dir.'a'.$id;
267 | if (SeedDMS_Core_File::file_exists($file))
268 | $err = file_get_contents($file);
269 | return $err;
270 | } /* }}} */
271 |
272 | public function getApprovalName($document, $id) { /* {{{ */
273 | $dir = $this->basedir . $this->getDocDir($document);
274 | return dir.'a'.$id;
275 | } /* }}} */
276 | }