19declare(strict_types=1);
63 if (
null === $database) {
65 $database =
$DIC->database();
113 public function import(
123 $result = $this->utilHelper->moveUploadedFile($zipFile,
$filename, $rootDir . $importPath .
$filename);
129 $this->utilHelper->unzip(
134 $subDirectoryName = str_replace(
'.zip',
'', strtolower(
$filename)) .
'/';
135 $subDirectoryAbsolutePath = $rootDir . $importPath . $subDirectoryName;
137 $copyDirectory = $rootDir . $importPath;
138 if (is_dir($subDirectoryAbsolutePath)) {
139 $copyDirectory = $subDirectoryAbsolutePath;
142 $directoryInformation = $this->utilHelper->getDir($copyDirectory);
145 foreach ($directoryInformation as $file) {
146 if (strcmp($file[
'type'],
'file') === 0) {
147 if (strpos($file[
'entry'],
'.xml') !==
false) {
151 if (strpos($file[
'entry'],
'.svg') !==
false) {
152 $filePath = $importPath . $file[
'entry'];
154 $stream = $this->
filesystem->readStream($filePath);
155 $file_metadata = $stream->getMetadata();
156 $absolute_file_path = $file_metadata[
'uri'];
159 pathinfo($absolute_file_path)[
'basename'],
160 filesize($absolute_file_path),
161 mime_content_type($absolute_file_path)
164 $processing_result = $this->svg_blacklist_processor->process($stream, $metadata);
165 if ($processing_result->getCode() !== ProcessingStatus::OK) {
172 if (0 === $xmlFiles) {
176 $certificate = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
178 $currentVersion = $certificate->getVersion();
179 $newVersion = $currentVersion + 1;
180 $backgroundImagePath = $certificate->getBackgroundImagePath();
181 $cardThumbnailImagePath = $certificate->getThumbnailImagePath();
183 $xsl = $certificate->getCertificateContent();
185 foreach ($directoryInformation as $file) {
186 if (strcmp($file[
'type'],
'file') === 0) {
187 $filePath = $importPath . $file[
'entry'];
188 if (strpos($file[
'entry'],
'.xml') !==
false) {
192 $xsl = preg_replace_callback(
193 "/url\([']{0,1}(.*?)[']{0,1}\)/",
194 function (array $matches) use ($rootDir):
string {
196 dirname($this->fileService->getBackgroundImageDirectory($rootDir)),
199 $fileName = basename($matches[1]);
201 if (
'[BACKGROUND_IMAGE]' === $fileName) {
203 } elseif ($basePath !==
'') {
207 return 'url(' . $basePath . $fileName .
')';
211 } elseif (strpos($file[
'entry'],
'.jpg') !==
false) {
212 $newBackgroundImageName =
'background_' . $newVersion .
'.jpg';
213 $newPath = $this->certificatePath . $newBackgroundImageName;
216 $backgroundImagePath = $this->certificatePath . $newBackgroundImageName;
221 $thumbnailImagePath = $rootDir . $backgroundImageThumbPath;
223 $originalImagePath = $rootDir . $newPath;
224 $this->utilHelper->convertImage(
230 } elseif (strpos($file[
'entry'],
'.svg') !==
false) {
231 $newCardThumbnailName =
'thumbnail_' . $newVersion .
'.svg';
232 $newPath = $this->certificatePath . $newCardThumbnailName;
236 $cardThumbnailImagePath = $this->certificatePath . $newCardThumbnailName;
241 $jsonEncodedTemplateValues = json_encode(
242 $this->placeholderDescriptionObject->getPlaceholderDescriptions(),
246 $newHashValue = hash(
250 $backgroundImagePath,
251 $jsonEncodedTemplateValues,
252 $cardThumbnailImagePath
258 $this->objectHelper->lookupType($this->objectId),
261 $jsonEncodedTemplateValues,
266 $backgroundImagePath,
267 $cardThumbnailImagePath
270 $this->templateRepository->save($template);
273 }
catch (Throwable
$e) {
274 $this->
logger->error(sprintf(
'Error during certificate import: %s',
$e->getMessage()));
275 $this->
logger->error($e->getTraceAsString());
291 $type = $this->objectHelper->lookupType($this->objectId);
294 $dir = $this->certificatePath . time() .
'__' .
$installationID .
'__' .
$type .
'__' . $certificateId .
'__certificate/';
302 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
__construct(int $objectId, string $certificatePath, ilCertificatePlaceholderDescription $placeholderDescriptionObject, ilLogger $logger, Filesystem $filesystem, ?ilCertificateTemplateRepository $templateRepository=null, ?ilCertificateObjectHelper $objectHelper=null, ?ilCertificateUtilHelper $utilHelper=null, ?ilDBInterface $database=null, ?ilCertificateBackgroundImageFileService $fileService=null, ?SVGBlacklistPreProcessor $svg_blacklist_processor=null)
getBackgroundImageThumbnailPath()
createArchiveDirectory(string $installationID)
Creates a directory for a zip archive containing multiple certificates.
ilCertificateUtilHelper $utilHelper
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...