Fix qti import see BT#12738

pull/2487/head
jmontoyaa 9 years ago
parent 376a55486b
commit 078b23766a
  1. 11
      main/exercise/export/exercise_import.inc.php
  2. 17
      main/inc/lib/fileUpload.lib.php

@ -43,7 +43,7 @@ function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath)
1,
null,
null,
null,
true,
null,
null,
false
@ -69,13 +69,18 @@ function import_exercise($file)
global $questionTempDir;
global $resourcesLinks;
$baseWorkDir = api_get_path(SYS_ARCHIVE_PATH).'qti2';
$baseWorkDir = api_get_path(SYS_ARCHIVE_PATH).'qti2/';
if (!is_dir($baseWorkDir)) {
mkdir($baseWorkDir, api_get_permissions_for_new_directories(), true);
}
$uploadPath = '/';
$uploadPath = api_get_unique_id().'/';
if (!is_dir($baseWorkDir.$uploadPath)) {
mkdir($baseWorkDir.$uploadPath, api_get_permissions_for_new_directories(), true);
}
// set some default values for the new exercise
$exercise_info = array();
$exercise_info['name'] = preg_replace('/.zip$/i', '', $file);

@ -267,7 +267,8 @@ function handle_uploaded_document(
$maxSpace,
$sessionId,
$groupId,
$output
$output,
$onlyUploadFile
);
} elseif ($unzip == 1 && !preg_match('/.zip$/', strtolower($uploadedFile['name']))) {
// We can only unzip ZIP files (no gz, tar,...)
@ -1036,14 +1037,15 @@ function unzip_uploaded_file($uploaded_file, $upload_path, $base_work_dir, $max_
* @param array $courseInfo
* @param array $userInfo
* @param array $uploaded_file - follows the $_FILES Structure
* @param string $upload_path - destination of the upload.
* @param string $uploadPath - destination of the upload.
* This path is to append to $base_work_dir
* @param string $base_work_dir - base working directory of the module
* @param int $maxFilledSpace - amount of bytes to not exceed in the base
* working directory
* @param int $sessionId
* @param int $groupId group.id
* @param boolean $output Optional. If no output not wanted on success, set to false.
* @param bool $output Optional. If no output not wanted on success, set to false.
* @param bool $onlyUploadFile
*
* @return boolean true if it succeeds false otherwise
*/
@ -1056,7 +1058,8 @@ function unzip_uploaded_document(
$maxFilledSpace,
$sessionId = 0,
$groupId = 0,
$output = true
$output = true,
$onlyUploadFile = false
) {
$zip = new PclZip($uploaded_file['tmp_name']);
@ -1087,6 +1090,7 @@ function unzip_uploaded_document(
PCLZIP_OPT_REPLACE_NEWER
);
if ($onlyUploadFile === false) {
// Add all documents in the unzipped folder to the database
add_all_documents_in_folder_to_database(
$courseInfo,
@ -1098,6 +1102,11 @@ function unzip_uploaded_document(
$output,
array('path' => $uploadPath)
);
} else {
// Copy result
$fs = new \Symfony\Component\Filesystem\Filesystem();
$fs->mirror($destinationDir, $base_work_dir.$uploadPath, null, ['overwrite']);
}
if (is_dir($destinationDir)) {
rmdirr($destinationDir);

Loading…
Cancel
Save