aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2013-02-21 12:37:13 +0100
committerBjörn Schießle <schiessle@owncloud.com>2013-02-21 12:37:13 +0100
commit2436d01985311b3cd14c2f0dec745081ae7d3507 (patch)
treed36220b44c17a6247856721869ad4d36ad6b54eb /apps
parentc24ec867f9e428dd90c021736c2d92c0516e3526 (diff)
downloadnextcloud-server-2436d01985311b3cd14c2f0dec745081ae7d3507.tar.gz
nextcloud-server-2436d01985311b3cd14c2f0dec745081ae7d3507.zip
calculate trashbin size per user
Diffstat (limited to 'apps')
-rw-r--r--apps/files_trashbin/appinfo/database.xml26
-rw-r--r--apps/files_trashbin/appinfo/version2
-rw-r--r--apps/files_trashbin/lib/trash.php52
3 files changed, 71 insertions, 9 deletions
diff --git a/apps/files_trashbin/appinfo/database.xml b/apps/files_trashbin/appinfo/database.xml
index 1144a1c9a97..6f2a27866ff 100644
--- a/apps/files_trashbin/appinfo/database.xml
+++ b/apps/files_trashbin/appinfo/database.xml
@@ -89,4 +89,30 @@
</table>
+ <table>
+
+ <name>*dbprefix*files_trashsize</name>
+
+ <declaration>
+
+ <field>
+ <name>user</name>
+ <type>text</type>
+ <default></default>
+ <notnull>true</notnull>
+ <length>50</length>
+ </field>
+
+ <field>
+ <name>size</name>
+ <type>text</type>
+ <default></default>
+ <notnull>true</notnull>
+ <length>50</length>
+ </field>
+
+ </declaration>
+
+ </table>
+
</database>
diff --git a/apps/files_trashbin/appinfo/version b/apps/files_trashbin/appinfo/version
index 49d59571fbf..be586341736 100644
--- a/apps/files_trashbin/appinfo/version
+++ b/apps/files_trashbin/appinfo/version
@@ -1 +1 @@
-0.1
+0.3
diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php
index 8d54a471b42..898f8972737 100644
--- a/apps/files_trashbin/lib/trash.php
+++ b/apps/files_trashbin/lib/trash.php
@@ -52,8 +52,9 @@ class Trashbin {
} else {
$type = 'file';
}
-
- if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) {
+
+ $trashbinSize = self::getTrashbinSize($user);
+ if ( $trashbinSize === false || $trashbinSize < 0 ) {
$trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin'));
$trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin'));
}
@@ -89,7 +90,7 @@ class Trashbin {
$quota = \OCP\Util::computerFileSize(\OC_Appconfig::getValue('files', 'default_quota'));
}
if ( $quota == null ) {
- $quota = \OC\Files\Filesystem::free_space('/');
+ $quota = \OC\Files\Filesystem::free_space('/') / count(\OCP\User::getUsers());
}
// calculate available space for trash bin
@@ -102,7 +103,8 @@ class Trashbin {
}
$trashbinSize -= self::expire($availableSpace);
- \OCP\Config::setAppValue('files_trashbin', 'size', $trashbinSize);
+
+ self::setTrashbinSize($user, $trashbinSize);
}
@@ -116,7 +118,8 @@ class Trashbin {
$user = \OCP\User::getUser();
$view = new \OC_FilesystemView('/'.$user);
- if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) {
+ $trashbinSize = self::getTrashbinSize($user);
+ if ( $trashbinSize === false || $trashbinSize < 0 ) {
$trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin'));
$trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin'));
}
@@ -185,7 +188,8 @@ class Trashbin {
$query->execute(array($user,$filename,$timestamp));
}
- \OCP\Config::setAppValue('files_trashbin', 'size', $trashbinSize);
+ self::setTrashbinSize($user, $trashbinSize);
+
return true;
} else {
\OC_Log::write('files_trashbin', 'Couldn\'t restore file from trash bin, '.$filename, \OC_log::ERROR);
@@ -205,7 +209,8 @@ class Trashbin {
$view = new \OC_FilesystemView('/'.$user);
$size = 0;
- if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) {
+ $trashbinSize = self::getTrashbinSize($user);
+ if ( $trashbinSize === false || $trashbinSize < 0 ) {
$trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin'));
$trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin'));
}
@@ -242,7 +247,7 @@ class Trashbin {
}
$view->unlink('/files_trashbin/'.$file);
$trashbinSize -= $size;
- \OCP\Config::setAppValue('files_trashbin', 'size', $trashbinSize);
+ self::setTrashbinSize($user, $trashbinSize);
return $size;
}
@@ -429,5 +434,36 @@ class Trashbin {
}
return $size;
}
+
+ /**
+ * get current size of trash bin from a given user
+ *
+ * @param $user user who owns the trash bin
+ * @return mixed trash bin size or false if no trash bin size is stored
+ */
+ private static function getTrashbinSize($user) {
+ $query = \OC_DB::prepare('SELECT size FROM *PREFIX*files_trashsize WHERE user=?');
+ $result = $query->execute(array($user))->fetchAll();
+
+ if ($result) {
+ return $result[0]['size'];
+ }
+ return false;
+ }
+
+ /**
+ * write to the database how much space is in use for the trash bin
+ *
+ * @param $user owner of the trash bin
+ * @param $size size of the trash bin
+ */
+ private static function setTrashbinSize($user, $size) {
+ if ( self::getTrashbinSize($user) === false) {
+ $query = \OC_DB::prepare('INSERT INTO *PREFIX*files_trashsize (size, user) VALUES (?, ?)');
+ }else {
+ $query = \OC_DB::prepare('UPDATE *PREFIX*files_trashsize SET size=? WHERE user=?');
+ }
+ $query->execute(array($size, $user));
+ }
}