From 7030756a983960e69abb3feecf387b5ae414d23e Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Wed, 18 Jul 2012 16:33:18 +0800 Subject: [PATCH 1/2] MDL-30792 Files API: maxbytes will be set by get_max_upload_file_size if less then 0 or greater then max moodle limit --- repository/filepicker.php | 4 ++-- repository/repository_ajax.php | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/repository/filepicker.php b/repository/filepicker.php index 73970d60a28..568cd6d1519 100644 --- a/repository/filepicker.php +++ b/repository/filepicker.php @@ -89,9 +89,9 @@ if ($repo_id) { } $context = context::instance_by_id($contextid); -$moodle_maxbytes = get_user_max_upload_file_size($context); +$moodle_maxbytes = get_user_max_upload_file_size($context, $CFG->maxbytes, $course->maxbytes); // to prevent maxbytes greater than moodle maxbytes setting -if ($maxbytes == 0 || $maxbytes>=$moodle_maxbytes) { +if (($maxbytes <= 0) || ($maxbytes >= $moodle_maxbytes)) { $maxbytes = $moodle_maxbytes; } diff --git a/repository/repository_ajax.php b/repository/repository_ajax.php index 5c368778430..84c92ce9abd 100644 --- a/repository/repository_ajax.php +++ b/repository/repository_ajax.php @@ -78,10 +78,13 @@ $repo = repository::get_repository_by_id($repo_id, $contextid, $repooptions); // Check permissions $repo->check_capability(); - -$moodle_maxbytes = get_user_max_upload_file_size($context); +$coursemaxbytes = 0; +if (!empty($course)) { + $coursemaxbytes = $course->maxbytes; +} +$moodle_maxbytes = get_user_max_upload_file_size($context, $CFG->maxbytes, $coursemaxbytes); // to prevent maxbytes greater than moodle maxbytes setting -if ($maxbytes == 0 || $maxbytes>=$moodle_maxbytes) { +if (($maxbytes <= 0) || ($maxbytes >= $moodle_maxbytes)) { $maxbytes = $moodle_maxbytes; } From 960f4379722c14457ca28b989fed959cfbe71e34 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Fri, 3 Aug 2012 11:20:55 +0800 Subject: [PATCH 2/2] MDL-30792 Files API: Cleaner approach to get maxbytes size in filepicker --- lib/moodlelib.php | 6 +++--- repository/filepicker.php | 8 +++----- repository/repository_ajax.php | 8 +++----- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 842efaceff3..6a6c682105a 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -5861,15 +5861,15 @@ function get_max_upload_file_size($sitebytes=0, $coursebytes=0, $modulebytes=0) } } - if ($sitebytes and $sitebytes < $minimumsize) { + if (($sitebytes > 0) and ($sitebytes < $minimumsize)) { $minimumsize = $sitebytes; } - if ($coursebytes and $coursebytes < $minimumsize) { + if (($coursebytes > 0) and ($coursebytes < $minimumsize)) { $minimumsize = $coursebytes; } - if ($modulebytes and $modulebytes < $minimumsize) { + if (($modulebytes > 0) and ($modulebytes < $minimumsize)) { $minimumsize = $modulebytes; } diff --git a/repository/filepicker.php b/repository/filepicker.php index 568cd6d1519..fd16e6676ca 100644 --- a/repository/filepicker.php +++ b/repository/filepicker.php @@ -89,11 +89,9 @@ if ($repo_id) { } $context = context::instance_by_id($contextid); -$moodle_maxbytes = get_user_max_upload_file_size($context, $CFG->maxbytes, $course->maxbytes); -// to prevent maxbytes greater than moodle maxbytes setting -if (($maxbytes <= 0) || ($maxbytes >= $moodle_maxbytes)) { - $maxbytes = $moodle_maxbytes; -} + +// Make sure maxbytes passed is within site filesize limits. +$maxbytes = get_user_max_upload_file_size($context, $CFG->maxbytes, $course->maxbytes, $maxbytes); $params = array('ctx_id' => $contextid, 'itemid' => $itemid, 'env' => $env, 'course'=>$courseid, 'maxbytes'=>$maxbytes, 'maxfiles'=>$maxfiles, 'subdirs'=>$subdirs, 'sesskey'=>sesskey()); $params['action'] = 'browse'; diff --git a/repository/repository_ajax.php b/repository/repository_ajax.php index 84c92ce9abd..d9f3cea305f 100644 --- a/repository/repository_ajax.php +++ b/repository/repository_ajax.php @@ -78,15 +78,13 @@ $repo = repository::get_repository_by_id($repo_id, $contextid, $repooptions); // Check permissions $repo->check_capability(); + $coursemaxbytes = 0; if (!empty($course)) { $coursemaxbytes = $course->maxbytes; } -$moodle_maxbytes = get_user_max_upload_file_size($context, $CFG->maxbytes, $coursemaxbytes); -// to prevent maxbytes greater than moodle maxbytes setting -if (($maxbytes <= 0) || ($maxbytes >= $moodle_maxbytes)) { - $maxbytes = $moodle_maxbytes; -} +// Make sure maxbytes passed is within site filesize limits. +$maxbytes = get_user_max_upload_file_size($context, $CFG->maxbytes, $coursemaxbytes, $maxbytes); // Wait as long as it takes for this script to finish set_time_limit(0);