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

manual cherry-pick of 9ab297b0b67a7f91f3c8314ad71728063d2fafb7

Half of this (the base library part) was already on master.

Import refactor: moved the transporter classes out of files importer and into base library
parent ea7d7b35
......@@ -179,73 +179,4 @@ class PluginImportFile extends PluginImport {
}
}
class MnetImporterTransport extends ImporterTransport {
private $importer;
private $host;
private $token;
private $relativepath;
private $tempdir;
private $zipfilename;
public function __construct(Importer $importer) {
$this->importer = $importer;
$this->token = $importer->get('token');
$this->host = get_record('host', 'wwwroot', $importer->get('host'));
}
public function cleanup() {
if (empty($this->tempdir)) {
return;
}
rmdirr($this->tempdir);
}
public function prepare_files() {
require_once(get_config('docroot') . 'api/xmlrpc/client.php');
$client = new Client();
try {
$client->set_method('portfolio/mahara/lib.php/fetch_file')
->add_param($this->token)
->send($this->host->wwwroot);
} catch (XmlrpcClientException $e) {
throw new ImportException('Failed to retrieve zipfile from remote server: ' . $e->getMessage());
}
if (!$filecontents = base64_decode($client->response)) {
throw new ImportException('Failed to retrieve zipfile from remote server');
}
$this->relativepath = 'temp/import/' . $this->importer->get('id') . '/';
if ($tmpdir = get_config('unziptempdir')) {
$this->tempdir = $tmpdir . $this->relativepath;
}
else {
$this->tempdir = get_config('dataroot') . $this->relativepath;
}
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)) {
throw new ImportException('Failed to write out the zipfile to local temporary storage');
}
}
public function files_info() {
return array(
'zipfile' => $this->zipfilename,
'tempdir' => $this->tempdir,
'relativepath' => $this->relativepath,
);
}
public function get_description() {
return get_string('remotehost', 'mahara', $this->host->name);
}
}
?>
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