ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCertificateCloneAction.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26
31{
32 private readonly Filesystem $fileSystem;
34
35 public function __construct(
36 private readonly ilDBInterface $database,
37 private readonly ilCertificatePathFactory $pathFactory,
38 private readonly ilCertificateTemplateRepository $templateRepository,
40 ?ilObjCertificateSettings $global_certificate_settings = null,
41 ) {
42 if (null === $objectHelper) {
44 }
45 $this->objectHelper = $objectHelper;
46 }
47
55 public function cloneCertificate(
56 ilObject $oldObject,
57 ilObject $newObject,
58 string $iliasVersion = ILIAS_VERSION_NUMERIC,
59 string $webDir = CLIENT_WEB_DIR
60 ): void {
61 $oldType = $oldObject->getType();
62 $newType = $newObject->getType();
63
64 if ($oldType !== $newType) {
65 throw new ilException(sprintf(
66 'The types "%s" and "%s" for cloning does not match',
67 $oldType,
68 $newType
69 ));
70 }
71
72 $certificatePath = $this->pathFactory->create($newObject);
73
74 $templates = $this->templateRepository->fetchCertificateTemplatesByObjId($oldObject->getId());
75
77 foreach ($templates as $template) {
78 $newTemplate = new ilCertificateTemplate(
79 $newObject->getId(),
80 $this->objectHelper->lookupType($newObject->getId()),
81 $template->getCertificateContent(),
82 $template->getCertificateHash(),
83 $template->getTemplateValues(),
84 $template->getVersion(),
85 $iliasVersion,
86 time(),
87 $template->isCurrentlyActive(),
88 $template->getBackgroundImagePath(),
89 $template->getTileImagePath(),
90 $template->getBackgroundImageIdentification(),
91 $template->getTileImageIdentification()
92 );
93
94 $this->templateRepository->save($newTemplate);
95 }
96
97 // #10271
98 if ($this->isActive($oldObject->getId())) {
99 $this->database->replace(
100 'il_certificate',
101 ['obj_id' => ['integer', $newObject->getId()]],
102 []
103 );
104 }
105 }
106
107 private function isActive(int $objectId): bool
108 {
109 $sql = 'SELECT 1 FROM il_certificate WHERE obj_id = ' . $this->database->quote($objectId, 'integer');
110
111 return (bool) $this->database->fetchAssoc($this->database->query($sql));
112 }
113}
Indicates that a file is missing or not found.
Indicates general problems with the input or output operations.
Definition: IOException.php:28
__construct(private readonly ilDBInterface $database, private readonly ilCertificatePathFactory $pathFactory, private readonly ilCertificateTemplateRepository $templateRepository, ?ilCertificateObjectHelper $objectHelper=null, ?ilObjCertificateSettings $global_certificate_settings=null,)
readonly ilCertificateObjectHelper $objectHelper
Base class for ILIAS Exception handling.
Class ilObjCertificateSettings.
Class ilObject Basic functions for all objects.
const CLIENT_WEB_DIR
Definition: constants.php:47
const ILIAS_VERSION_NUMERIC
The filesystem interface provides the public interface for the Filesystem service API consumer.
Definition: Filesystem.php:37
Interface ilDBInterface.