Permalink
Browse files

MDL-36708 files: Checking the size limit of a draft area does include…

… references
  • Loading branch information...
FMCorz committed Jan 7, 2013
1 parent ca48fe5 commit 7aff468346f8c36476e05012e979a40282185330
Showing with 16 additions and 4 deletions.
  1. +16 −4 lib/filelib.php
View
@@ -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;
}
}

0 comments on commit 7aff468

Please sign in to comment.