mirror of
https://github.com/moodle/moodle.git
synced 2025-03-20 07:30:01 +01:00
Merge branch 'MDL-56122-master' of https://github.com/lucisgit/moodle
This commit is contained in:
commit
ccaf17855e
@ -52,6 +52,8 @@ class document_services {
|
||||
const STAMPS_FILEAREA = 'stamps';
|
||||
/** Filename for combined pdf */
|
||||
const COMBINED_PDF_FILENAME = 'combined.pdf';
|
||||
/** Hash of blank pdf */
|
||||
const BLANK_PDF_HASH = '4c803c92c71f21b423d13de570c8a09e0a31c718';
|
||||
|
||||
/** Base64 encoded blank pdf. This is the most reliable/fastest way to generate a blank pdf. */
|
||||
const BLANK_PDF_BASE64 = <<<EOD
|
||||
@ -243,9 +245,11 @@ EOD;
|
||||
$filename = self::COMBINED_PDF_FILENAME;
|
||||
$fs = \get_file_storage();
|
||||
|
||||
$combinedpdf = $fs->get_file($contextid, $component, $filearea, $itemid, $filepath, $filename);
|
||||
if (!$combinedpdf ||
|
||||
($submission && ($combinedpdf->get_timemodified() < $submission->timemodified))) {
|
||||
if (!$combinedpdf = $fs->get_file($contextid, $component, $filearea, $itemid, $filepath, $filename)) {
|
||||
return self::generate_combined_pdf_for_attempt($assignment, $userid, $attemptnumber);
|
||||
}
|
||||
if ($submission && ($combinedpdf->get_timemodified() < $submission->timemodified ||
|
||||
$combinedpdf->get_contenthash() == self::BLANK_PDF_HASH)) {
|
||||
return self::generate_combined_pdf_for_attempt($assignment, $userid, $attemptnumber);
|
||||
}
|
||||
return $combinedpdf;
|
||||
@ -478,6 +482,7 @@ EOD;
|
||||
* @return array(stored_file)
|
||||
*/
|
||||
public static function get_page_images_for_attempt($assignment, $userid, $attemptnumber, $readonly = false) {
|
||||
global $DB;
|
||||
|
||||
$assignment = self::get_assignment_from_param($assignment);
|
||||
|
||||
@ -516,7 +521,22 @@ EOD;
|
||||
$pages = array();
|
||||
if (!empty($files)) {
|
||||
$first = reset($files);
|
||||
if (!$readonly && $first->get_timemodified() < $submission->timemodified) {
|
||||
$pagemodified = $first->get_timemodified();
|
||||
// Check that we don't just have a single blank page. The hash of a blank page image can vary with
|
||||
// the version of ghostscript used, so we need to examine the combined pdf it was generated from.
|
||||
$blankpage = false;
|
||||
if (!$readonly && count($files) == 1) {
|
||||
$pdfarea = self::COMBINED_PDF_FILEAREA;
|
||||
$pdfname = self::COMBINED_PDF_FILENAME;
|
||||
if ($pdf = $fs->get_file($contextid, $component, $pdfarea, $itemid, $filepath, $pdfname)) {
|
||||
// The combined pdf may have a different hash if it has been regenerated since the page
|
||||
// image was created. However if this is the case the page image will be stale anyway.
|
||||
if ($pdf->get_contenthash() == self::BLANK_PDF_HASH || $pagemodified < $pdf->get_timemodified()) {
|
||||
$blankpage = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$readonly && ($pagemodified < $submission->timemodified || $blankpage)) {
|
||||
// Image files are stale, we need to regenerate them, except in readonly mode.
|
||||
// We also need to remove the draft annotations and comments associated with this attempt.
|
||||
$fs->delete_area_files($contextid, $component, $filearea, $itemid);
|
||||
|
@ -216,6 +216,33 @@ class assignfeedback_editpdf_testcase extends mod_assign_base_testcase {
|
||||
|
||||
$grade = $assign->get_user_grade($this->students[0]->id, true);
|
||||
|
||||
$contextid = $assign->get_context()->id;
|
||||
$component = 'assignfeedback_editpdf';
|
||||
$filearea = document_services::COMBINED_PDF_FILEAREA;
|
||||
$itemid = $grade->id;
|
||||
$filepath = '/';
|
||||
$filename = document_services::COMBINED_PDF_FILENAME;
|
||||
$fs = \get_file_storage();
|
||||
|
||||
// Generate a blank combined pdf.
|
||||
$record = new \stdClass();
|
||||
$record->contextid = $contextid;
|
||||
$record->component = $component;
|
||||
$record->filearea = $filearea;
|
||||
$record->itemid = $itemid;
|
||||
$record->filepath = $filepath;
|
||||
$record->filename = $filename;
|
||||
$fs->create_file_from_string($record, base64_decode(document_services::BLANK_PDF_BASE64));
|
||||
|
||||
// Verify that the blank combined pdf has the expected hash.
|
||||
$combinedpdf = $fs->get_file($contextid, $component, $filearea, $itemid, $filepath, $filename);
|
||||
$this->assertEquals($combinedpdf->get_contenthash(), document_services::BLANK_PDF_HASH);
|
||||
|
||||
// Generate page images and verify that the combined pdf has been replaced.
|
||||
document_services::get_page_images_for_attempt($assign, $this->students[0]->id, -1);
|
||||
$combinedpdf = $fs->get_file($contextid, $component, $filearea, $itemid, $filepath, $filename);
|
||||
$this->assertNotEquals($combinedpdf->get_contenthash(), document_services::BLANK_PDF_HASH);
|
||||
|
||||
$notempty = page_editor::has_annotations_or_comments($grade->id, false);
|
||||
$this->assertFalse($notempty);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user