Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'MDL-36708-24' of git://github.com/FMCorz/moodle into MO…

…ODLE_24_STABLE
  • Loading branch information...
commit 9d49ca31b11fc296a6f1c50836232ef64787a0d7 2 parents a79b88e + 217d797
@danpoltawski danpoltawski authored
Showing with 16 additions and 4 deletions.
  1. +16 −4 lib/filelib.php
View
20 lib/filelib.php
@@ -465,6 +465,8 @@ function file_rewrite_pluginfile_urls($text, $file, $contextid, $component, $fil
* @param int $draftitemid the draft area item id.
* @return array with the following entries:
* 'filecount' => number of files in the draft area.
+ * 'filesize' => total size of the 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) {
@@ -475,12 +477,17 @@ function file_get_draft_area_info($draftitemid) {
$results = array();
- // The number of files
+ // The number of files.
$draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id', false);
$results['filecount'] = count($draftfiles);
$results['filesize'] = 0;
+ $results['filesize_without_references'] = 0;
foreach ($draftfiles as $file) {
- $results['filesize'] += $file->get_filesize();
+ $filesize = $file->get_filesize();
+ $results['filesize'] += $filesize;
+ if (!$file->is_external_file()) {
+ $results['filesize_without_references'] += $filesize;
+ }
}
return $results;
@@ -494,13 +501,18 @@ function file_get_draft_area_info($draftitemid) {
* @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;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.