Skip to content

Commit

Permalink
Improved image error reporting for #199.
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Jan 18, 2024
1 parent 3b1bf36 commit fa913b1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
40 changes: 23 additions & 17 deletions classes/toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function check_displayed_image($sectionimage, $courseid, $coursecontextid
}
} else {
throw new \moodle_exception(
'cannotgetimagelock',
'imagemanagement',
'format_grid',
'',
get_string('cannotgetmanagesectionimagelock', 'format_grid')
Expand Down Expand Up @@ -228,7 +228,10 @@ public function setup_displayed_image($sectionimage, $sectionfile, $courseid, $s
'id' => $sectionfile->get_id(),
'itemid' => $sectionfile->get_itemid(),
'filename' => $filename,
'filemime' => $sectionfile->get_mimetype(),
'filesize' => $sectionfile->get_filesize(),
'sectionid' => $sectionid,
'userid' => $sectionfile->get_userid(),
];
$data = self::generate_image(
$tmpfilepath,
Expand Down Expand Up @@ -286,7 +289,7 @@ public function setup_displayed_image($sectionimage, $sectionfile, $courseid, $s
);
if ($sectionimage->displayedimagestate == -1) {
throw new \moodle_exception(
'cannotconvertuploadedimagetodisplayedimage',
'imagemanagement',
'format_grid',
'',
get_string(
Expand Down Expand Up @@ -392,7 +395,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei
if (empty($imageinfo)) {
unlink($filepath);
throw new \moodle_exception(
'noimageinformation',
'imagemanagement',
'format_grid',
'',
get_string(
Expand All @@ -409,7 +412,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei
if (empty($originalheight)) {
unlink($filepath);
throw new \moodle_exception(
'originalheightempty',
'imagemanagement',
'format_grid',
'',
get_string(
Expand All @@ -422,7 +425,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei
if (empty($originalwidth)) {
unlink($filepath);
throw new \moodle_exception(
'originalwidthempty',
'imagemanagement',
'format_grid',
'',
get_string(
Expand All @@ -447,7 +450,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei
} else {
unlink($filepath);
throw new \moodle_exception(
'formatnotsupported',
'imagemanagement',
'format_grid',
'',
get_string(
Expand All @@ -465,7 +468,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei
} else {
unlink($filepath);
throw new \moodle_exception(
'formatnotsupported',
'imagemanagement',
'format_grid',
'',
get_string(
Expand All @@ -485,7 +488,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei
} else {
unlink($filepath);
throw new \moodle_exception(
'formatnotsupported',
'imagemanagement',
'format_grid',
'',
get_string(
Expand All @@ -502,7 +505,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei
} else {
unlink($filepath);
throw new \moodle_exception(
'formatnotsupported',
'imagemanagement',
'format_grid',
'',
get_string(
Expand All @@ -516,7 +519,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei
default:
unlink($filepath);
throw new \moodle_exception(
'mimetypenotsupported',
'imagemanagement',
'format_grid',
'',
get_string(
Expand Down Expand Up @@ -618,7 +621,7 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei
ob_end_clean();
unlink($filepath);
throw new \moodle_exception(
'functionfailed',
'imagemanagement',
'format_grid',
'',
get_string(
Expand All @@ -637,11 +640,14 @@ private static function generate_image($filepath, $requestedwidth, $requestedhei
}

private static function debugdata_decode($debugdata) {
$o = 'itemid > ' . $debugdata['itemid'];
$o .= ', filename > ' . $debugdata['filename'];
$o .= ' and sectionid > ' . $debugdata['sectionid'] . '. ';
$o = 'id: ' . $debugdata['item'];
$o .= 'itemid: ' . $debugdata['itemid'];
$o .= ', filename: ' . $debugdata['filename'];
$o .= ', filemime: ' . $debugdata['filemime'];
$o .= ', filesize: ' . $debugdata['filesize'];
$o .= ', creator user id: ' . $debugdata['userid'];
$o .= ' and sectionid: ' . $debugdata['sectionid'] . '. ';
$o .= get_string('reporterror', 'format_grid');

return $o;
}

Expand Down Expand Up @@ -718,7 +724,7 @@ private static function update_the_displayed_images($courseid = null) {
}
} else {
throw new \moodle_exception(
'cannotgetimagelock',
'imagemanagement',
'format_grid',
'',
get_string('cannotgetmanagesectionimagelock', 'format_grid')
Expand Down Expand Up @@ -798,7 +804,7 @@ public static function delete_image($sectionid, $courseid) {
}
} else {
throw new \moodle_exception(
'cannotgetimagelock',
'imagemanagement',
'format_grid',
'',
get_string('cannotgetmanagesectionimagelock', 'format_grid')
Expand Down
17 changes: 9 additions & 8 deletions lang/en/format_grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,16 @@
$string['versionstable'] = 'Stable version - Could contain bugs. Check on a test server before installing on your production server.';

// Exception messages.
$string['cannotconvertuploadedimagetodisplayedimage'] = 'Cannot convert uploaded image to displayed image - {$a}. Please report error details and the information contained in the php.log file to developer.';
$string['cannotconvertuploadedimagetodisplayedimage'] = 'Cannot convert uploaded image to displayed image - {$a}.';
$string['cannotgetmanagesectionimagelock'] = 'Cannot get manage section image lock. This can happen if two people are editing the settinsg of the same section on the same course at the same time.';
$string['formatnotsupported'] = 'Format is not supported at this server, please fix the system configuration to have the GD PHP extension installed - {$a}.';
$string['functionfailed'] = 'Function failed on image - {$a}.';
$string['mimetypenotsupported'] = 'Mime type is not supported as an image format in the Grid format - {$a}.';
$string['originalheightempty'] = 'Original height is empty - {$a}.';
$string['originalwidthempty'] = 'Original width is empty - {$a}.';
$string['noimageinformation'] = 'Image information is empty - {$a}.';
$string['reporterror'] = 'Please report error details and the information contained in the php.log file to developer';
$string['formatnotsupported'] = 'Format is not supported at this server, please fix the system configuration to have the GD PHP extension installed - {$a}';
$string['functionfailed'] = 'Function failed on image - {$a}';
$string['imagemanagement'] = 'Image management: {$a}.';
$string['mimetypenotsupported'] = 'Mime type is not supported as an image format in the Grid format - {$a}';
$string['originalheightempty'] = 'Original height is empty - {$a}';
$string['originalwidthempty'] = 'Original width is empty - {$a}';
$string['noimageinformation'] = 'Image information is empty - {$a}';
$string['reporterror'] = 'Please use the error details and the information contained in the php.log to understand the nature of why the uploaded image cannot be used';

// Privacy.
$string['privacy:nop'] = 'The Grid format stores lots of settings that pertain to its configuration. None of the settings are related to a specific user. It is your responsibilty to ensure that no user data is entered in any of the free text fields. Setting a setting will result in that action being logged within the core Moodle logging system against the user whom changed it, this is outside of the formats control, please see the core logging system for privacy compliance for this. When uploading images, you should avoid uploading images with embedded location data (EXIF GPS) included or other such personal data. It would be possible to extract any location / personal data from the images. Please examine the code carefully to be sure that it complies with your interpretation of your privacy laws. I am not a lawyer and my analysis is based on my interpretation. If you have any doubt then remove the format forthwith.';

0 comments on commit fa913b1

Please sign in to comment.