Merge branch 'MDL-69570-master' of https://github.com/abgreeve/moodle
This commit is contained in:
@@ -106,7 +106,7 @@ class provider implements
|
||||
$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())
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Cleans up orphaned feedback pdf files and table entries.
|
||||
*
|
||||
* @package assignfeedback_editpdf
|
||||
* @copyright 2022 Adrian Greeve <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace assignfeedback_editpdf\task;
|
||||
|
||||
use core\task\adhoc_task;
|
||||
|
||||
/**
|
||||
* Cleans up orphaned feedback pdf files and table entries.
|
||||
*
|
||||
* @package assignfeedback_editpdf
|
||||
* @copyright 2022 Adrian Greeve <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class remove_orphaned_editpdf_files extends adhoc_task {
|
||||
|
||||
/**
|
||||
* Run the task.
|
||||
*/
|
||||
public function execute() {
|
||||
$this->remove_files_and_entries();
|
||||
$this->remove_rotated_table_entries();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes edit pdf feedback files and table entries that have been orphaned.
|
||||
*/
|
||||
private function remove_files_and_entries(): void {
|
||||
global $DB;
|
||||
|
||||
// Patiently remove all orphaned temporary pdf files.
|
||||
$sql = "SELECT DISTINCT f.contextid, f.component, f.filearea, f.itemid
|
||||
FROM {files} f
|
||||
LEFT JOIN {assign_grades} g ON g.id = f.itemid
|
||||
WHERE f.component = :assigneditpdf
|
||||
AND NOT (filearea = :stamps AND f.itemid = 0)
|
||||
AND g.id IS NULL";
|
||||
$params = ['assigneditpdf' => 'assignfeedback_editpdf', 'stamps' => 'stamps'];
|
||||
|
||||
$results = $DB->get_recordset_sql($sql, $params);
|
||||
foreach ($results as $record) {
|
||||
$fs = get_file_storage();
|
||||
$fs->delete_area_files($record->contextid, $record->component, $record->filearea, $record->itemid);
|
||||
}
|
||||
$results->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes orphaned entries in the feedback edit pdf rotation table.
|
||||
*/
|
||||
private function remove_rotated_table_entries(): void {
|
||||
global $DB;
|
||||
$rotatesql = "SELECT er.id AS erid
|
||||
FROM {assignfeedback_editpdf_rot} er
|
||||
LEFT JOIN {assign_grades} g ON g.id = er.gradeid
|
||||
WHERE g.id IS NULL";
|
||||
$DB->delete_records_subquery('assignfeedback_editpdf_rot', 'id', 'erid' ,$rotatesql);
|
||||
}
|
||||
}
|
||||
@@ -93,5 +93,11 @@ function xmldb_assignfeedback_editpdf_upgrade($oldversion) {
|
||||
upgrade_plugin_savepoint(true, 2022082200, 'assignfeedback', 'editpdf');
|
||||
}
|
||||
|
||||
if ($oldversion < 2022112801) {
|
||||
$task = new \assignfeedback_editpdf\task\remove_orphaned_editpdf_files();
|
||||
\core\task\manager::queue_adhoc_task($task);
|
||||
|
||||
upgrade_plugin_savepoint(true, 2022112801, 'assignfeedback', 'editpdf');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -405,6 +405,7 @@ class assign_feedback_editpdf extends assign_feedback_plugin {
|
||||
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;
|
||||
}
|
||||
@@ -436,7 +437,28 @@ class assign_feedback_editpdf extends assign_feedback_plugin {
|
||||
* @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(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2022112800;
|
||||
$plugin->version = 2022112801;
|
||||
$plugin->requires = 2022111800;
|
||||
$plugin->component = 'assignfeedback_editpdf';
|
||||
|
||||
@@ -3601,7 +3601,18 @@ Anchor link 2:<a title=\"bananas\" href=\"../logo-240x60.gif\">Link text</a>
|
||||
$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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user