Commit 2384d2c3 authored by Penny Leach's avatar Penny Leach
Browse files

importer: keep track of what files we add and the new folder if any

so we can bounce the user back over mnet with a better url
parent 0df3bbef
......@@ -360,6 +360,11 @@ function send_content_ready($token, $username, $format, $importdata, $fetchnow=f
delete_records('import_queue', 'id', $queue->id);
$result->status = true;
$result->type = 'complete';
$returndata = $importer->get_return_data();
$result->querystring = '?';
foreach ($importer->get_return_data() as $k => $v) {
$result->querystring .= $k . '=' . $v . '&';
}
} else {
// or set ready to 1 for the next cronjob to go fetch it.
$result->status = set_field('import_queue', 'ready', 1, 'id', $queue->id);
......
......@@ -145,6 +145,15 @@ abstract class Importer {
return true;
}
/**
* if we're sending stuff back to wherever we were called from
* use this method
* at the moment, the only implementation is for mnet
* sending back a list of file ids.
*/
public function get_return_data() {
return array();
}
}
abstract class ImporterTransport {
......@@ -172,6 +181,8 @@ class FilesImporter extends Importer {
private $files;
private $unzipdir;
private $zipfilesha1;
private $artefacts;
private $importdir;
public function __construct($id, $record=null) {
parent::__construct($id, $record);
......@@ -268,7 +279,7 @@ class FilesImporter extends Importer {
// we're just adding them as files into an 'incoming' directory in the user's file area.
safe_require('artefact', 'file');
try {
$dir = ArtefactTypeFolder::get_folder_id('incoming', get_string('incomingfolderdesc'), null, true, $this->get('usr'));
$this->importdir = ArtefactTypeFolder::get_folder_id('incoming', get_string('incomingfolderdesc'), null, true, $this->get('usr'));
} catch (Exception $e) {
throw new ImportException($e->getMessage());
}
......@@ -278,12 +289,17 @@ class FilesImporter extends Importer {
$data = (object)array(
'title' => $f->wantsfilename,
'description' => $f->wantsfilename . ' (' . get_string('importedfrom', 'mahara', $this->get('importertransport')->get_description()) . ')',
'parent' => $dir,
'parent' => $this->importdir,
'owner' => $this->get('usr'),
'container' => 0,
'locked' => 0,
);
if ($imagesize = getimagesize(get_config('dataroot') . $this->relativepath . 'extract/' . $f->actualfilename)) {
$mime = $imagesize['mime'];
$data->filetype = $mime;
}
$id = ArtefactTypeFile::save_file(
$this->relativepath . 'extract/' . $f->actualfilename,
$data,
......@@ -302,6 +318,11 @@ class FilesImporter extends Importer {
throw new ImportException('Failed to create some new artefacts');
}
}
$this->artefacts = $savedfiles;
}
public function get_return_data() {
return array('folder' => $this->importdir, 'file' => (count($this->artefacts) == 1) ? $this->artefacts[0] : 0);
}
}
......
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