From: Thomas Mueller Date: Wed, 2 Jan 2013 13:35:45 +0000 (+0100) Subject: moving storage calculation code to OC_Helper::getStorageInfo() X-Git-Tag: v5.0.0alpha1~192^2~23 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2d36a20a1df4129608e9573cea3dcbb2e9de2d12;p=nextcloud-server.git moving storage calculation code to OC_Helper::getStorageInfo() --- diff --git a/lib/helper.php b/lib/helper.php index be4e4e52677..c870536eb52 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -758,4 +758,23 @@ class OC_Helper { } 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); + } } diff --git a/settings/personal.php b/settings/personal.php index 47dbcc53ebc..4624bda8397 100644 --- a/settings/personal.php +++ b/settings/personal.php @@ -15,15 +15,7 @@ OC_Util::addScript( '3rdparty', 'chosen/chosen.jquery.min' ); OC_Util::addStyle( '3rdparty', 'chosen' ); OC_App::setActiveNavigationEntry( 'personal' ); -// calculate the disc space -$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; +$storageInfo=OC_Helper::getStorageInfo(); $email=OC_Preferences::getValue(OC_User::getUser(), 'settings', 'email', ''); @@ -50,9 +42,9 @@ foreach($languageCodes as $lang) { // Return template $tmpl = new OC_Template( 'settings', 'personal', 'user'); -$tmpl->assign('usage', OC_Helper::humanFileSize($used)); -$tmpl->assign('total_space', OC_Helper::humanFileSize($total)); -$tmpl->assign('usage_relative', $relative); +$tmpl->assign('usage', OC_Helper::humanFileSize($storageInfo['used'])); +$tmpl->assign('total_space', OC_Helper::humanFileSize($storageInfo['total'])); +$tmpl->assign('usage_relative', $storageInfo['relative']); $tmpl->assign('email', $email); $tmpl->assign('languages', $languages);