ILIAS  release_8 Revision v8.24
ilCertificateTemplateImportAction Class Reference
+ Collaboration diagram for ilCertificateTemplateImportAction:

Public Member Functions

 __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)
 
 import (string $zipFile, string $filename, string $rootDir=CLIENT_WEB_DIR, string $iliasVerision=ILIAS_VERSION_NUMERIC, string $installationID=IL_INST_ID)
 

Private Member Functions

 createArchiveDirectory (string $installationID)
 Creates a directory for a zip archive containing multiple certificates. More...
 
 getBackgroundImageThumbnailPath ()
 

Private Attributes

int $objectId
 
string $certificatePath
 
ilCertificateTemplateRepository $templateRepository
 
ilCertificatePlaceholderDescription $placeholderDescriptionObject
 
ilLogger $logger
 
Filesystem $filesystem
 
ilCertificateObjectHelper $objectHelper
 
ilCertificateUtilHelper $utilHelper
 
string $installationID
 
ilCertificateBackgroundImageFileService $fileService
 
SVGBlacklistPreProcessor $svg_blacklist_processor
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilCertificateTemplateImportAction::__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 
)

Definition at line 46 of file class.ilCertificateTemplateImportAction.php.

58 {
59 $this->objectId = $objectId;
60 $this->certificatePath = $certificatePath;
61
62 $this->logger = $logger;
63 if (null === $database) {
64 global $DIC;
65 $database = $DIC->database();
66 }
67
68 $this->filesystem = $filesystem;
69
70 $this->placeholderDescriptionObject = $placeholderDescriptionObject;
71
72 if (null === $templateRepository) {
74 }
75 $this->templateRepository = $templateRepository;
76
77 if (null === $objectHelper) {
79 }
80 $this->objectHelper = $objectHelper;
81
82 if (null === $utilHelper) {
84 }
85 $this->utilHelper = $utilHelper;
86
87 if (null === $fileService) {
91 );
92 }
93 $this->fileService = $fileService;
94 if (null === $svg_blacklist_processor) {
96 }
97 $this->svg_blacklist_processor = $svg_blacklist_processor;
98 }
ilCertificateBackgroundImageFileService $fileService
ilCertificatePlaceholderDescription $placeholderDescriptionObject
Just a wrapper class to create Unit Test for other classes.
global $DIC
Definition: feed.php:28

References $certificatePath, $DIC, $fileService, $filesystem, $logger, $objectHelper, $objectId, $placeholderDescriptionObject, $svg_blacklist_processor, $templateRepository, $utilHelper, ILIAS\Repository\filesystem(), and ILIAS\Repository\logger().

+ Here is the call graph for this function:

Member Function Documentation

◆ createArchiveDirectory()

ilCertificateTemplateImportAction::createArchiveDirectory ( string  $installationID)
private

Creates a directory for a zip archive containing multiple certificates.

Parameters
string$installationID
Returns
string The created archive directory
Exceptions
IOException

Definition at line 289 of file class.ilCertificateTemplateImportAction.php.

289 : string
290 {
291 $type = $this->objectHelper->lookupType($this->objectId);
292 $certificateId = $this->objectId;
293
294 $dir = $this->certificatePath . time() . '__' . $installationID . '__' . $type . '__' . $certificateId . '__certificate/';
295 $this->filesystem->createDir($dir);
296
297 return $dir;
298 }
$type

References $installationID, $objectId, $type, and ILIAS\Repository\filesystem().

Referenced by import().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getBackgroundImageThumbnailPath()

ilCertificateTemplateImportAction::getBackgroundImageThumbnailPath ( )
private

Definition at line 300 of file class.ilCertificateTemplateImportAction.php.

300 : string
301 {
302 return $this->certificatePath . 'background.jpg.thumb.jpg';
303 }

Referenced by import().

+ Here is the caller graph for this function:

◆ import()

ilCertificateTemplateImportAction::import ( string  $zipFile,
string  $filename,
string  $rootDir = CLIENT_WEB_DIR,
string  $iliasVerision = ILIAS_VERSION_NUMERIC,
string  $installationID = IL_INST_ID 
)
Parameters
string$zipFile
string$filename
string$rootDir
string$iliasVerision
string | false$installationID
Returns
bool
Exceptions
FileAlreadyExistsException
FileNotFoundException
IOException
ilDatabaseException
ilException

Definition at line 113 of file class.ilCertificateTemplateImportAction.php.

119 : bool {
120 $importPath = $this->createArchiveDirectory($installationID);
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(
130 $rootDir . $importPath . $filename,
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
158 $metadata = new Metadata(
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) {
189 $xsl = $this->filesystem->read($filePath);
190 // as long as we cannot make RPC calls in a given directory, we have
191 // to add the complete path to every url
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;
214 $this->filesystem->copy($filePath, $newPath);
215
216 $backgroundImagePath = $this->certificatePath . $newBackgroundImageName;
217 // upload of the background image, create a thumbnail
218
219 $backgroundImageThumbPath = $this->getBackgroundImageThumbnailPath();
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
234 $this->filesystem->copy($filePath, $newPath);
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
256 $template = new ilCertificateTemplate(
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 {
279 $this->filesystem->deleteDir($importPath);
280 }
281 }
$filename
Definition: buildRTE.php:78
createArchiveDirectory(string $installationID)
Creates a directory for a zip archive containing multiple certificates.

References Vendor\Package\$e, $filename, createArchiveDirectory(), ILIAS\Repository\filesystem(), getBackgroundImageThumbnailPath(), and ILIAS\Repository\logger().

+ Here is the call graph for this function:

Field Documentation

◆ $certificatePath

string ilCertificateTemplateImportAction::$certificatePath
private

Definition at line 35 of file class.ilCertificateTemplateImportAction.php.

Referenced by __construct().

◆ $fileService

ilCertificateBackgroundImageFileService ilCertificateTemplateImportAction::$fileService
private

Definition at line 43 of file class.ilCertificateTemplateImportAction.php.

Referenced by __construct().

◆ $filesystem

Filesystem ilCertificateTemplateImportAction::$filesystem
private

Definition at line 39 of file class.ilCertificateTemplateImportAction.php.

Referenced by __construct().

◆ $installationID

string ilCertificateTemplateImportAction::$installationID
private

Definition at line 42 of file class.ilCertificateTemplateImportAction.php.

Referenced by createArchiveDirectory().

◆ $logger

ilLogger ilCertificateTemplateImportAction::$logger
private

Definition at line 38 of file class.ilCertificateTemplateImportAction.php.

Referenced by __construct().

◆ $objectHelper

ilCertificateObjectHelper ilCertificateTemplateImportAction::$objectHelper
private

Definition at line 40 of file class.ilCertificateTemplateImportAction.php.

Referenced by __construct().

◆ $objectId

int ilCertificateTemplateImportAction::$objectId
private

◆ $placeholderDescriptionObject

ilCertificatePlaceholderDescription ilCertificateTemplateImportAction::$placeholderDescriptionObject
private

Definition at line 37 of file class.ilCertificateTemplateImportAction.php.

Referenced by __construct().

◆ $svg_blacklist_processor

SVGBlacklistPreProcessor ilCertificateTemplateImportAction::$svg_blacklist_processor
private

Definition at line 44 of file class.ilCertificateTemplateImportAction.php.

Referenced by __construct().

◆ $templateRepository

ilCertificateTemplateRepository ilCertificateTemplateImportAction::$templateRepository
private

Definition at line 36 of file class.ilCertificateTemplateImportAction.php.

Referenced by __construct().

◆ $utilHelper

ilCertificateUtilHelper ilCertificateTemplateImportAction::$utilHelper
private

Definition at line 41 of file class.ilCertificateTemplateImportAction.php.

Referenced by __construct().


The documentation for this class was generated from the following file: