MDL-68262 assignfeedback_editpdf: Correct args to make_request_directory

This commit is contained in:
Andrew Nicols 2024-05-30 09:37:25 +08:00 committed by Huong Nguyen
parent 5e7e6ad9b7
commit b17b4ad4a3
No known key found for this signature in database
GPG Key ID: 40D88AB693A3E72A
2 changed files with 7 additions and 13 deletions

View File

@ -414,7 +414,7 @@ EOD;
return []; return [];
} }
$tmpdir = \make_request_directory('assignfeedback_editpdf/pageimages/' . self::hash($assignment, $userid, $attemptnumber)); $tmpdir = \make_request_directory();
$combined = $tmpdir . '/' . self::COMBINED_PDF_FILENAME; $combined = $tmpdir . '/' . self::COMBINED_PDF_FILENAME;
$document->get_combined_file()->copy_content_to($combined); // Copy the file. $document->get_combined_file()->copy_content_to($combined); // Copy the file.
@ -681,7 +681,7 @@ EOD;
$file = $document->get_combined_file(); $file = $document->get_combined_file();
$tmpdir = make_request_directory('assignfeedback_editpdf/final/' . self::hash($assignment, $userid, $attemptnumber)); $tmpdir = make_request_directory();
$combined = $tmpdir . '/' . self::COMBINED_PDF_FILENAME; $combined = $tmpdir . '/' . self::COMBINED_PDF_FILENAME;
$file->copy_content_to($combined); // Copy the file. $file->copy_content_to($combined); // Copy the file.
@ -702,7 +702,7 @@ EOD;
} }
$fs = get_file_storage(); $fs = get_file_storage();
$stamptmpdir = make_request_directory('assignfeedback_editpdf/stamps/' . self::hash($assignment, $userid, $attemptnumber)); $stamptmpdir = make_request_directory();
$grade = $assignment->get_user_grade($userid, true, $attemptnumber); $grade = $assignment->get_user_grade($userid, true, $attemptnumber);
// Copy any new stamps to this instance. // Copy any new stamps to this instance.
if ($files = $fs->get_area_files($assignment->get_context()->id, if ($files = $fs->get_area_files($assignment->get_context()->id,
@ -1004,8 +1004,7 @@ EOD;
$degree = ($degree - 90) % 360; $degree = ($degree - 90) % 360;
} }
$filename = $matches[0].'png'; $filename = $matches[0].'png';
$tmpdir = make_request_directory(self::COMPONENT . '/' . self::PAGE_IMAGE_FILEAREA . '/' $tmpdir = make_request_directory();
. self::hash($assignment, $userid, $attemptnumber));
$tempfile = $tmpdir . '/' . time() . '_' . $filename; $tempfile = $tmpdir . '/' . time() . '_' . $filename;
imagepng($content, $tempfile); imagepng($content, $tempfile);
@ -1041,9 +1040,7 @@ EOD;
private static function save_jpg_to_pdf($assignment, $userid, $attemptnumber, $file, $size=null) { private static function save_jpg_to_pdf($assignment, $userid, $attemptnumber, $file, $size=null) {
// Temporary file. // Temporary file.
$filename = $file->get_filename(); $filename = $file->get_filename();
$tmpdir = make_request_directory('assignfeedback_editpdf' . DIRECTORY_SEPARATOR $tmpdir = make_request_directory();
. self::TMP_JPG_TO_PDF_FILEAREA . DIRECTORY_SEPARATOR
. self::hash($assignment, $userid, $attemptnumber));
$tempfile = $tmpdir . DIRECTORY_SEPARATOR . $filename . ".pdf"; $tempfile = $tmpdir . DIRECTORY_SEPARATOR . $filename . ".pdf";
// Determine orientation. // Determine orientation.
$orientation = 'P'; $orientation = 'P';
@ -1092,9 +1089,7 @@ EOD;
*/ */
private static function save_rotated_image_file($assignment, $userid, $attemptnumber, $rotateddata, $filename) { private static function save_rotated_image_file($assignment, $userid, $attemptnumber, $rotateddata, $filename) {
$filearea = self::TMP_ROTATED_JPG_FILEAREA; $filearea = self::TMP_ROTATED_JPG_FILEAREA;
$tmpdir = make_request_directory('assignfeedback_editpdf' . DIRECTORY_SEPARATOR $tmpdir = make_request_directory();
. $filearea . DIRECTORY_SEPARATOR
. self::hash($assignment, $userid, $attemptnumber));
$tempfile = $tmpdir . DIRECTORY_SEPARATOR . basename($filename); $tempfile = $tmpdir . DIRECTORY_SEPARATOR . basename($filename);
imagejpeg($rotateddata, $tempfile); imagejpeg($rotateddata, $tempfile);
$newfile = self::save_file($assignment, $userid, $attemptnumber, $filearea, $tempfile); $newfile = self::save_file($assignment, $userid, $attemptnumber, $filearea, $tempfile);
@ -1104,5 +1099,4 @@ EOD;
} }
return $newfile; return $newfile;
} }
} }

View File

@ -49,7 +49,7 @@ final class document_services_test extends \advanced_testcase {
$filearea = document_services::TMP_ROTATED_JPG_FILEAREA; $filearea = document_services::TMP_ROTATED_JPG_FILEAREA;
$content = 'some random content'; $content = 'some random content';
$tempfile = make_request_directory('assignfeedback_editpdf') . DIRECTORY_SEPARATOR . 'mock.file'; $tempfile = make_request_directory() . DIRECTORY_SEPARATOR . 'mock.file';
file_put_contents($tempfile, $content); file_put_contents($tempfile, $content);
// Invoke the method and confirm, that the file is saved. // Invoke the method and confirm, that the file is saved.