diff --git a/Services/Certificate/classes/Template/Action/Clone/class.ilCertificateCloneAction.php b/Services/Certificate/classes/Template/Action/Clone/class.ilCertificateCloneAction.php
index f95825da2697..c51ca63a0a70 100644
--- a/Services/Certificate/classes/Template/Action/Clone/class.ilCertificateCloneAction.php
+++ b/Services/Certificate/classes/Template/Action/Clone/class.ilCertificateCloneAction.php
@@ -19,6 +19,7 @@ class ilCertificateCloneAction
private Filesystem $fileSystem;
private ilCertificateObjectHelper $objectHelper;
private string $webDirectory;
+ private string $global_certificate_path;
public function __construct(
ilDBInterface $database,
@@ -27,7 +28,8 @@ public function __construct(
?Filesystem $fileSystem = null,
?ilLogger $logger = null,
?ilCertificateObjectHelper $objectHelper = null,
- string $webDirectory = CLIENT_WEB_DIR
+ string $webDirectory = CLIENT_WEB_DIR,
+ string $global_certificate_path = null
) {
$this->database = $database;
$this->pathFactory = $pathFactory;
@@ -50,6 +52,16 @@ public function __construct(
}
$this->objectHelper = $objectHelper;
+ if (null === $global_certificate_path) {
+ $global_certificate_path = str_replace(
+ '[CLIENT_WEB_DIR]',
+ '',
+ ilObjCertificateSettingsAccess::getBackgroundImagePath(true)
+ );
+ }
+ $this->global_certificate_path = $global_certificate_path;
+
+
$this->webDirectory = $webDirectory;
}
@@ -93,42 +105,46 @@ public function cloneCertificate(
$newBackgroundImage = '';
$newBackgroundImageThumbnail = '';
- if ($this->fileSystem->has($backgroundImagePath) &&
- !$this->fileSystem->hasDir($backgroundImagePath)
- ) {
- $newBackgroundImage = $certificatePath . $backgroundImageFile;
- $newBackgroundImageThumbnail = str_replace(
- $webDir,
- '',
- $this->getBackgroundImageThumbPath($certificatePath)
- );
- if ($this->fileSystem->has($newBackgroundImage) &&
- !$this->fileSystem->hasDir($newBackgroundImage)
+ if ($this->global_certificate_path !== $backgroundImagePath) {
+ if ($this->fileSystem->has($backgroundImagePath) &&
+ !$this->fileSystem->hasDir($backgroundImagePath)
) {
- $this->fileSystem->delete($newBackgroundImage);
+ $newBackgroundImage = $certificatePath . $backgroundImageFile;
+ $newBackgroundImageThumbnail = str_replace(
+ $webDir,
+ '',
+ $this->getBackgroundImageThumbPath($certificatePath)
+ );
+ if ($this->fileSystem->has($newBackgroundImage) &&
+ !$this->fileSystem->hasDir($newBackgroundImage)
+ ) {
+ $this->fileSystem->delete($newBackgroundImage);
+ }
+
+ $this->fileSystem->copy(
+ $backgroundImagePath,
+ $newBackgroundImage
+ );
}
- $this->fileSystem->copy(
- $backgroundImagePath,
- $newBackgroundImage
- );
- }
-
- if (
- $newBackgroundImageThumbnail !== '' &&
- $this->fileSystem->has($backgroundImageThumbnail) &&
- !$this->fileSystem->hasDir($backgroundImageThumbnail)
- ) {
- if ($this->fileSystem->has($newBackgroundImageThumbnail) &&
- !$this->fileSystem->hasDir($newBackgroundImageThumbnail)
+ if (
+ $newBackgroundImageThumbnail !== '' &&
+ $this->fileSystem->has($backgroundImageThumbnail) &&
+ !$this->fileSystem->hasDir($backgroundImageThumbnail)
) {
- $this->fileSystem->delete($newBackgroundImageThumbnail);
+ if ($this->fileSystem->has($newBackgroundImageThumbnail) &&
+ !$this->fileSystem->hasDir($newBackgroundImageThumbnail)
+ ) {
+ $this->fileSystem->delete($newBackgroundImageThumbnail);
+ }
+
+ $this->fileSystem->copy(
+ $backgroundImageThumbnail,
+ $newBackgroundImageThumbnail
+ );
}
-
- $this->fileSystem->copy(
- $backgroundImageThumbnail,
- $newBackgroundImageThumbnail
- );
+ } else {
+ $newBackgroundImage = $this->global_certificate_path;
}
$newCardThumbImage = '';
diff --git a/Services/Certificate/test/ilCertificateCloneActionTest.php b/Services/Certificate/test/ilCertificateCloneActionTest.php
index 6221c15c1978..abf2c070f379 100644
--- a/Services/Certificate/test/ilCertificateCloneActionTest.php
+++ b/Services/Certificate/test/ilCertificateCloneActionTest.php
@@ -57,12 +57,26 @@ public function testCloneCertificate() : void
'/some/where/background.jpg',
'/some/where/card_thumb.jpg',
$id = null
+ ),
+ new ilCertificateTemplate(
+ 30,
+ 'crs',
+ ' Some Content ',
+ md5(' Some Content '),
+ '[]',
+ '3',
+ 'v5.3.0',
+ 123456789,
+ true,
+ '/certificates/default/background.jpg',
+ '/some/where/card_thumb.jpg',
+ $id = null
)
)
);
$templateRepository
- ->expects($this->exactly(2))
+ ->expects($this->exactly(3))
->method('save');
$fileSystem = $this->getMockBuilder(\ILIAS\Filesystem\Filesystem::class)
@@ -72,7 +86,7 @@ public function testCloneCertificate() : void
->willReturn(true);
$fileSystem
- ->expects($this->exactly(6))
+ ->expects($this->exactly(7))
->method('copy');
$logger = $this->getMockBuilder(ilLogger::class)
@@ -92,7 +106,8 @@ public function testCloneCertificate() : void
$fileSystem,
$logger,
$objectHelper,
- 'some/web/directory'
+ 'some/web/directory',
+ '/certificates/default/background.jpg'
);
$oldObject = $this->getMockBuilder(ilObject::class)