Skip to content

Commit

Permalink
Certificate: Throw exception if archive should be created without files
Browse files Browse the repository at this point in the history
See: https://mantis.ilias.de/view.php?id=38994
(cherry picked from commit b74bf43)
  • Loading branch information
mjansenDatabay committed Nov 24, 2023
1 parent c9ee16f commit f402950
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
class ilUserCertificateZip
{
private readonly string $typeInFileName;
private bool $files_added_to_archive = false;

public function __construct(
private readonly int $objectId,
Expand Down Expand Up @@ -71,10 +72,18 @@ public function addPDFtoArchiveDirectory(string $pdfdata, string $dir, string $f
$fh = fopen($dir . $filename, 'wb');
fwrite($fh, $pdfdata);
fclose($fh);
$this->files_added_to_archive = true;
}

/**
* @throws \ILIAS\Filesystem\Exception\IOException
*/
public function zipCertificatesInArchiveDirectory(string $dir, bool $deliver = true): string
{
if (!$this->files_added_to_archive) {
throw new \ILIAS\Filesystem\Exception\IOException('No files added to archive directory');
}

$zipFile = time() . '__' . $this->installionId . '__' . $this->typeInFileName . '__' . $this->objectId . '__certificates.zip';
$zipFilePath = $this->webDirectory . $this->certificatePath . $zipFile;

Expand Down

0 comments on commit f402950

Please sign in to comment.