19declare(strict_types=1);
65 if (
null === $database) {
67 $database =
$DIC->database();
70 $this->web_fs = $filesystem;
116 public function import(
125 $abs_tmp_directory = rtrim($storage_directory,
'/') .
'/temp/';
128 $clean_up_import_dir =
function () use (&$rel_tmp_import_path, &$rel_import_path):
void {
130 if ($this->tmp_fs->hasDir($rel_tmp_import_path)) {
131 $this->tmp_fs->deleteDir($rel_tmp_import_path);
133 }
catch (Throwable
$e) {
134 $this->
logger->error(sprintf(
"Can't clean up temporary import directory: %s",
$e->getMessage()));
135 $this->
logger->error($e->getTraceAsString());
139 if ($this->web_fs->hasDir($rel_import_path)) {
140 $this->web_fs->deleteDir($rel_import_path);
142 }
catch (Throwable
$e) {
143 $this->
logger->error(sprintf(
"Can't clean up import directory: %s",
$e->getMessage()));
144 $this->
logger->error($e->getTraceAsString());
149 $abs_zip_path = $abs_tmp_directory . $rel_tmp_import_path .
$filename;
150 $result = $this->utilHelper->moveUploadedFile(
160 $this->utilHelper->unzip(
161 $abs_tmp_directory . $rel_tmp_import_path .
$filename,
165 $abs_unzip_destination_dir = $abs_tmp_directory . $rel_tmp_import_path;
166 $sub_directory = str_replace(
'.zip',
'', strtolower(
$filename)) .
'/';
167 $abs_sub_directory_path = $abs_tmp_directory . $rel_tmp_import_path . $sub_directory;
168 if (is_dir($abs_sub_directory_path)) {
169 $abs_target_directory = $abs_sub_directory_path;
172 $this->utilHelper->renameExecutables($abs_sub_directory_path);
174 if ($this->tmp_fs->has($rel_tmp_import_path .
$filename)) {
175 $this->tmp_fs->delete($rel_tmp_import_path .
$filename);
178 $tmp_contents = $this->tmp_fs->listContents($rel_tmp_import_path,
true);
179 foreach ($tmp_contents as $file) {
180 if (!$file->isFile()) {
184 if (!$this->web_fs->has($rel_import_path . basename($file->getPath()))) {
185 $this->web_fs->writeStream(
186 $rel_import_path . basename($file->getPath()),
187 $this->tmp_fs->readStream($file->getPath())
192 $num_background_images = 0;
193 $num_tile_images = 0;
195 $contents = $this->web_fs->listContents($rel_import_path);
196 foreach ($contents as $file) {
197 if (!$file->isFile()) {
201 if (strpos($file->getPath(),
'.xml') !==
false) {
205 if (strpos($file->getPath(),
'.svg') !==
false) {
206 $stream = $this->web_fs->readStream($file->getPath());
207 $file_metadata = $stream->getMetadata();
208 $absolute_file_path = $file_metadata[
'uri'];
211 pathinfo($absolute_file_path)[
'basename'],
212 filesize($absolute_file_path),
213 mime_content_type($absolute_file_path)
218 $processing_result = $this->svg_blacklist_processor->process($stream, $metadata);
219 if ($processing_result->getCode() !== ProcessingStatus::OK) {
224 if (str_contains($file->getPath(),
'.jpg')) {
225 ++$num_background_images;
229 if (0 === $num_xml_files) {
230 $this->
logger->error(
'No XML file found in the imported zip file');
233 if ($num_background_images > 1) {
234 $this->
logger->error(
'More than one background image found in the imported zip file');
237 if ($num_tile_images > 1) {
238 $this->
logger->error(
'More than one tile image found in the imported zip file');
242 $certificate = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
244 $currentVersion = $certificate->getVersion();
245 $newVersion = $currentVersion + 1;
246 $backgroundImagePath = $certificate->getBackgroundImagePath();
247 $cardThumbnailImagePath = $certificate->getThumbnailImagePath();
249 $xsl = $certificate->getCertificateContent();
251 foreach ($contents as $file) {
252 if (!$file->isFile()) {
256 if (strpos($file->getPath(),
'.xml') !==
false) {
257 $xsl = $this->web_fs->read($file->getPath());
260 $xsl = preg_replace_callback(
261 "/url\([']{0,1}(.*?)[']{0,1}\)/",
262 function (array $matches) use ($web_directory):
string {
264 dirname($this->fileService->getBackgroundImageDirectory($web_directory)),
267 $fileName = basename($matches[1]);
269 if (
'[BACKGROUND_IMAGE]' === $fileName) {
271 } elseif ($basePath !==
'') {
275 return 'url(' . $basePath . $fileName .
')';
279 } elseif (strpos($file->getPath(),
'.jpg') !==
false) {
280 $newBackgroundImageName =
'background_' . $newVersion .
'.jpg';
281 $newPath = $this->certificatePath . $newBackgroundImageName;
282 $this->web_fs->copy($file->getPath(), $newPath);
284 $backgroundImagePath = $this->certificatePath . $newBackgroundImageName;
289 $thumbnailImagePath = $web_directory . $backgroundImageThumbPath;
291 $originalImagePath = $web_directory . $newPath;
292 $this->utilHelper->convertImage(
298 } elseif (strpos($file->getPath(),
'.svg') !==
false) {
299 $newCardThumbnailName =
'thumbnail_' . $newVersion .
'.svg';
300 $newPath = $this->certificatePath . $newCardThumbnailName;
302 $this->web_fs->copy($file->getPath(), $newPath);
304 $cardThumbnailImagePath = $this->certificatePath . $newCardThumbnailName;
308 $jsonEncodedTemplateValues = json_encode(
309 $this->placeholderDescriptionObject->getPlaceholderDescriptions(),
313 $newHashValue = hash(
317 $backgroundImagePath,
318 $jsonEncodedTemplateValues,
319 $cardThumbnailImagePath
325 $this->objectHelper->lookupType($this->objectId),
328 $jsonEncodedTemplateValues,
333 $backgroundImagePath,
334 $cardThumbnailImagePath
337 $this->templateRepository->save($template);
340 }
catch (Throwable
$e) {
341 $this->
logger->error(sprintf(
'Error during certificate import: %s',
$e->getMessage()));
342 $this->
logger->error($e->getTraceAsString());
346 $clean_up_import_dir();
357 if ($this->web_fs->hasDir($dir)) {
358 $this->web_fs->deleteDir($dir);
360 $this->web_fs->createDir($dir);
372 if ($this->tmp_fs->hasDir($dir)) {
373 $this->tmp_fs->deleteDir($dir);
375 $this->tmp_fs->createDir($dir);
383 $type = $this->objectHelper->lookupType($this->objectId);
385 return implode($seperator, [
386 $this->certificatePath . time(),
396 return $this->certificatePath .
'background.jpg.thumb.jpg';
Class SVGBlacklistPreProcessor.
Class FileAlreadyExistsException.
Class FileNotFoundException.
ilCertificateBackgroundImageFileService $fileService
ilCertificateObjectHelper $objectHelper
ilCertificateTemplateRepository $templateRepository
SVGBlacklistPreProcessor $svg_blacklist_processor
ilCertificatePlaceholderDescription $placeholderDescriptionObject
createTemporaryArchiveDirectory(string $installationId)
getBackgroundImageThumbnailPath()
__construct(int $objectId, string $certificatePath, ilCertificatePlaceholderDescription $placeholderDescriptionObject, ilLogger $logger, Filesystem $filesystem, Filesystem $tmp_fs, ?ilCertificateTemplateRepository $templateRepository=null, ?ilCertificateObjectHelper $objectHelper=null, ?ilCertificateUtilHelper $utilHelper=null, ?ilDBInterface $database=null, ?ilCertificateBackgroundImageFileService $fileService=null, ?SVGBlacklistPreProcessor $svg_blacklist_processor=null)
buildArchivePath(string $installationId)
ilCertificateUtilHelper $utilHelper
createArchiveDirectory(string $installationId)
Just a wrapper class to create Unit Test for other classes.
Component logger with individual log levels by component id.
const ILIAS_VERSION_NUMERIC
Class FlySystemFileAccessTest \Provider\FlySystem @runTestsInSeparateProcesses @preserveGlobalState d...