Skip to content

Commit 2b4eaab

Browse files
committed
throwing correct error message whenever a user tries to insert a file from ocis into moodle that is bigger than the configured max size.
1 parent 08a8bf9 commit 2b4eaab

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lang/en/repository_ocis.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@
6262
$string['webfinger_error'] = 'Could not get user-information from webfinger service.';
6363
$string['personal_drive'] = 'Personal';
6464
$string['shares_drive'] = 'Shares';
65+
$string['exceed_maxbytes_error'] = 'File exceeds maximum uploaded file size limit';

lib.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,21 @@ public static function get_instance_option_names() {
379379
* @throws moodle_exception
380380
*/
381381
public function get_file($fileid, $filename = ''): array {
382+
global $CFG;
383+
382384
$localpath = $this->prepare_file($fileid);
383385
try {
384386
$file = $this->getocismanager()->get_ocis_client()->getResourceById($fileid);
385-
file_put_contents($localpath, $file->getContentStream());
387+
if ($file->getSize() > (int)$CFG->maxbytes && (int)$CFG->maxbytes !== 0) {
388+
throw new moodle_exception(
389+
'exceed_maxbytes_error',
390+
'repository_ocis',
391+
'',
392+
null,
393+
);
394+
} else {
395+
file_put_contents($localpath, $file->getContentStream());
396+
}
386397
} catch (HttpException $e) {
387398
throw new moodle_exception(
388399
'could_not_connect_error',

0 commit comments

Comments
 (0)