MDL-30792 Files API: Cleaner approach to get maxbytes size in filepicker

This commit is contained in:
Rajesh Taneja 2012-08-03 11:20:55 +08:00
parent 7030756a98
commit 960f437972
3 changed files with 9 additions and 13 deletions

View file

@ -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; $minimumsize = $sitebytes;
} }
if ($coursebytes and $coursebytes < $minimumsize) { if (($coursebytes > 0) and ($coursebytes < $minimumsize)) {
$minimumsize = $coursebytes; $minimumsize = $coursebytes;
} }
if ($modulebytes and $modulebytes < $minimumsize) { if (($modulebytes > 0) and ($modulebytes < $minimumsize)) {
$minimumsize = $modulebytes; $minimumsize = $modulebytes;
} }

View file

@ -89,11 +89,9 @@ if ($repo_id) {
} }
$context = context::instance_by_id($contextid); $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 // Make sure maxbytes passed is within site filesize limits.
if (($maxbytes <= 0) || ($maxbytes >= $moodle_maxbytes)) { $maxbytes = get_user_max_upload_file_size($context, $CFG->maxbytes, $course->maxbytes, $maxbytes);
$maxbytes = $moodle_maxbytes;
}
$params = array('ctx_id' => $contextid, 'itemid' => $itemid, 'env' => $env, 'course'=>$courseid, 'maxbytes'=>$maxbytes, 'maxfiles'=>$maxfiles, 'subdirs'=>$subdirs, 'sesskey'=>sesskey()); $params = array('ctx_id' => $contextid, 'itemid' => $itemid, 'env' => $env, 'course'=>$courseid, 'maxbytes'=>$maxbytes, 'maxfiles'=>$maxfiles, 'subdirs'=>$subdirs, 'sesskey'=>sesskey());
$params['action'] = 'browse'; $params['action'] = 'browse';

View file

@ -78,15 +78,13 @@ $repo = repository::get_repository_by_id($repo_id, $contextid, $repooptions);
// Check permissions // Check permissions
$repo->check_capability(); $repo->check_capability();
$coursemaxbytes = 0; $coursemaxbytes = 0;
if (!empty($course)) { if (!empty($course)) {
$coursemaxbytes = $course->maxbytes; $coursemaxbytes = $course->maxbytes;
} }
$moodle_maxbytes = get_user_max_upload_file_size($context, $CFG->maxbytes, $coursemaxbytes); // Make sure maxbytes passed is within site filesize limits.
// to prevent maxbytes greater than moodle maxbytes setting $maxbytes = get_user_max_upload_file_size($context, $CFG->maxbytes, $coursemaxbytes, $maxbytes);
if (($maxbytes <= 0) || ($maxbytes >= $moodle_maxbytes)) {
$maxbytes = $moodle_maxbytes;
}
// Wait as long as it takes for this script to finish // Wait as long as it takes for this script to finish
set_time_limit(0); set_time_limit(0);