Commit 7563daad authored by Son Nguyen's avatar Son Nguyen Committed by Robert Lyon

Bug 1602452: Using Phar to extract archive artefacts

This will support zipped, tar and gzip files

Fix errors when extract an archive which has more than
10 entries

behatnotneeded

Change-Id: I60c53a59ad28bbc1ae9ebfcd0d638b6d09f7ecb7
parent a0d57f31
......@@ -58,12 +58,9 @@ if (!empty($folderid)) {
throw new AccessDeniedException(get_string('cannotextractfileinfoldersubmitted', 'artefact.file'));
}
}
try {
$zipinfo = $file->read_archive();
}
catch (SystemException $e) {
$message = get_string('invalidarchive', 'artefact.file');
}
// Read the archive information, throw an ArchiveException if error
$zipinfo = $file->read_archive();
if ($zipinfo) {
$quotaallowed = false;
......@@ -147,7 +144,12 @@ function unzip_artefact_submit(Pieform $form, $values) {
$from = files_page($file);
if (count($zipinfo->names) > 10) {
$SESSION->set('unzip', array('file' => $file->get('id'), 'from' => $from, 'artefacts' => count($zipinfo->names), 'zipinfo' => $zipinfo));
$SESSION->set('unzip', array('file' => $file->get('id'),
'from' => $from,
'artefacts' => count($zipinfo->names),
'zipinfo' => $zipinfo
)
);
$smarty = smarty();
$smarty->display('artefact:file:extract-progress.tpl');
exit;
......
......@@ -310,7 +310,13 @@ $string['filesextractedfromarchive'] = 'Files extracted from archive';
$string['filesextractedfromziparchive'] = 'Files extracted from Zip archive';
$string['fileswillbeextractedintofolder'] = 'Files will be extracted into %s';
$string['insufficientquotaforunzip'] = 'Your remaining file quota is too small to unzip this file. You can either delete files to free up space or contact your administrator to have your quota increased.';
$string['invalidarchive'] = 'Error reading archive file.';
$string['invalidarchive1'] = 'Invalid archive file.';
$string['invalidarchivehandle'] = 'Invalid archive file handle.';
$string['cannotopenarchive'] = 'Can not open the archive file %s.';
$string['cannotreadarchivecontent'] = 'Can not read the archive content.';
$string['cannotextractarchive'] = 'Unable to extract archive into %s.';
$string['cannotcopytemparchive'] = 'Unable to copy the archive file from %s to %s.';
$string['cannotdeletetemparchive'] = 'Unable to delete the temporary archive file %s.';
$string['pleasewaitwhileyourfilesarebeingunzipped'] = 'Please wait while your files are being unzipped.';
$string['spacerequired'] = 'Space required';
$string['unzipprogress'] = '%s files/folders created.';
......
This diff is collapsed.
......@@ -838,6 +838,9 @@ $string['phpuploaderror_6'] = 'Missing a temporary folder.';
$string['phpuploaderror_7'] = 'Failed to write file to disk. Check that your filesystem has enough space to write to the Mahara dataroot and/or the PHP \'upload_tmp_dir\' directories.';
$string['phpuploaderror_8'] = 'File upload stopped by extension.';
$string['adminphpuploaderror'] = 'A file upload error was probably caused by your server configuration.';
$string['noinputnamesupplied'] = 'No input name is provided.';
$string['cannotrenametempfile'] = 'Can not rename the temporary file.';
$string['failedmovingfiletodataroot'] = 'Can not move uploaded file to dataroot.';
$string['youraccounthasbeensuspendedtext2'] = 'Your account at %s has been suspended by %s.'; // @todo: more info?
$string['youraccounthasbeensuspendedtextcron'] = 'Your account at %s has been suspended.';
......
......@@ -1062,3 +1062,17 @@ class ExportException extends SystemException {
return $this->getMessage();
}
}
/**
* An exception related to read/write/extract archive artefact
*/
class ArchiveException extends SystemException {
public function strings() {
return array_merge(parent::strings(),
array('message' => get_string('invalidarchive1', 'artefact.file'),
'title' => get_string('invalidarchive1', 'artefact.file')));
}
public function render_exception() {
return $this->getMessage();
}
}
......@@ -71,11 +71,11 @@ class upload_manager {
return false;
}
else {
return get_string('noinputnamesupplied');
return get_string('noinputnamesupplied', 'mahara');
}
}
$file = $_FILES[$name];
$file = $_FILES[$name];
$maxsize = get_config('maxuploadsize');
if (isset($this->inputindex)) {
$size = $file['size'][$this->inputindex];
......@@ -190,7 +190,7 @@ class upload_manager {
chmod($destination . '/' . $newname, get_config('filepermissions'));
return false;
}
return get_string('failedmovingfiletodataroot');
return get_string('failedmovingfiletodataroot', 'mahara');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment