Merge branch 'MDL-49998' of git://github.com/stronk7/moodle

This commit is contained in:
David Monllao 2015-05-01 15:05:42 +08:00
commit 84d83fe7e1
3 changed files with 14 additions and 19 deletions

View File

@ -193,11 +193,7 @@ class document_services {
$files = self::list_compatible_submission_files_for_attempt($assignment, $userid, $attemptnumber);
$pdf = new pdf();
if (!$files) {
// No valid submission files - create an empty pdf.
$pdf->AddPage();
} else {
if ($files) {
// Create a mega joined PDF.
$compatiblepdfs = array();
foreach ($files as $file) {
@ -221,12 +217,11 @@ class document_services {
if ($pagecount == 0) {
// We at least want a single blank page.
debugging('TCPDF did not produce a valid pdf:' . $tmpfile . '. Replacing with a blank pdf.', DEBUG_DEVELOPER);
$pdf = new pdf();
$pdf->AddPage();
@unlink($tmpfile);
$files = false;
}
}
$pdf->Close(); // No real need to close this pdf, because it has been saved by combine_pdfs(), but for clarity.
$grade = $assignment->get_user_grade($userid, true, $attemptnumber);
$record = new \stdClass();
@ -243,18 +238,20 @@ class document_services {
// Detect corrupt generated pdfs and replace with a blank one.
if ($files) {
$pagecount = $pdf->load_pdf($tmpfile);
$verifypdf = new pdf();
$pagecount = $verifypdf->load_pdf($tmpfile);
if ($pagecount <= 0) {
$files = false;
}
$verifypdf->Close(); // PDF loaded and never saved/outputted needs to be closed.
}
if (!$files) {
// This was a blank pdf.
unset($pdf);
$pdf = new pdf();
$content = $pdf->Output(self::COMBINED_PDF_FILENAME, 'S');
$blankpdf = new pdf();
$content = $blankpdf->Output(self::COMBINED_PDF_FILENAME, 'S');
$file = $fs->create_file_from_string($record, $content);
$blankpdf->Close(); // No real need to close this pdf, because it has been outputted, but for clarity.
} else {
// This was a combined pdf.
$file = $fs->create_file_from_pathname($record, $tmpfile);
@ -314,6 +311,7 @@ class document_services {
// Get the total number of pages.
$pdf = new pdf();
$pagecount = $pdf->set_pdf($combined);
$pdf->Close(); // PDF loaded and never saved/outputted needs to be closed.
// Delete temporary folders and files.
@unlink($combined);
@ -375,6 +373,7 @@ class document_services {
$files[$i] = $fs->create_file_from_pathname($record, $tmpdir . '/' . $image);
@unlink($tmpdir . '/' . $image);
}
$pdf->Close(); // PDF loaded and never saved/outputted needs to be closed.
@unlink($combined);
@rmdir($tmpdir);

View File

@ -485,13 +485,13 @@ class pdf extends \FPDI {
// PDF was not valid - try running it through ghostscript to clean it up.
$pagecount = 0;
}
$pdf->Close(); // PDF loaded and never saved/outputted needs to be closed.
if ($pagecount > 0) {
// Page is valid and can be read by tcpdf.
return $tempsrc;
}
$gsexec = \escapeshellarg($CFG->pathtogs);
$tempdstarg = \escapeshellarg($tempdst);
$tempsrcarg = \escapeshellarg($tempsrc);
@ -511,6 +511,8 @@ class pdf extends \FPDI {
// PDF was not valid - try running it through ghostscript to clean it up.
$pagecount = 0;
}
$pdf->Close(); // PDF loaded and never saved/outputted needs to be closed.
if ($pagecount <= 0) {
@unlink($tempdst);
// Could not parse the converted pdf.
@ -572,6 +574,7 @@ class pdf extends \FPDI {
$ret->status = self::GSPATH_ERROR;
$ret->message = $e->getMessage();
}
$pdf->Close(); // PDF loaded and never saved/outputted needs to be closed.
return $ret;
}

View File

@ -52,13 +52,6 @@ class assignfeedback_editpdf_testcase extends mod_assign_base_testcase {
parent::setUp();
}
/**
* Tidy up open files that may be left open.
*/
protected function tearDown() {
gc_collect_cycles();
}
protected function create_assign_and_submit_pdf() {
global $CFG;
$assign = $this->create_instance(array('assignsubmission_onlinetext_enabled' => 1,