Commit a02a87c8 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Let export continue when a missing file is found (bug #749863)



If a missing file is found during export, instead of failing, just skip
the artefact and continue, displaying a message when the export file is
served.

Change-Id: I37d3410e7e8fb9acf4bf07d8bc901f2c6dc8fc0f
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 0b4b644a
......@@ -114,4 +114,4 @@ $SESSION->set('exportfile', $exporter->get('exportdir') . $zipfile);
$wwwroot = get_config('wwwroot');
$strexportgeneratedsuccessfullyjs = get_string('exportgeneratedsuccessfullyjs', 'export', '<a href="' . $wwwroot . 'export/" target="_top">', '</a>');
$strexportgeneratedsuccessfully = get_string('exportgeneratedsuccessfully', 'export', '<a href="download.php" target="_top">', '</a>');
print_export_footer($strexportgeneratedsuccessfully, $strexportgeneratedsuccessfullyjs);
print_export_footer($strexportgeneratedsuccessfully, $strexportgeneratedsuccessfullyjs, $exporter->get('messages'));
......@@ -526,9 +526,17 @@ class PluginExportLeap extends PluginExport {
if (!$element->is_leap()) {
continue;
}
$element->add_attachments();
$element->assign_smarty_vars();
$this->xml .= $element->get_export_xml();
try {
$element->add_attachments();
$element->assign_smarty_vars();
$this->xml .= $element->get_export_xml();
}
catch (FileNotFoundException $e) {
// If we don't find a file on disk, just continue the export,
// but leave this artefact out.
$this->messages[] = $e->getMessage();
log_debug('Missing file in leap2a export for artefact ' . $artefact->get('id'));
}
}
}
}
......@@ -564,7 +572,7 @@ class PluginExportLeap extends PluginExport {
*/
public function add_attachment($filepath, $newname) {
if (!file_exists($filepath) || empty($newname)) {
throw new ParamOutOfRangeException(get_string('nonexistentfile', 'export', $newname));
throw new FileNotFoundException(get_string('nonexistentfile', 'export', $newname));
}
$newname = substr(str_replace('/', '_', $newname), 0, 245);
$this->attachments[] = (object)array('file' => $filepath, 'name' => $newname);
......
......@@ -293,6 +293,8 @@ abstract class PluginExport extends Plugin {
throw new SystemException("Couldn't create the temporary export directory $this->exportdir");
}
$this->messages = array();
$this->notify_progress_callback(10, 'Setup');
}
......
......@@ -869,6 +869,11 @@ class UploadException extends UserException {}
*/
class CollectionNotFoundException extends NotFoundException {}
/**
* Exception - file not found in dataroot
*/
class FileNotFoundException extends NotFoundException {}
/**
* Exception - Access denied. Throw this if a user is trying to view something they can't
*/
......
......@@ -63,7 +63,7 @@ function print_iframe_progress_handler($percent, $status) {
echo '<p class="progress-text">' . hsc($status) . "</p>\n";
}
function print_export_footer($strexportgeneratedsuccessfully, $strexportgeneratedsuccessfullyjs) {
function print_export_footer($strexportgeneratedsuccessfully, $strexportgeneratedsuccessfullyjs, $jsmessages=array()) {
?>
<script type="text/javascript">
document.write('<div class="progress-bar" style="width: 100%;"><p><?php echo $strexportgeneratedsuccessfullyjs; ?></p></div>');
......@@ -72,6 +72,10 @@ function print_export_footer($strexportgeneratedsuccessfully, $strexportgenerate
// download inline in the iframe
document.location = 'download.php';
}
var messages = <?php echo json_encode(join('; ', $jsmessages)); ?>;
if (messages) {
parent.displayMessage(messages);
}
</script>
<div class="progress-bar" style="width: 100%;">
<p><?php echo $strexportgeneratedsuccessfully; ?></p>
......
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