Commit 646cf69a authored by Penny Leach's avatar Penny Leach
Browse files

Fix ups to the calling of import exceptions.



Went through and changed all the throws of ImportException to correctly
pass the importer (or null) as the first argument
Signed-off-by: default avatarPenny Leach <penny@mjollnir.org>
parent 92e0b4c2
......@@ -281,15 +281,15 @@ function send_content_intent($username) {
list ($user, $authinstance) = find_remote_user($username, $REMOTEWWWROOT);
if (!$user) {
throw new ImportException("Could not find user $username for $REMOTEWWWROOT");
throw new ImportException(null, "Could not find user $username for $REMOTEWWWROOT");
}
if (!is_executable(get_config('pathtounzip'))) {
throw new ImportException("Cannot find unzip executable");
throw new ImportException(null, "Cannot find unzip executable");
}
if (!$authinstance->weimportcontent) {
$e = new ImportException('Importing content is disabled');
$e = new ImportException(null, 'Importing content is disabled');
$e->set_log_off(); // we don't want these ones.
throw $e;
}
......@@ -308,16 +308,16 @@ function send_content_ready($token, $username, $format, $importdata, $fetchnow=f
list ($user, $authinstance) = find_remote_user($username, $REMOTEWWWROOT);
if (!$user) {
throw new ImportException("Could not find user $username for $REMOTEWWWROOT");
throw new ImportException(null, "Could not find user $username for $REMOTEWWWROOT");
}
// go verify the token
if (!$queue = get_record('import_queue', 'token', $token, 'host', $REMOTEWWWROOT)) {
throw new ImportException("Could not find queue record with given token for username $username for $REMOTEWWWROOT");
throw new ImportException(null, "Could not find queue record with given token for username $username for $REMOTEWWWROOT");
}
if (strtotime($queue->expirytime) < time()) {
throw new ImportException("Queue record has expired");
throw new ImportException(null, "Queue record has expired");
}
$queue->format = $format;
......@@ -325,20 +325,20 @@ function send_content_ready($token, $username, $format, $importdata, $fetchnow=f
try {
$class = PluginImport::class_from_format($format);
} catch (Exception $e) {
throw new ImportException('Invalid format $format');
throw new ImportException(null, 'Invalid format $format');
}
try {
call_static_method($class, 'validate_import_data', $importdata);
} catch (Exception $e) {
throw new ImportException('Invalid importdata: ' . $e->getMessage());
throw new ImportException(null, 'Invalid importdata: ' . $e->getMessage());
}
if (!array_key_exists('totalsize', $importdata)) {
throw new ImportException('Invalid importdata: missing totalsize');
throw new ImportException(null, 'Invalid importdata: missing totalsize');
}
if (!$user->quota_allowed($importdata['totalsize'])) {
$e = new ImportException('Exceeded user quota');
$e = new ImportException(null, 'Exceeded user quota');
$e->set_log_off();
throw $e;
}
......
......@@ -50,10 +50,10 @@ class PluginImportFile extends PluginImport {
!array_key_exists('filesmanifest', $importdata) ||
!is_array($importdata['filesmanifest']) ||
count($importdata['filesmanifest']) == 0) {
throw new ImportException('Missing files manifest in import data');
throw new ImportException($this, 'Missing files manifest in import data');
}
if (!array_key_exists('zipfilesha1', $importdata)) {
throw new ImportException('Missing zipfile sha1 in import data');
throw new ImportException($this, 'Missing zipfile sha1 in import data');
}
return true;
}
......@@ -72,12 +72,12 @@ class PluginImportFile extends PluginImport {
$this->tempdir = $filesinfo['tempdir'];
if (sha1_file($this->tempdir . $this->zipfile) != $this->zipfilesha1) {
throw new ImportException('sha1 of recieved zipfile didn\'t match expected sha1');
throw new ImportException($this, 'sha1 of recieved zipfile didn\'t match expected sha1');
}
$this->unzipdir = $this->tempdir . 'extract/';
if (!check_dir_exists($this->unzipdir)) {
throw new ImportException('Failed to create the temporary directories to work in');
throw new ImportException($this, 'Failed to create the temporary directories to work in');
}
$command = sprintf('%s %s %s %s',
......@@ -89,7 +89,7 @@ class PluginImportFile extends PluginImport {
$output = array();
exec($command, $output, $returnvar);
if ($returnvar != 0) {
throw new ImportException('Failed to unzip the file recieved from the transport object');
throw new ImportException($this, 'Failed to unzip the file recieved from the transport object');
}
}
......@@ -122,7 +122,7 @@ class PluginImportFile extends PluginImport {
$bad_c = count($badfiles);
$man_c = count($this->manifest);
if ($ok_c != $man_c) {
throw new ImportException('Files receieved did not exactly match what was in the manifest');
throw new ImportException($this, 'Files receieved did not exactly match what was in the manifest');
// @todo penny later - better reporting (missing files, too many files, etc)
}
$this->files = $okfiles;
......@@ -134,7 +134,7 @@ class PluginImportFile extends PluginImport {
try {
$this->importdir = ArtefactTypeFolder::get_folder_id('incoming', get_string('incomingfolderdesc'), null, true, $this->get('usr'));
} catch (Exception $e) {
throw new ImportException($e->getMessage());
throw new ImportException($this, $e->getMessage());
}
$savedfiles = array(); // to put files into so we can delete them should we encounter an exception
foreach ($this->files as $f) {
......@@ -160,7 +160,7 @@ class PluginImportFile extends PluginImport {
true
);
if (empty($id)) {
throw new ImportException("Failed to create new artefact for $f->sha1");
throw new ImportException($this, "Failed to create new artefact for $f->sha1");
}
$savedfiles[] = $id;
}
......@@ -169,7 +169,7 @@ class PluginImportFile extends PluginImport {
$tmp = artefact_instance_from_id($fileid);
$tmp->delete();
}
throw new ImportException('Failed to create some new artefacts');
throw new ImportException($this, 'Failed to create some new artefacts');
}
}
$this->artefacts = $savedfiles;
......
......@@ -266,10 +266,10 @@ class MnetImporterTransport extends ImporterTransport {
->add_param($this->token)
->send($this->host->wwwroot);
} catch (XmlrpcClientException $e) {
throw new ImportException('Failed to retrieve zipfile from remote server: ' . $e->getMessage());
throw new ImportException($this->importer, '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');
throw new ImportException($this->importer, 'Failed to retrieve zipfile from remote server');
}
$this->relativepath = 'temp/import/' . $this->importer->get('id') . '/';
......@@ -280,12 +280,12 @@ class MnetImporterTransport extends ImporterTransport {
$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');
throw new ImportException($this->importer, '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');
throw new ImportException($this->importer, 'Failed to write out the zipfile to local temporary storage');
}
}
......
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