Commit f5c4ed7b authored by Penny Leach's avatar Penny Leach
Browse files

Portfolio data transfer: #3176 create a unziptempdir setting

Some shared hosts don't allow unzip to run outside of cwd and /tmp
So this creates a new config option to be able to set it to /tmp (or
anything else)
parent 7f47b0a1
......@@ -720,12 +720,14 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
* Takes the name of a file outside the myfiles area.
* Returns a boolean indicating success or failure.
*/
public static function save_file($pathname, $data, User &$user=null) {
public static function save_file($pathname, $data, User &$user=null, $outsidedataroot=false) {
// This is only used when blog posts are saved: Files which
// have been uploaded to the post are moved to a permanent
// location in the files area using this function.
$dataroot = get_config('dataroot');
$pathname = $dataroot . $pathname;
if (!$outsidedataroot) {
$pathname = $dataroot . $pathname;
}
if (!$size = filesize($pathname)) {
return false;
}
......
......@@ -149,6 +149,9 @@ $cfg->imagemaxheight = 1024;
// paths and arguments for various system commands
$cfg->pathtounzip = '/usr/bin/unzip';
$cfg->unzipdirarg = '-d';
// some shared hosts have restrictions on where unzip can be used
// dataroot is often not allowed; but /tmp is
// $cfg->unziptempdir = '/tmp/';
// How often Mahara should update the last access time for users. Setting this
// lower means the field will be updated more regularly, but means a database
......
......@@ -217,19 +217,20 @@ class FilesImporter extends Importer {
// this contains relativepath and zipfile name
$this->relativepath = $filesinfo['relativepath'];
$this->zipfile = $filesinfo['zipfile'];
$this->tempdir = $filesinfo['tempdir'];
if (sha1_file(get_config('dataroot') . '/' . $this->relativepath . '/' . $this->zipfile) != $this->zipfilesha1) {
if (sha1_file($this->tempdir . $this->zipfile) != $this->zipfilesha1) {
throw new ImportException('sha1 of recieved zipfile didn\'t match expected sha1');
}
$this->unzipdir = get_config('dataroot') . '/' . $this->relativepath . 'extract/';
$this->unzipdir = $this->tempdir . 'extract/';
if (!check_dir_exists($this->unzipdir)) {
throw new ImportException('Failed to create the temporary directories to work in');
}
$command = sprintf('%s %s %s %s',
get_config('pathtounzip'),
escapeshellarg(get_config('dataroot') . '/' . $this->relativepath . '/' . $this->zipfile),
escapeshellarg($this->tempdir . $this->zipfile),
get_config('unzipdirarg'),
escapeshellarg($this->unzipdir)
);
......@@ -295,15 +296,16 @@ class FilesImporter extends Importer {
'locked' => 0,
);
if ($imagesize = getimagesize(get_config('dataroot') . $this->relativepath . 'extract/' . $f->actualfilename)) {
if ($imagesize = getimagesize($this->tempdir . 'extract/' . $f->actualfilename)) {
$mime = $imagesize['mime'];
$data->filetype = $mime;
}
$id = ArtefactTypeFile::save_file(
$this->relativepath . 'extract/' . $f->actualfilename,
$this->tempdir . 'extract/' . $f->actualfilename,
$data,
$this->get('usrobj')
$this->get('usrobj'),
true
);
if (empty($id)) {
throw new ImportException("Failed to create new artefact for $f->sha1");
......@@ -365,13 +367,19 @@ class MnetImporterTransport extends ImporterTransport {
}
$this->relativepath = 'temp/import/' . $this->importer->get('id') . '/';
$this->tempdir = get_config('dataroot') . $this->relativepath;
if ($tmpdir = get_config('unziptempdir')) {
$this->tempdir = $tmpdir . $this->relativepath;
}
else {
$this->tempdir = get_config('dataroot') . $this->relativepath;
}
log_debug($this->tempdir);
if (!check_dir_exists($this->tempdir)) {
throw new ImportException('Failed to create the temporary directories to work in');
}
$this->zipfilename = 'import.zip';
if (!file_put_contents($this->tempdir . '/' . $this->zipfilename, $filecontents)) {
if (!file_put_contents($this->tempdir . $this->zipfilename, $filecontents)) {
throw new ImportException('Failed to write out the zipfile to local temporary storage');
}
}
......@@ -379,6 +387,7 @@ class MnetImporterTransport extends ImporterTransport {
public function files_info() {
return array(
'zipfile' => $this->zipfilename,
'tempdir' => $this->tempdir,
'relativepath' => $this->relativepath,
);
}
......
Supports Markdown
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