From 6734267bfae0df325f4ea7651d5fe6560ce11714 Mon Sep 17 00:00:00 2001 From: Moritz Strohm Date: Tue, 1 Aug 2023 13:11:19 +0200 Subject: fixed errors --- app/controllers/file.php | 9 ++++----- app/views/file/unzipquestion.php | 4 ++-- lib/filesystem/FileArchiveManager.class.php | 22 +++++++++++----------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/controllers/file.php b/app/controllers/file.php index d7dd417..77f0a53 100644 --- a/app/controllers/file.php +++ b/app/controllers/file.php @@ -173,6 +173,8 @@ class FileController extends AuthenticatedController public function unzipquestion_action() { $this->to_plugin = Request::get('to_plugin'); + URLHelper::addLinkParam('to_plugin', $this->to_plugin); + $this->files = []; if ($this->to_plugin) { //Plugin file area. @@ -186,9 +188,6 @@ class FileController extends AuthenticatedController $file_ids = Request::getArray('file_refs'); foreach ($file_ids as $file_id) { $file = $plugin->getPreparedFile($file_id); - /*if ($file instanceof FileType) { - $file = $file->convertToStandardFile(); - }*/ if ($file instanceof FileType) { $this->files[] = $file; } @@ -1619,7 +1618,7 @@ class FileController extends AuthenticatedController if (Request::isPost()) { CSRFProtection::verifyUnsafeRequest(); - if (count($file_ref_ids) === 1) { + if (is_array($file_ref_ids) && count($file_ref_ids) === 1) { // store flag if file is an accessible file $this->store_accessibility_flag($file_ref_ids[0]); } @@ -1686,7 +1685,7 @@ class FileController extends AuthenticatedController } } - if (count($file_ref_ids) === 1) { + if (is_array($file_ref_ids) && count($file_ref_ids) === 1) { if (Config::get()->OERCAMPUS_ENABLED && Config::get()->OER_ENABLE_POST_UPLOAD && $GLOBALS['perm']->have_perm('tutor') diff --git a/app/views/file/unzipquestion.php b/app/views/file/unzipquestion.php index a7e82b1..361ae63 100644 --- a/app/views/file/unzipquestion.php +++ b/app/views/file/unzipquestion.php @@ -1,7 +1,7 @@
- - + + asImg(120, ['style' => 'display: block; margin-left: auto; margin-right: auto;']) ?> diff --git a/lib/filesystem/FileArchiveManager.class.php b/lib/filesystem/FileArchiveManager.class.php index 52ef527..2a06d51 100644 --- a/lib/filesystem/FileArchiveManager.class.php +++ b/lib/filesystem/FileArchiveManager.class.php @@ -828,7 +828,7 @@ class FileArchiveManager * @param FolderType $target_folder The folder where the file shall be stored. * @param User $user The user who wishes to extract the file from the archive. * - * @return FileRef|null FileRef instance on success, null otherwise. + * @return FileType|null FileType instance on success, null otherwise. */ public static function extractFileFromArchive( Studip\ZipArchive $archive, @@ -869,18 +869,18 @@ class FileArchiveManager return null; } - // Ok, we now must create a FileRef: + // Ok, we now must create a File: $file_ref = new FileRef(); $file_ref->file_id = $file->id; $file_ref->folder_id = $target_folder->getId(); $file_ref->user_id = $user->id; $file_ref->name = $file->name; - if ($file_ref->store()) { - return $file_ref; + $file = new StandardFile($file_ref); + if ($saved_file = $target_folder->addFile($file, $user->id)) { + return $saved_file; } - //Something went wrong: abort and clean up! - $file_ref->delete(); + //Something went wrong: return null; } @@ -922,7 +922,7 @@ class FileArchiveManager // loop over all entries in the zip archive and put each entry // in the current folder or one of its subfolders: - $file_refs = []; + $files = []; for ($i = 0; $i < $archive->numFiles; $i++) { $entry_info = $archive->statIndex($i); @@ -977,19 +977,19 @@ class FileArchiveManager //we extract one file: //$entry_info['name'] is necessary because we need the full path //to the entry inside the archive. - $file_ref = self::extractFileFromArchive( + $file = self::extractFileFromArchive( $archive, $entry_info['name'], $extracted_entry_destination_folder, $user ); - if ($file_ref instanceof FileRef) { - $file_refs[] = $file_ref; + if ($file instanceof FileType) { + $files[] = $file; } } } - return $file_refs; + return $files; } } -- cgit v1.0