Skip to content

Commit

Permalink
MDL-30792 Files API: Cleaner approach to get maxbytes size in filepicker
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajesh Taneja committed Aug 3, 2012
1 parent d3e1371 commit 6ecbaca
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/moodlelib.php
Expand Up @@ -5842,15 +5842,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;
}

Expand Down
8 changes: 3 additions & 5 deletions repository/filepicker.php
Expand Up @@ -89,11 +89,9 @@
}

$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';
Expand Down
8 changes: 3 additions & 5 deletions repository/repository_ajax.php
Expand Up @@ -78,15 +78,13 @@

// 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);
Expand Down

0 comments on commit 6ecbaca

Please sign in to comment.