Skip to content

Commit

Permalink
[FIX] 0038523: Download in Manage-Tab wirft Fehler
Browse files Browse the repository at this point in the history
  • Loading branch information
chfsx committed Nov 17, 2023
1 parent 71f3518 commit 30a5a2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ public function run(array $input, \ILIAS\BackgroundTasks\Observer $observer): Va
$object_name = $object->getTitle();
$object_temp_dir = ""; // empty as content will be added in recurseFolder and getFileDirs

if ($object_type == "fold") {
if ($object_type === "fold" || $object_type === "crs") {
$num_recursions = 0;
$files_from_folder = self::recurseFolder($object_ref_id, $object_name, $object_temp_dir, $num_recursions, $initiated_by_folder_action);
$files = array_merge($files, $files_from_folder);
} elseif (($object_type == "file") && (($file_dirs = self::getFileDirs(
} elseif (($object_type === "file") && (($file_dirs = self::getFileDirs(
$object_ref_id,
$object_name,
$object_temp_dir
Expand Down Expand Up @@ -145,10 +145,15 @@ private static function getFileDirs($a_ref_id, $a_file_name, $a_temp_dir)
if ($ilAccess->checkAccessOfUser($user->getId(), "read", "", $a_ref_id)) {
$file = new ilObjFile($a_ref_id);
$source_dir = $file->getFile();

if (@!is_file($source_dir)) {
return false;
}
$target_dir = $a_temp_dir . '/' . ilFileUtils::getASCIIFilename($a_file_name);
$filname_with_suffix = ilFileUtils::getASCIIFilename(
rtrim($a_file_name, '.') . '.' . $file->getFileExtension()
);

$target_dir = $a_temp_dir . '/' . $filname_with_suffix;

// #25025: allow duplicate filenames by appending an incrementing
// number per duplicate in brackets to the name.
Expand Down Expand Up @@ -207,7 +212,7 @@ private static function recurseFolder($a_ref_id, $a_folder_name, $a_temp_dir, $a
$files_from_folder = self::recurseFolder($child["ref_id"], $child['title'], $temp_dir, $num_recursions, $a_initiated_by_folder_action);
$files = array_merge($files, $files_from_folder);
} else {
if (($child["type"] == "file") && (($dirs = self::getFileDirs($child["ref_id"], $child['title'], $temp_dir)) !== false)) {
if (($child["type"] === "file") && (($dirs = self::getFileDirs($child["ref_id"], $child['title'], $temp_dir)) !== false)) {
$files[] = $dirs;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class ilZipJob extends AbstractJob
{
private ?ilLogger $logger;

private \ILIAS\Filesystem\Util\Archive\Archives $archives;

/**
* Construct
Expand All @@ -39,6 +39,7 @@ public function __construct()
{
global $DIC;
$this->logger = $DIC->logger()->cal();
$this->archives = $DIC->archives();
}


Expand Down Expand Up @@ -80,10 +81,15 @@ public function run(array $input, \ILIAS\BackgroundTasks\Observer $observer): Va
{
$this->logger->debug('Start zipping input dir!');
$this->logger->dump($input);
$tmpdir = rtrim($input[0]->getValue(), "/");
$string = $input[0]->getValue();
$tmpdir = rtrim($string, "/");
$this->logger->debug('Zipping directory:' . $tmpdir);
$zip_name = $tmpdir . '.zip';
ilFileUtils::zip($tmpdir, $zip_name);

$zip = $this->archives->zip([]);
$zip->addDirectory($tmpdir);
$zip_stream = $zip->get();
stream_copy_to_stream($zip_stream->detach(), fopen($zip_name, 'wb')); // we currently have to write to disk

// delete temp directory
ilFileUtils::delDir($tmpdir);
Expand Down

0 comments on commit 30a5a2f

Please sign in to comment.