moving storage calculation code to OC_Helper::getStorageInfo()

This commit is contained in:
Thomas Mueller 2013-01-02 14:35:45 +01:00
parent 516464ba94
commit 2d36a20a1d
2 changed files with 23 additions and 12 deletions

View File

@ -758,4 +758,23 @@ class OC_Helper {
} }
return $str; return $str;
} }
/**
* Calculate the disc space
*/
public static function getStorageInfo() {
$rootInfo = OC_FileCache::get('');
$used = $rootInfo['size'];
if ($used < 0) {
$used = 0;
}
$free = OC_Filesystem::free_space();
$total = $free + $used;
if ($total == 0) {
$total = 1; // prevent division by zero
}
$relative = round(($used / $total) * 10000) / 100;
return array('free' => $free, 'used' => $used, 'total' => $total, 'relative' => $relative);
}
} }

View File

@ -15,15 +15,7 @@ OC_Util::addScript( '3rdparty', 'chosen/chosen.jquery.min' );
OC_Util::addStyle( '3rdparty', 'chosen' ); OC_Util::addStyle( '3rdparty', 'chosen' );
OC_App::setActiveNavigationEntry( 'personal' ); OC_App::setActiveNavigationEntry( 'personal' );
// calculate the disc space $storageInfo=OC_Helper::getStorageInfo();
$rootInfo=OC_FileCache::get('');
$sharedInfo=OC_FileCache::get('/Shared');
$used=$rootInfo['size'];
if($used<0) $used=0;
$free=OC_Filesystem::free_space();
$total=$free+$used;
if($total==0) $total=1; // prevent division by zero
$relative=round(($used/$total)*10000)/100;
$email=OC_Preferences::getValue(OC_User::getUser(), 'settings', 'email', ''); $email=OC_Preferences::getValue(OC_User::getUser(), 'settings', 'email', '');
@ -50,9 +42,9 @@ foreach($languageCodes as $lang) {
// Return template // Return template
$tmpl = new OC_Template( 'settings', 'personal', 'user'); $tmpl = new OC_Template( 'settings', 'personal', 'user');
$tmpl->assign('usage', OC_Helper::humanFileSize($used)); $tmpl->assign('usage', OC_Helper::humanFileSize($storageInfo['used']));
$tmpl->assign('total_space', OC_Helper::humanFileSize($total)); $tmpl->assign('total_space', OC_Helper::humanFileSize($storageInfo['total']));
$tmpl->assign('usage_relative', $relative); $tmpl->assign('usage_relative', $storageInfo['relative']);
$tmpl->assign('email', $email); $tmpl->assign('email', $email);
$tmpl->assign('languages', $languages); $tmpl->assign('languages', $languages);