Skip to content

Commit

Permalink
MDL-69570 assignfeedback_editpdf: Remove temp pdf files
Browse files Browse the repository at this point in the history
This adds a new method to the assignfeedback edit pdf library
to specify user data file areas that will return just the meaningful
annotated feedback pdf.

get_file_areas has been updated for this plugin to return all
file areas related to assignfeedback_editpdf, and should stop
producing orphaned files and records when a course reset is done.

Thanks to @toniginard who provided a base solution for me to work
off.
  • Loading branch information
abgreeve authored and andrewnicols committed Nov 29, 2022
1 parent 0ea3d45 commit b50c240
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mod/assign/feedback/editpdf/classes/privacy/provider.php
Expand Up @@ -106,7 +106,7 @@ public static function export_feedback_user_data(assign_plugin_request_data $exp
$currentpath[] = get_string('privacy:path', 'assignfeedback_editpdf');
$assign = $exportdata->get_assign();
$plugin = $assign->get_plugin_by_type('assignfeedback', 'editpdf');
$fileareas = $plugin->get_file_areas();
$fileareas = $plugin->get_user_data_file_areas();
$grade = $exportdata->get_pluginobject();
foreach ($fileareas as $filearea => $notused) {
writer::with_context($exportdata->get_context())
Expand Down
24 changes: 23 additions & 1 deletion mod/assign/feedback/editpdf/locallib.php
Expand Up @@ -405,6 +405,7 @@ public function delete_instance() {
list($gradeids, $params) = $DB->get_in_or_equal(array_keys($grades), SQL_PARAMS_NAMED);
$DB->delete_records_select('assignfeedback_editpdf_annot', 'gradeid ' . $gradeids, $params);
$DB->delete_records_select('assignfeedback_editpdf_cmnt', 'gradeid ' . $gradeids, $params);
$DB->delete_records_select('assignfeedback_editpdf_rot', 'gradeid ' . $gradeids, $params);
}
return true;
}
Expand Down Expand Up @@ -436,7 +437,28 @@ public function is_configurable() {
* @return array - An array of fileareas (keys) and descriptions (values)
*/
public function get_file_areas() {
return array(document_services::FINAL_PDF_FILEAREA => $this->get_name());
return [
document_services::FINAL_PDF_FILEAREA => $this->get_name(),
document_services::COMBINED_PDF_FILEAREA => $this->get_name(),
document_services::PARTIAL_PDF_FILEAREA => $this->get_name(),
document_services::IMPORT_HTML_FILEAREA => $this->get_name(),
document_services::PAGE_IMAGE_FILEAREA => $this->get_name(),
document_services::PAGE_IMAGE_READONLY_FILEAREA => $this->get_name(),
document_services::STAMPS_FILEAREA => $this->get_name(),
document_services::TMP_JPG_TO_PDF_FILEAREA => $this->get_name(),
document_services::TMP_ROTATED_JPG_FILEAREA => $this->get_name()
];
}

/**
* Get all file areas for user data related to this plugin.
*
* @return array - An array of user data fileareas (keys) and descriptions (values)
*/
public function get_user_data_file_areas(): array {
return [
document_services::FINAL_PDF_FILEAREA => $this->get_name(),
];
}

/**
Expand Down
13 changes: 12 additions & 1 deletion mod/assign/tests/locallib_test.php
Expand Up @@ -3601,7 +3601,18 @@ public function test_get_plugins_file_areas() {
$fileareas = $plugin->get_file_areas();

if ($type == 'editpdf') {
$this->assertEquals(array('download' => 'Annotate PDF'), $fileareas);
$checkareas = [
'download' => 'Annotate PDF',
'combined' => 'Annotate PDF',
'partial' => 'Annotate PDF',
'importhtml' => 'Annotate PDF',
'pages' => 'Annotate PDF',
'readonlypages' => 'Annotate PDF',
'stamps' => 'Annotate PDF',
'tmp_jpg_to_pdf' => 'Annotate PDF',
'tmp_rotated_jpg' => 'Annotate PDF'
];
$this->assertEquals($checkareas, $fileareas);
$usingfilearea++;
} else if ($type == 'file') {
$this->assertEquals(array('feedback_files' => 'Feedback files'), $fileareas);
Expand Down
2 changes: 2 additions & 0 deletions mod/assign/upgrade.txt
Expand Up @@ -2,6 +2,8 @@ This files describes API changes in the assign code.
=== 4.1 ===
* New method \assign::is_userid_filtered() has been implemented. It returns false if user id is filtered out by either
user preferences for grading table or submission status filter. Otherwise, returns true.
* A new method was added to feedback/editpdf/locallib.php - get_user_data_file_areas() This just returns the necessary file areas
for retrieving a complete feedback pdf.

=== 4.0 ===
* The method \assign::grading_disabled() now has optional $gradinginfo parameter to improve performance
Expand Down

0 comments on commit b50c240

Please sign in to comment.