19declare(strict_types=1);
40 private readonly \ILIAS\Data\Factory
$df;
44 private readonly
int $objectId,
45 private readonly
string $certificatePath,
49 private readonly IRSS $irss,
58 if ($database ===
null) {
59 $database =
$DIC->database();
77 $this->df =
$df ?? new \ILIAS\Data\Factory();
88 public function import(
89 string $path_to_zip_file,
97 $clean_up_import_dir =
function () use (&$import_path) {
102 }
catch (Throwable
$e) {
103 $this->
logger->error(sprintf(
"Can't clean up import directory: %s",
$e->getMessage()));
104 $this->
logger->error($e->getTraceAsString());
108 $result = $this->df->ok(
true);
113 function () use ($path_to_zip_file,
$filename, $root_directory, $import_path): \
ILIAS\Data\Result {
114 $result = $this->utilHelper->moveUploadedFile(
117 $root_directory . $import_path .
$filename
120 return $this->df->ok($result);
123 return $this->df->error(
125 'Could not move uploaded file %s to %s',
127 $root_directory . $import_path .
$filename
132 ->then(
function () use ($root_directory, $import_path,
$filename): \
ILIAS\Data\Result {
133 $destination_dir = $root_directory . $import_path;
134 $unzip = $this->utilHelper->unzip(
135 $root_directory . $import_path .
$filename,
140 $unzipped = $unzip->extract();
146 return $this->df->ok($unzipped);
149 return $this->df->error(
151 'Could not unzip file %s to %s',
152 $root_directory . $import_path .
$filename,
157 ->then(
function () use ($import_path,
$filename): \
ILIAS\Data\Result {
163 $contents = $this->
filesystem->listContents($import_path);
164 foreach ($contents as $file) {
165 if (!$file->isFile()) {
169 if (str_contains($file->getPath(),
'.xml')) {
173 if (str_contains($file->getPath(),
'.svg')) {
174 $stream = $this->
filesystem->readStream($file->getPath());
175 $file_metadata = $stream->getMetadata();
176 $absolute_file_path = $file_metadata[
'uri'];
179 pathinfo($absolute_file_path)[
'basename'],
180 filesize($absolute_file_path),
181 mime_content_type($absolute_file_path)
184 $processing_result = $this->svg_blacklist_processor->process($stream, $metadata);
185 if ($processing_result->getCode() !== ProcessingStatus::OK) {
186 return $this->df->error(
187 sprintf(
'SVG file check failed. Reason: %s', $processing_result->getMessage())
193 if ($num_xml_files === 0) {
194 return $this->df->error(
195 sprintf(
'No XML files found in import directory: %s', $import_path)
199 return $this->df->ok($contents);
204 ->then(
function (array $contents) use ($ilias_version) {
205 $certificate = $this->templateRepository->fetchCurrentlyUsedCertificate($this->objectId);
207 $current_version = $certificate->getVersion();
208 $upcoming_verion = $current_version + 1;
209 $xsl = $certificate->getCertificateContent();
211 foreach ($contents as $file) {
212 if (!$file->isFile()) {
216 if (str_contains($file->getPath(),
'.xml')) {
217 $xsl = $this->
filesystem->read($file->getPath());
219 "/url\([']{0,1}(.*?)[']{0,1}\)/",
220 'url([BACKGROUND_IMAGE])',
223 } elseif (str_contains($file->getPath(),
'.jpg')) {
224 $background_rid = $this->irss->manage()->stream(
225 $this->
filesystem->readStream($file->getPath()),
228 } elseif (str_contains($file->getPath(),
'.svg')) {
229 $tile_image_rid = $this->irss->manage()->stream(
230 $this->
filesystem->readStream($file->getPath()),
236 $serialized_template_values = json_encode(
237 $this->placeholderDescriptionObject->getPlaceholderDescriptions(),
241 $upcoming_version_hash = hash(
245 isset($background_rid) ? $this->irss->manage()->getResource(
247 )->getStorageID() :
'',
248 $serialized_template_values,
249 isset($tile_image_rid) ? $this->irss->manage()->getResource(
251 )->getStorageID() :
''
257 $this->objectHelper->lookupType($this->objectId),
259 $upcoming_version_hash,
260 $serialized_template_values,
267 isset($background_rid) ? $background_rid->serialize() :
'',
268 isset($tile_image_rid) ? $tile_image_rid->serialize() :
''
271 $this->templateRepository->save($template);
276 }
catch (Throwable
$e) {
277 $this->
logger->error(sprintf(
'Error during certificate import: %s',
$e->getMessage()));
278 $this->
logger->error($e->getTraceAsString());
282 $clean_up_import_dir();
293 $type = $this->objectHelper->lookupType($this->objectId);
294 $certificateId = $this->objectId;
296 $dir = $this->certificatePath . time() .
'__' . $installationID .
'__' . $type .
'__' . $certificateId .
'__certificate/';
Class SVGBlacklistPreProcessor.
Indicates that a file is missing or not found.
Indicates general problems with the input or output operations.
__construct(private readonly int $objectId, private readonly string $certificatePath, private readonly ilCertificatePlaceholderDescription $placeholderDescriptionObject, private readonly ilLogger $logger, private readonly Filesystem $filesystem, private readonly IRSS $irss, ?ilCertificateTemplateRepository $templateRepository=null, ?ilCertificateObjectHelper $objectHelper=null, ?ilCertificateUtilHelper $utilHelper=null, ?ilDBInterface $database=null, ?\ILIAS\Data\Factory $df=null, ?SVGBlacklistPreProcessor $svg_blacklist_processor=null)
readonly ilCertificateTemplateStakeholder $stakeholder
readonly ilCertificateTemplateRepository $templateRepository
readonly ilCertificateObjectHelper $objectHelper
readonly SVGBlacklistPreProcessor $svg_blacklist_processor
createArchiveDirectory(string $installationID)
Creates a directory for a zip archive containing multiple certificates.
readonly ilCertificateUtilHelper $utilHelper
readonly ILIAS Data Factory $df
Just a wrapper class to create Unit Test for other classes.
Component logger with individual log levels by component id.
const ILIAS_VERSION_NUMERIC
The filesystem interface provides the public interface for the Filesystem service API consumer.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
if(!file_exists('../ilias.ini.php'))