Skip to content

Commit

Permalink
Certificate: Fix cloning templates (Mantis 32127) (#4070)
Browse files Browse the repository at this point in the history
(cherry picked from commit 57c10c3)
  • Loading branch information
mjansenDatabay committed Feb 22, 2022
1 parent 0e5dfde commit d4af8bc
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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 = '';
Expand Down
21 changes: 18 additions & 3 deletions Services/Certificate/test/ilCertificateCloneActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,26 @@ public function testCloneCertificate() : void
'/some/where/background.jpg',
'/some/where/card_thumb.jpg',
$id = null
),
new ilCertificateTemplate(
30,
'crs',
'<xml> Some Content </xml>',
md5('<xml> Some Content </xml>'),
'[]',
'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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit d4af8bc

Please sign in to comment.