119 : bool {
121
122 try {
123 $result = $this->utilHelper->moveUploadedFile($zipFile,
$filename, $rootDir . $importPath .
$filename);
124
125 if (!$result) {
126 return false;
127 }
128
129 $this->utilHelper->unzip(
131 true
132 );
133
134 $subDirectoryName = str_replace(
'.zip',
'', strtolower(
$filename)) .
'/';
135 $subDirectoryAbsolutePath = $rootDir . $importPath . $subDirectoryName;
136
137 $copyDirectory = $rootDir . $importPath;
138 if (is_dir($subDirectoryAbsolutePath)) {
139 $copyDirectory = $subDirectoryAbsolutePath;
140 }
141
142 $directoryInformation = $this->utilHelper->getDir($copyDirectory);
143
144 $xmlFiles = 0;
145 foreach ($directoryInformation as $file) {
146 if (strcmp($file['type'], 'file') === 0) {
147 if (strpos($file['entry'], '.xml') !== false) {
148 $xmlFiles++;
149 }
150
151 if (strpos($file['entry'], '.svg') !== false) {
152 $filePath = $importPath . $file['entry'];
153
154 $stream = $this->
filesystem->readStream($filePath);
155 $file_metadata = $stream->getMetadata();
156 $absolute_file_path = $file_metadata['uri'];
157
159 pathinfo($absolute_file_path)['basename'],
160 filesize($absolute_file_path),
161 mime_content_type($absolute_file_path)
162 );
163
164 $processing_result = $this->svg_blacklist_processor->process($stream, $metadata);
165 if ($processing_result->getCode() !== ProcessingStatus::OK) {
166 return false;
167 }
168 }
169 }
170 }
171
172 if (0 === $xmlFiles) {
173 return false;
174 }
175
176 $certificate = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
177
178 $currentVersion = $certificate->getVersion();
179 $newVersion = $currentVersion + 1;
180 $backgroundImagePath = $certificate->getBackgroundImagePath();
181 $cardThumbnailImagePath = $certificate->getThumbnailImagePath();
182
183 $xsl = $certificate->getCertificateContent();
184
185 foreach ($directoryInformation as $file) {
186 if (strcmp($file['type'], 'file') === 0) {
187 $filePath = $importPath . $file['entry'];
188 if (strpos($file['entry'], '.xml') !== false) {
190
191
192 $xsl = preg_replace_callback(
193 "/url\([']{0,1}(.*?)[']{0,1}\)/",
194 function (array $matches) use ($rootDir): string {
195 $basePath = rtrim(
196 dirname($this->fileService->getBackgroundImageDirectory($rootDir)),
197 '/'
198 );
199 $fileName = basename($matches[1]);
200
201 if ('[BACKGROUND_IMAGE]' === $fileName) {
202 $basePath = '';
203 } elseif ($basePath !== '') {
204 $basePath .= '/';
205 }
206
207 return 'url(' . $basePath . $fileName . ')';
208 },
209 $xsl
210 );
211 } elseif (strpos($file['entry'], '.jpg') !== false) {
212 $newBackgroundImageName = 'background_' . $newVersion . '.jpg';
213 $newPath = $this->certificatePath . $newBackgroundImageName;
215
216 $backgroundImagePath = $this->certificatePath . $newBackgroundImageName;
217
218
220
221 $thumbnailImagePath = $rootDir . $backgroundImageThumbPath;
222
223 $originalImagePath = $rootDir . $newPath;
224 $this->utilHelper->convertImage(
225 $originalImagePath,
226 $thumbnailImagePath,
227 'JPEG',
228 "100"
229 );
230 } elseif (strpos($file['entry'], '.svg') !== false) {
231 $newCardThumbnailName = 'thumbnail_' . $newVersion . '.svg';
232 $newPath = $this->certificatePath . $newCardThumbnailName;
233
235
236 $cardThumbnailImagePath = $this->certificatePath . $newCardThumbnailName;
237 }
238 }
239 }
240
241 $jsonEncodedTemplateValues = json_encode(
242 $this->placeholderDescriptionObject->getPlaceholderDescriptions(),
243 JSON_THROW_ON_ERROR
244 );
245
246 $newHashValue = hash(
247 'sha256',
248 implode('', [
249 $xsl,
250 $backgroundImagePath,
251 $jsonEncodedTemplateValues,
252 $cardThumbnailImagePath
253 ])
254 );
255
257 $this->objectId,
258 $this->objectHelper->lookupType($this->objectId),
259 $xsl,
260 $newHashValue,
261 $jsonEncodedTemplateValues,
262 $newVersion,
263 $iliasVerision,
264 time(),
265 true,
266 $backgroundImagePath,
267 $cardThumbnailImagePath
268 );
269
270 $this->templateRepository->save($template);
271
272 return true;
273 }
catch (Throwable
$e) {
274 $this->
logger->error(sprintf(
'Error during certificate import: %s',
$e->getMessage()));
275 $this->
logger->error($e->getTraceAsString());
276
277 return false;
278 } finally {
280 }
281 }
getBackgroundImageThumbnailPath()
createArchiveDirectory(string $installationID)
Creates a directory for a zip archive containing multiple certificates.