Merge branch 'MDL-36708-master' of git://github.com/FMCorz/moodle
This commit is contained in:
+16
-4
@@ -468,6 +468,7 @@ function file_rewrite_pluginfile_urls($text, $file, $contextid, $component, $fil
|
||||
* 'filecount' => number of files in the draft area.
|
||||
* 'filesize' => total size of the files in the draft area.
|
||||
* 'foldercount' => number of folders in the draft area.
|
||||
* 'filesize_without_references' => total size of the area excluding file references.
|
||||
* (more information will be added as needed).
|
||||
*/
|
||||
function file_get_draft_area_info($draftitemid, $filepath = '/') {
|
||||
@@ -479,7 +480,8 @@ function file_get_draft_area_info($draftitemid, $filepath = '/') {
|
||||
$results = array(
|
||||
'filecount' => 0,
|
||||
'foldercount' => 0,
|
||||
'filesize' => 0
|
||||
'filesize' => 0,
|
||||
'filesize_without_references'
|
||||
);
|
||||
|
||||
if ($filepath != '/') {
|
||||
@@ -493,7 +495,12 @@ function file_get_draft_area_info($draftitemid, $filepath = '/') {
|
||||
} else {
|
||||
$results['filecount'] += 1;
|
||||
}
|
||||
$results['filesize'] += $file->get_filesize();
|
||||
|
||||
$filesize = $file->get_filesize();
|
||||
$results['filesize'] += $filesize;
|
||||
if (!$file->is_external_file()) {
|
||||
$results['filesize_without_references'] += $filesize;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
@@ -507,13 +514,18 @@ function file_get_draft_area_info($draftitemid, $filepath = '/') {
|
||||
* @param int $draftitemid the draft area item id.
|
||||
* @param int $areamaxbytes the maximum size allowed in this draft area.
|
||||
* @param int $newfilesize the size that would be added to the current area.
|
||||
* @param bool $includereferences true to include the size of the references in the area size.
|
||||
* @return bool true if the area will/has exceeded its limit.
|
||||
* @since 2.4
|
||||
*/
|
||||
function file_is_draft_area_limit_reached($draftitemid, $areamaxbytes, $newfilesize = 0) {
|
||||
function file_is_draft_area_limit_reached($draftitemid, $areamaxbytes, $newfilesize = 0, $includereferences = false) {
|
||||
if ($areamaxbytes != FILE_AREA_MAX_BYTES_UNLIMITED) {
|
||||
$draftinfo = file_get_draft_area_info($draftitemid);
|
||||
if ($draftinfo['filesize'] + $newfilesize > $areamaxbytes) {
|
||||
$areasize = $draftinfo['filesize_without_references'];
|
||||
if ($includereferences) {
|
||||
$areasize = $draftinfo['filesize'];
|
||||
}
|
||||
if ($areasize + $newfilesize > $areamaxbytes) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user