re-implement/refactor getQuotaInfo() on DAV storage
This commit is contained in:
parent
4a028b6015
commit
7a144b90fb
@ -9,7 +9,7 @@ require_once('include/conversation.php');
|
|||||||
class Home extends \Zotlabs\Web\Controller {
|
class Home extends \Zotlabs\Web\Controller {
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
|
||||||
$ret = array();
|
$ret = array();
|
||||||
|
|
||||||
call_hooks('home_init',$ret);
|
call_hooks('home_init',$ret);
|
||||||
|
@ -333,6 +333,7 @@ class Browser extends DAV\Browser\Plugin {
|
|||||||
|
|
||||||
$aclselect = null;
|
$aclselect = null;
|
||||||
$lockstate = '';
|
$lockstate = '';
|
||||||
|
$limit = 0;
|
||||||
|
|
||||||
if($this->auth->owner_id) {
|
if($this->auth->owner_id) {
|
||||||
$channel = channelx_by_n($this->auth->owner_id);
|
$channel = channelx_by_n($this->auth->owner_id);
|
||||||
@ -343,10 +344,11 @@ class Browser extends DAV\Browser\Plugin {
|
|||||||
|
|
||||||
$aclselect = ((local_channel() == $this->auth->owner_id) ? populate_acl($channel_acl,false, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_storage')) : '');
|
$aclselect = ((local_channel() == $this->auth->owner_id) ? populate_acl($channel_acl,false, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_storage')) : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Storage and quota for the account (all channels of the owner of this directory)!
|
||||||
|
$limit = engr_units_to_bytes(service_class_fetch($this->auth->owner_id, 'attach_upload_limit'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storage and quota for the account (all channels of the owner of this directory)!
|
|
||||||
$limit = engr_units_to_bytes(service_class_fetch($owner, 'attach_upload_limit'));
|
|
||||||
if((! $limit) && get_config('system','cloud_report_disksize')) {
|
if((! $limit) && get_config('system','cloud_report_disksize')) {
|
||||||
$limit = engr_units_to_bytes(disk_free_space('store'));
|
$limit = engr_units_to_bytes(disk_free_space('store'));
|
||||||
}
|
}
|
||||||
|
@ -571,39 +571,6 @@ class Directory extends DAV\Node implements DAV\ICollection, DAV\IQuota, DAV\IMo
|
|||||||
return datetime_convert('UTC', 'UTC', $r[0]['edited'], 'U');
|
return datetime_convert('UTC', 'UTC', $r[0]['edited'], 'U');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Return quota usage.
|
|
||||||
*
|
|
||||||
* @fixme Should guests relly see the used/free values from filesystem of the
|
|
||||||
* complete store directory?
|
|
||||||
*
|
|
||||||
* @return array with used and free values in bytes.
|
|
||||||
*/
|
|
||||||
public function getQuotaInfo() {
|
|
||||||
// values from the filesystem of the complete <i>store/</i> directory
|
|
||||||
$limit = disk_total_space('store');
|
|
||||||
$free = disk_free_space('store');
|
|
||||||
|
|
||||||
if ($this->auth->owner_id) {
|
|
||||||
$c = q("select * from channel where channel_id = %d and channel_removed = 0 limit 1",
|
|
||||||
intval($this->auth->owner_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
$ulimit = engr_units_to_bytes(service_class_fetch($c[0]['channel_id'], 'attach_upload_limit'));
|
|
||||||
$limit = (($ulimit) ? $ulimit : $limit);
|
|
||||||
|
|
||||||
$x = q("select sum(filesize) as total from attach where aid = %d",
|
|
||||||
intval($c[0]['channel_account_id'])
|
|
||||||
);
|
|
||||||
$free = (($x) ? $limit - $x[0]['total'] : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array(
|
|
||||||
$limit - $free,
|
|
||||||
$free
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Array with all Directory and File DAV\\Node items for the given path.
|
* @brief Array with all Directory and File DAV\\Node items for the given path.
|
||||||
@ -895,4 +862,48 @@ class Directory extends DAV\Node implements DAV\ICollection, DAV\IQuota, DAV\IMo
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getQuotaInfo() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the quota information
|
||||||
|
*
|
||||||
|
* This method MUST return an array with 2 values, the first being the total used space,
|
||||||
|
* the second the available space (in bytes)
|
||||||
|
*/
|
||||||
|
|
||||||
|
$used = 0;
|
||||||
|
$limit = 0;
|
||||||
|
$free = 0;
|
||||||
|
|
||||||
|
if ($this->auth->owner_id) {
|
||||||
|
$channel = channelx_by_n($this->auth->owner_id);
|
||||||
|
if($channel) {
|
||||||
|
$r = q("SELECT SUM(filesize) AS total FROM attach WHERE aid = %d",
|
||||||
|
intval($channel['channel_account_id'])
|
||||||
|
);
|
||||||
|
$used = (($r) ? (float) $r[0]['total'] : 0);
|
||||||
|
$limit = (float) service_class_fetch($this->auth->owner_id, 'attach_upload_limit');
|
||||||
|
if($limit) {
|
||||||
|
// Don't let the result go negative
|
||||||
|
$free = (($limit > $used) ? $limit - $used : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(! $limit) {
|
||||||
|
$free = disk_free_space('store');
|
||||||
|
$used = disk_total_space('store') - $free;
|
||||||
|
}
|
||||||
|
|
||||||
|
// prevent integer overflow on 32-bit systems
|
||||||
|
|
||||||
|
if($used > (float) PHP_INT_MAX)
|
||||||
|
$used = PHP_INT_MAX;
|
||||||
|
if($free > (float) PHP_INT_MAX)
|
||||||
|
$free = PHP_INT_MAX;
|
||||||
|
|
||||||
|
return [ (int) $used, (int) $free ];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ function tt($singular, $plural, $count, $ctx = ''){
|
|||||||
if (! function_exists($f))
|
if (! function_exists($f))
|
||||||
$f = 'string_plural_select_default';
|
$f = 'string_plural_select_default';
|
||||||
|
|
||||||
$k = $f($count);
|
$k = $f(intval($count));
|
||||||
|
|
||||||
return is_array($t) ? $t[$k] : $t;
|
return is_array($t) ? $t[$k] : $t;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user