} else {\r
$type = 'file';\r
}
- \r
- if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) {\r
+
+ $trashbinSize = self::getTrashbinSize($user);\r
+ if ( $trashbinSize === false || $trashbinSize < 0 ) {\r
$trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin'));
$trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin'));\r
}
$quota = \OCP\Util::computerFileSize(\OC_Appconfig::getValue('files', 'default_quota'));\r
}\r
if ( $quota == null ) {\r
- $quota = \OC\Files\Filesystem::free_space('/');\r
+ $quota = \OC\Files\Filesystem::free_space('/') / count(\OCP\User::getUsers());\r
}
// calculate available space for trash bin\r
}
$trashbinSize -= self::expire($availableSpace);
- \OCP\Config::setAppValue('files_trashbin', 'size', $trashbinSize);\r
+
+ self::setTrashbinSize($user, $trashbinSize);\r
}
$user = \OCP\User::getUser();
$view = new \OC_FilesystemView('/'.$user);
- if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) {\r
+ $trashbinSize = self::getTrashbinSize($user);
+ if ( $trashbinSize === false || $trashbinSize < 0 ) {\r
$trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin'));\r
$trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin'));\r
}
$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);
$view = new \OC_FilesystemView('/'.$user);
$size = 0;\r
- if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) {\r
+ $trashbinSize = self::getTrashbinSize($user);
+ if ( $trashbinSize === false || $trashbinSize < 0 ) {\r
$trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin'));\r
$trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin'));\r
}
}
$view->unlink('/files_trashbin/'.$file);
$trashbinSize -= $size;
- \OCP\Config::setAppValue('files_trashbin', 'size', $trashbinSize);
+ self::setTrashbinSize($user, $trashbinSize);
\r
return $size;\r
}
}\r
return $size;\r
}
+
+ /**\r
+ * get current size of trash bin from a given user\r
+ *\r
+ * @param $user user who owns the trash bin\r
+ * @return mixed trash bin size or false if no trash bin size is stored\r
+ */\r
+ private static function getTrashbinSize($user) {\r
+ $query = \OC_DB::prepare('SELECT size FROM *PREFIX*files_trashsize WHERE user=?');\r
+ $result = $query->execute(array($user))->fetchAll();\r
+\r
+ if ($result) {\r
+ return $result[0]['size'];\r
+ }\r
+ return false;\r
+ }\r
+ \r
+ /**\r
+ * write to the database how much space is in use for the trash bin\r
+ *\r
+ * @param $user owner of the trash bin\r
+ * @param $size size of the trash bin\r
+ */\r
+ private static function setTrashbinSize($user, $size) {\r
+ if ( self::getTrashbinSize($user) === false) {\r
+ $query = \OC_DB::prepare('INSERT INTO *PREFIX*files_trashsize (size, user) VALUES (?, ?)');\r
+ }else {\r
+ $query = \OC_DB::prepare('UPDATE *PREFIX*files_trashsize SET size=? WHERE user=?');\r
+ }\r
+ $query->execute(array($size, $user));\r
+ }
}\r