diff --git a/Services/Certificate/classes/Template/Action/Clone/class.ilCertificateCloneAction.php b/Services/Certificate/classes/Template/Action/Clone/class.ilCertificateCloneAction.php index 8504623963be..56ca2a92bfa8 100644 --- a/Services/Certificate/classes/Template/Action/Clone/class.ilCertificateCloneAction.php +++ b/Services/Certificate/classes/Template/Action/Clone/class.ilCertificateCloneAction.php @@ -40,6 +40,7 @@ class ilCertificateCloneAction * @var string */ private $webDirectory; + private $global_certificate_path; /** * @param ilDBInterface $database @@ -57,7 +58,8 @@ public function __construct( \ILIAS\Filesystem\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; @@ -80,6 +82,15 @@ 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; } @@ -122,43 +133,49 @@ 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 ( - strlen($newBackgroundImageThumbnail) > 0 && - $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 = ''; - $cardThumbImagePath = (string) $template->getThumbnailImagePath(); - + $cardThumbImagePath = $template->getThumbnailImagePath(); if ($this->fileSystem->has($cardThumbImagePath) && !$this->fileSystem->hasDir($cardThumbImagePath)) { $newCardThumbImage = $certificatePath . basename($cardThumbImagePath); if ($this->fileSystem->has($newCardThumbImage) && !$this->fileSystem->hasDir($newCardThumbImage)) { diff --git a/Services/Certificate/test/ilCertificateCloneActionTest.php b/Services/Certificate/test/ilCertificateCloneActionTest.php index 015aca5ca34a..5599805619a4 100644 --- a/Services/Certificate/test/ilCertificateCloneActionTest.php +++ b/Services/Certificate/test/ilCertificateCloneActionTest.php @@ -61,12 +61,26 @@ public function testCloneCertificate() '/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') @@ -76,7 +90,7 @@ public function testCloneCertificate() ->willReturn(true); $fileSystem - ->expects($this->exactly(6)) + ->expects($this->exactly(7)) ->method('copy'); $logger = $this->getMockBuilder('ilLogger') @@ -96,7 +110,8 @@ public function testCloneCertificate() $fileSystem, $logger, $objectHelper, - 'some/web/directory' + 'some/web/directory', + '/certificates/default/background.jpg' ); $oldObject = $this->getMockBuilder('ilObject')