diff --git a/mod/assign/feedback/editpdf/classes/document_services.php b/mod/assign/feedback/editpdf/classes/document_services.php index 7ae0b30ef02..912bd8addff 100644 --- a/mod/assign/feedback/editpdf/classes/document_services.php +++ b/mod/assign/feedback/editpdf/classes/document_services.php @@ -438,8 +438,10 @@ class document_services { if (!empty($files)) { $first = reset($files); if (!$readonly && $first->get_timemodified() < $submission->timemodified) { - // Image files are stale - regenerate them, except in readonly mode. + // 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); + page_editor::delete_draft_content($itemid); $files = array(); } else { diff --git a/mod/assign/feedback/editpdf/classes/page_editor.php b/mod/assign/feedback/editpdf/classes/page_editor.php index 1b1447ac0df..3dfa0716871 100644 --- a/mod/assign/feedback/editpdf/classes/page_editor.php +++ b/mod/assign/feedback/editpdf/classes/page_editor.php @@ -340,4 +340,21 @@ class page_editor { return true; } + + /** + * Delete the draft annotations and comments. + * + * This is intended to be used when the version of the PDF has changed and the annotations + * might not be relevant any more, therefore we should delete them. + * + * @param int $gradeid The grade ID. + * @return bool + */ + public static function delete_draft_content($gradeid) { + global $DB; + $conditions = array('gradeid' => $gradeid, 'draft' => 1); + $result = $DB->delete_records('assignfeedback_editpdf_annot', $conditions); + $result = $result && $DB->delete_records('assignfeedback_editpdf_cmnt', $conditions); + return $result; + } }