Commit 4d76de6f authored by Ankit Agarwal's avatar Ankit Agarwal
Browse files

MDL-55859 assign_editpdf: cleanup htmlfile in case of errors

parent e40d5048
......@@ -200,7 +200,13 @@ EOD;
$record->filename = $plugin->get_type() . '-' . $filename;
$htmlfile = $fs->create_file_from_string($record, $file);
$convertedfile = $fs->get_converted_document($htmlfile, 'pdf');
try {
$convertedfile = $fs->get_converted_document($htmlfile, 'pdf');
} catch (\Exception $e) {
// Let us delete the file and re-throw the exception.
$htmlfile->delete();
throw $e;
}
$htmlfile->delete();
if ($convertedfile) {
$files[$filename] = $convertedfile;
......
......@@ -71,5 +71,21 @@ function xmldb_assignfeedback_editpdf_upgrade($oldversion) {
// Automatically generated Moodle v3.2.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2017022700) {
// Get orphaned, duplicate files and delete them.
$fs = get_file_storage();
$sqllike = $DB->sql_like("filename", "?");
$where = "component='assignfeedback_editpdf' AND filearea = 'importhtml' AND " . $sqllike;
$filerecords = $DB->get_records_select("files", $where, ["onlinetext-%"]);
foreach ($filerecords as $filerecord) {
$file = $fs->get_file_instance($filerecord);
$file->delete();
}
// Editpdf savepoint reached.
upgrade_plugin_savepoint(true, 2017022700, 'assignfeedback', 'editpdf');
}
return true;
}
......@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016120500;
$plugin->version = 2017022700;
$plugin->requires = 2016112900;
$plugin->component = 'assignfeedback_editpdf';
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