From c24ec867f9e428dd90c021736c2d92c0516e3526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Thu, 21 Feb 2013 12:20:29 +0100 Subject: [PATCH 1/5] calculate versions size per user --- apps/files_versions/appinfo/database.xml | 35 ++++++++++++++++ apps/files_versions/appinfo/version | 2 +- apps/files_versions/lib/versions.php | 53 ++++++++++++++++++++---- 3 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 apps/files_versions/appinfo/database.xml diff --git a/apps/files_versions/appinfo/database.xml b/apps/files_versions/appinfo/database.xml new file mode 100644 index 0000000000..7cfa5aa79a --- /dev/null +++ b/apps/files_versions/appinfo/database.xml @@ -0,0 +1,35 @@ + + + + *dbname* + true + false + + utf8 + + + + *dbprefix*files_versions + + + + + user + text + + true + 50 + + + size + text + + true + 50 + + + + +
+ +
diff --git a/apps/files_versions/appinfo/version b/apps/files_versions/appinfo/version index e6d5cb833c..e4c0d46e55 100644 --- a/apps/files_versions/appinfo/version +++ b/apps/files_versions/appinfo/version @@ -1 +1 @@ -1.0.2 \ No newline at end of file +1.0.3 \ No newline at end of file diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index ba9f8ba41c..415830a9a0 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -45,6 +45,37 @@ class Storage { return array($uid, $filename); } + /** + * get current size of all versions from a given user + * + * @param $user user who owns the versions + * @return mixed versions size or false if no versions size is stored + */ + private static function getVersionsSize($user) { + $query = \OC_DB::prepare('SELECT size FROM *PREFIX*files_versions 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 versions + * + * @param $user owner of the versions + * @param $size size of the versions + */ + private static function setVersionsSize($user, $size) { + if ( self::getVersionsSize($user) === false) { + $query = \OC_DB::prepare('INSERT INTO *PREFIX*files_versions (size, user) VALUES (?, ?)'); + }else { + $query = \OC_DB::prepare('UPDATE *PREFIX*files_versions SET size=? WHERE user=?'); + } + $query->execute(array($size, $user)); + } + /** * store a new version of a file. */ @@ -73,17 +104,19 @@ class Storage { } // store a new version of a file - $result = $users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename)); - if ( ($versionsSize = \OCP\Config::getAppValue('files_versions', 'size')) === null ) { + $users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename)); + $versionsSize = self::getVersionsSize($uid); + if ( $versionsSize === false || $versionSize < 0 ) { $versionsSize = self::calculateSize($uid); } + $versionsSize += $users_view->filesize('files'.$filename); - + // expire old revisions if necessary $newSize = self::expire($filename, $versionsSize); - + if ( $newSize != $versionsSize ) { - \OCP\Config::setAppValue('files_versions', 'size', $versionsSize); + self::setVersionsSize($uid, $newSize); } } } @@ -98,14 +131,15 @@ class Storage { $abs_path = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$filename.'.v'; if( ($versions = self::getVersions($uid, $filename)) ) { - if ( ($versionsSize = \OCP\Config::getAppValue('files_versions', 'size')) === null ) { + $versionsSize = self::getVersionsSize($uid); + if ( $versionsSize === false || $versionsSize < 0 ) { $versionsSize = self::calculateSize($uid); } foreach ($versions as $v) { unlink($abs_path . $v['version']); $versionsSize -= $v['size']; } - \OCP\Config::setAppValue('files_versions', 'size', $versionsSize); + self::setVersionsSize($uid, $versionsSize); } } @@ -314,12 +348,13 @@ class Storage { $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()); } // make sure that we have the current size of the version history if ( $versionsSize === null ) { - if ( ($versionsSize = \OCP\Config::getAppValue('files_versions', 'size')) === null ) { + $versionsSize = self::getVersionsSize($uid); + if ( $versionsSize === false || $versionsSize < 0 ) { $versionsSize = self::calculateSize($uid); } } From 2436d01985311b3cd14c2f0dec745081ae7d3507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Thu, 21 Feb 2013 12:37:13 +0100 Subject: [PATCH 2/5] calculate trashbin size per user --- apps/files_trashbin/appinfo/database.xml | 26 ++++++++++++ apps/files_trashbin/appinfo/version | 2 +- apps/files_trashbin/lib/trash.php | 52 ++++++++++++++++++++---- 3 files changed, 71 insertions(+), 9 deletions(-) diff --git a/apps/files_trashbin/appinfo/database.xml b/apps/files_trashbin/appinfo/database.xml index 1144a1c9a9..6f2a27866f 100644 --- a/apps/files_trashbin/appinfo/database.xml +++ b/apps/files_trashbin/appinfo/database.xml @@ -89,4 +89,30 @@ + + + *dbprefix*files_trashsize + + + + + user + text + + true + 50 + + + + size + text + + true + 50 + + + + +
+ diff --git a/apps/files_trashbin/appinfo/version b/apps/files_trashbin/appinfo/version index 49d59571fb..be58634173 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 8d54a471b4..898f897273 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)); + } } From 629097bee73d70af002a5277529a7afdca75897d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Thu, 21 Feb 2013 22:44:44 +0100 Subject: [PATCH 3/5] increase db fileds for usernames --- apps/files_trashbin/appinfo/database.xml | 4 ++-- apps/files_versions/appinfo/database.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/files_trashbin/appinfo/database.xml b/apps/files_trashbin/appinfo/database.xml index 6f2a27866f..6f12b26d05 100644 --- a/apps/files_trashbin/appinfo/database.xml +++ b/apps/files_trashbin/appinfo/database.xml @@ -26,7 +26,7 @@ text true - 50 + 64 @@ -100,7 +100,7 @@ text true - 50 + 64 diff --git a/apps/files_versions/appinfo/database.xml b/apps/files_versions/appinfo/database.xml index 7cfa5aa79a..d385477698 100644 --- a/apps/files_versions/appinfo/database.xml +++ b/apps/files_versions/appinfo/database.xml @@ -18,7 +18,7 @@ text true - 50 + 64 size From df76e0d1c33fc1fa9610b98a7aee41941c09eb3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Fri, 22 Feb 2013 10:05:08 +0100 Subject: [PATCH 4/5] use the same string lengths like the file cache --- apps/files_trashbin/appinfo/database.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_trashbin/appinfo/database.xml b/apps/files_trashbin/appinfo/database.xml index 6f12b26d05..aae334b148 100644 --- a/apps/files_trashbin/appinfo/database.xml +++ b/apps/files_trashbin/appinfo/database.xml @@ -18,7 +18,7 @@ text true - 50 + 250 @@ -42,7 +42,7 @@ text true - 200 + 512 From e30b3f64e09acfd813f13d1c54872e484ec03382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 25 Feb 2013 14:29:31 +0100 Subject: [PATCH 5/5] fix line endings --- apps/files_trashbin/lib/trash.php | 188 +++++++++++++++--------------- 1 file changed, 94 insertions(+), 94 deletions(-) diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index 032df86a61..8f745f8203 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -36,77 +36,77 @@ class Trashbin { */ public static function move2trash($file_path) { $user = \OCP\User::getUser(); - $view = new \OC\Files\View('/'. $user); - if (!$view->is_dir('files_trashbin')) { - $view->mkdir('files_trashbin'); + $view = new \OC\Files\View('/'. $user); + if (!$view->is_dir('files_trashbin')) { + $view->mkdir('files_trashbin'); $view->mkdir("files_trashbin/files"); $view->mkdir("files_trashbin/versions"); - $view->mkdir("files_trashbin/keyfiles"); - } - - $path_parts = pathinfo($file_path); - - $deleted = $path_parts['basename']; - $location = $path_parts['dirname']; - $timestamp = time(); - $mime = $view->getMimeType('files'.$file_path); - - if ( $view->is_dir('files'.$file_path) ) { - $type = 'dir'; - } else { - $type = 'file'; + $view->mkdir("files_trashbin/keyfiles"); + } + + $path_parts = pathinfo($file_path); + + $deleted = $path_parts['basename']; + $location = $path_parts['dirname']; + $timestamp = time(); + $mime = $view->getMimeType('files'.$file_path); + + if ( $view->is_dir('files'.$file_path) ) { + $type = 'dir'; + } else { + $type = 'file'; } - $trashbinSize = self::getTrashbinSize($user); + $trashbinSize = self::getTrashbinSize($user); if ( $trashbinSize === false || $trashbinSize < 0 ) { $trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin')); } $trashbinSize += self::copy_recursive($file_path, 'files_trashbin/files/'.$deleted.'.d'.$timestamp, $view); - if ( $view->file_exists('files_trashbin/files/'.$deleted.'.d'.$timestamp) ) { + if ( $view->file_exists('files_trashbin/files/'.$deleted.'.d'.$timestamp) ) { $query = \OC_DB::prepare("INSERT INTO *PREFIX*files_trash (id,timestamp,location,type,mime,user) VALUES (?,?,?,?,?,?)"); $result = $query->execute(array($deleted, $timestamp, $location, $type, $mime, $user)); if ( !$result ) { // if file couldn't be added to the database than also don't store it in the trash bin. $view->deleteAll('files_trashbin/files/'.$deleted.'.d'.$timestamp); \OC_Log::write('files_trashbin', 'trash bin database couldn\'t be updated', \OC_log::ERROR); return; - } + } - // Take care of file versions - if ( \OCP\App::isEnabled('files_versions') ) { + // Take care of file versions + if ( \OCP\App::isEnabled('files_versions') ) { if ( $view->is_dir('files_versions'.$file_path) ) { - $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_versions/'.$file_path)); - $view->rename('files_versions'.$file_path, 'files_trashbin/versions'. $deleted.'.d'.$timestamp); - } else if ( $versions = \OCA\Files_Versions\Storage::getVersions($file_path) ) { + $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_versions/'.$file_path)); + $view->rename('files_versions'.$file_path, 'files_trashbin/versions'. $deleted.'.d'.$timestamp); + } else if ( $versions = \OCA\Files_Versions\Storage::getVersions($file_path) ) { foreach ($versions as $v) { - $trashbinSize += $view->filesize('files_versions'.$v['path'].'.v'.$v['version']); - $view->rename('files_versions'.$v['path'].'.v'.$v['version'], 'files_trashbin/versions'. $deleted.'.v'.$v['version'].'.d'.$timestamp); - } + $trashbinSize += $view->filesize('files_versions'.$v['path'].'.v'.$v['version']); + $view->rename('files_versions'.$v['path'].'.v'.$v['version'], 'files_trashbin/versions'. $deleted.'.v'.$v['version'].'.d'.$timestamp); + } } } // Take care of encryption keys - $keyfile = \OC_Filesystem::normalizePath('files_encryption/keyfiles/'.$file_path); + $keyfile = \OC_Filesystem::normalizePath('files_encryption/keyfiles/'.$file_path); if ( \OCP\App::isEnabled('files_encryption') && $view->file_exists($keyfile.'.key') ) { if ( $view->is_dir('files'.$file_path) ) { $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'.$user.'/'.$keyfile)); $view->rename($keyfile, 'files_trashbin/keyfiles/'. $deleted.'.d'.$timestamp); - } else { + } else { $trashbinSize += $view->filesize($keyfile.'.key'); $view->rename($keyfile.'.key', 'files_trashbin/keyfiles/'. $deleted.'.key.d'.$timestamp); - } + } } } else { \OC_Log::write('files_trashbin', 'Couldn\'t move '.$file_path.' to the trash bin', \OC_log::ERROR); } - // get available disk space for user - $quota = \OCP\Util::computerFileSize(\OC_Preferences::getValue($user, 'files', 'quota')); - if ( $quota === null ) { - $quota = \OCP\Util::computerFileSize(\OC_Appconfig::getValue('files', 'default_quota')); - } - if ( $quota === null ) { + // get available disk space for user + $quota = \OCP\Util::computerFileSize(\OC_Preferences::getValue($user, 'files', 'quota')); + if ( $quota === null ) { + $quota = \OCP\Util::computerFileSize(\OC_Appconfig::getValue('files', 'default_quota')); + } + if ( $quota === null ) { $quota = \OC\Files\Filesystem::free_space('/') / count(\OCP\User::getUsers()); } @@ -121,7 +121,7 @@ class Trashbin { $trashbinSize -= self::expire($availableSpace); - self::setTrashbinSize($user, $trashbinSize); + self::setTrashbinSize($user, $trashbinSize); } @@ -186,9 +186,9 @@ class Trashbin { $versionedFile = $file; } if ( $result[0]['type'] === 'dir' ) { - $trashbinSize -= self::calculateSize(new \OC_FilesystemView('/'.$user.'/'.'files_trashbin/versions/'. $file)); - $view->rename(\OC_Filesystem::normalizePath('files_trashbin/versions/'. $file), \OC_Filesystem::normalizePath('files_versions/'.$location.'/'.$filename.$ext)); - } else if ( $versions = self::getVersionsFromTrash($versionedFile, $timestamp) ) { + $trashbinSize -= self::calculateSize(new \OC_FilesystemView('/'.$user.'/'.'files_trashbin/versions/'. $file)); + $view->rename(\OC_Filesystem::normalizePath('files_trashbin/versions/'. $file), \OC_Filesystem::normalizePath('files_versions/'.$location.'/'.$filename.$ext)); + } else if ( $versions = self::getVersionsFromTrash($versionedFile, $timestamp) ) { foreach ($versions as $v) { if ($timestamp ) { $trashbinSize -= $view->filesize('files_trashbin/versions/'.$versionedFile.'.v'.$v.'.d'.$timestamp); @@ -196,8 +196,8 @@ class Trashbin { } else { $trashbinSize -= $view->filesize('files_trashbin/versions/'.$versionedFile.'.v'.$v); $view->rename('files_trashbin/versions/'.$versionedFile.'.v'.$v, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v); - } - } + } + } } } @@ -210,15 +210,15 @@ class Trashbin { } if ($timestamp) { $keyfile .= '.d'.$timestamp; - } + } if ( \OCP\App::isEnabled('files_encryption') && $view->file_exists($keyfile) ) { - if ( $result[0]['type'] === 'dir' ) { + if ( $result[0]['type'] === 'dir' ) { $trashbinSize -= self::calculateSize(new \OC_FilesystemView('/'.$user.'/'.$keyfile)); $view->rename($keyfile, 'files_encryption/keyfiles/'. $location.'/'.$filename); } else { $trashbinSize -= $view->filesize($keyfile); $view->rename($keyfile, 'files_encryption/keyfiles/'. $location.'/'.$filename.'.key'); - } + } } if ( $timestamp ) { @@ -245,7 +245,7 @@ class Trashbin { public static function delete($filename, $timestamp=null) { $user = \OCP\User::getUser(); $view = new \OC_FilesystemView('/'.$user); - $size = 0; + $size = 0; $trashbinSize = self::getTrashbinSize($user); if ( $trashbinSize === false || $trashbinSize < 0 ) { @@ -278,23 +278,23 @@ class Trashbin { } // Take care of encryption keys - $parts = pathinfo($file); - if ( $view->is_dir('/files_trashbin/files/'.$file) ) { - $keyfile = \OC_Filesystem::normalizePath('files_trashbin/keyfiles/'.$filename); - } else { - $keyfile = \OC_Filesystem::normalizePath('files_trashbin/keyfiles/'.$filename.'.key'); - } - if ($timestamp) { - $keyfile .= '.d'.$timestamp; - } - if ( \OCP\App::isEnabled('files_encryption') && $view->file_exists($keyfile) ) { - if ( $view->is_dir($keyfile) ) { - $size += self::calculateSize(new \OC_FilesystemView('/'.$user.'/'.$keyfile)); - } else { - $size += $view->filesize($keyfile); - } - $view->unlink($keyfile); - } + $parts = pathinfo($file); + if ( $view->is_dir('/files_trashbin/files/'.$file) ) { + $keyfile = \OC_Filesystem::normalizePath('files_trashbin/keyfiles/'.$filename); + } else { + $keyfile = \OC_Filesystem::normalizePath('files_trashbin/keyfiles/'.$filename.'.key'); + } + if ($timestamp) { + $keyfile .= '.d'.$timestamp; + } + if ( \OCP\App::isEnabled('files_encryption') && $view->file_exists($keyfile) ) { + if ( $view->is_dir($keyfile) ) { + $size += self::calculateSize(new \OC_FilesystemView('/'.$user.'/'.$keyfile)); + } else { + $size += $view->filesize($keyfile); + } + $view->unlink($keyfile); + } if ($view->is_dir('/files_trashbin/files/'.$file)) { $size += self::calculateSize(new \OC_Filesystemview('/'.$user.'/files_trashbin/files/'.$file)); @@ -304,7 +304,7 @@ class Trashbin { $view->unlink('/files_trashbin/files/'.$file); $trashbinSize -= $size; self::setTrashbinSize($user, $trashbinSize); - + return $size; } @@ -477,35 +477,35 @@ 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)); + /** + * 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)); } }