Skip to content
This repository has been archived by the owner on Sep 3, 2018. It is now read-only.

Commit

Permalink
[FIX] filegals: Fix logic for getMaxQuotaDescendants function to coll…
Browse files Browse the repository at this point in the history
…ect the quota or contents size of child galleries, not the largest file size (thanks Geoff)

git-svn-id: https://svn.code.sf.net/p/tikiwiki/code/branches/14.x@55400 b456876b-0849-0410-b77d-98878d47e9d5
  • Loading branch information
jonnybradley committed May 12, 2015
1 parent 4672a73 commit 07ae25d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
26 changes: 22 additions & 4 deletions lib/filegals/filegallib.php
Expand Up @@ -1913,18 +1913,36 @@ function getQuota($galleryId=0)
}
return $quota;
}
// get the max quota in M of the children of a fgal

/**
* get the max quota in MB of the children of a fgal,
* or total contents size where no quota is set
*
* @param int $galleryId
* @return float
*/

function getMaxQuotaDescendants($galleryId=0)
{
if (empty($galleryId)) {
return 0;
}
$this->getGalleryChildrenIds($subtree, $galleryId, 'list');
if (is_array($subtree)) {
if (is_array($subtree) && !empty($subtree)) {
$files = $this->table('tiki_files');
return $files->fetchOne($files->max('filesize'), array('galleryId' => $files->in($subtree)));
$gals = $this->table('tiki_file_galleries');
$size = 0;
foreach ($subtree as $subGalleryId) {
$quota = $gals->fetchOne('quota', array('galleryId' => $subGalleryId));
if ($quota) {
$size += $quota;
} else {
$size += $files->fetchOne($files->sum('filesize'), array('galleryId' => $subGalleryId)) / (1024 * 1024);
}
}
return $size;
} else {
return 0;
return 0.0;
}
}
// check quota is smaller than parent quotas and bigger than children quotas
Expand Down
3 changes: 1 addition & 2 deletions tiki-list_file_gallery.php
Expand Up @@ -99,8 +99,7 @@
}
$gal_info['usedSize'] = $filegallib->getUsedSize($_REQUEST['galleryId']);
$gal_info['maxQuota'] = $filegallib->getQuota($gal_info['parentId']);
// quick and dirty fix to Mb byte mismatch with minQuota
$gal_info['minQuota'] = $filegallib->getMaxQuotaDescendants($_REQUEST['galleryId'])/(1024*1024);
$gal_info['minQuota'] = $filegallib->getMaxQuotaDescendants($_REQUEST['galleryId']);

if ($_REQUEST['galleryId'] == $prefs['fgal_root_user_id'] && $tiki_p_admin_file_galleries !== 'y') {
include_once('tiki-sefurl.php');
Expand Down

0 comments on commit 07ae25d

Please sign in to comment.