diff options
author | Victor Dubiniuk <victor.dubiniuk@gmail.com> | 2015-07-30 22:31:18 +0300 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-08-10 20:40:43 +0200 |
commit | 4ef26157880f5cd5d5bd27abe0a6991d7c8a415a (patch) | |
tree | b5ca833cb5f26b4097ff0653f70be284a328f618 /apps/files_trashbin/lib/trashbin.php | |
parent | c2856c05aa9cbdc3adddea127a8588183647ee0a (diff) | |
download | nextcloud-server-4ef26157880f5cd5d5bd27abe0a6991d7c8a415a.tar.gz nextcloud-server-4ef26157880f5cd5d5bd27abe0a6991d7c8a415a.zip |
Enhance trashbin expiration settings
Diffstat (limited to 'apps/files_trashbin/lib/trashbin.php')
-rw-r--r-- | apps/files_trashbin/lib/trashbin.php | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index 8b666c56c66..2719eece2a8 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -38,12 +38,10 @@ namespace OCA\Files_Trashbin; use OC\Files\Filesystem; use OC\Files\View; +use OCA\Files_Trashbin\AppInfo\Application; use OCA\Files_Trashbin\Command\Expire; class Trashbin { - // how long do we keep files in the trash bin if no other value is defined in the config file (unit: days) - - const DEFAULT_RETENTION_OBLIGATION = 30; // unit: percentage; 50% of available disk space/quota const DEFAULTMAXSIZE = 50; @@ -631,14 +629,10 @@ class Trashbin { $availableSpace = self::calculateFreeSpace($trashBinSize, $user); $size = 0; - $retention_obligation = \OC_Config::getValue('trashbin_retention_obligation', self::DEFAULT_RETENTION_OBLIGATION); - - $limit = time() - ($retention_obligation * 86400); - $dirContent = Helper::getTrashFiles('/', $user, 'mtime'); // delete all files older then $retention_obligation - list($delSize, $count) = self::deleteExpiredFiles($dirContent, $user, $limit, $retention_obligation); + list($delSize, $count) = self::deleteExpiredFiles($dirContent, $user); $size += $delSize; $availableSpace += $size; @@ -652,11 +646,11 @@ class Trashbin { */ private static function scheduleExpire($trashBinSize, $user) { // let the admin disable auto expire - $autoExpire = \OC_Config::getValue('trashbin_auto_expire', true); - if ($autoExpire === false) { - return; + $application = new Application(); + $expiration = $application->getContainer()->query('Expiration'); + if ($expiration->isEnabled()) { + \OC::$server->getCommandBus()->push(new Expire($user, $trashBinSize)); } - \OC::$server->getCommandBus()->push(new Expire($user, $trashBinSize)); } /** @@ -669,11 +663,13 @@ class Trashbin { * @return int size of deleted files */ protected static function deleteFiles($files, $user, $availableSpace) { + $application = new Application(); + $expiration = $application->getContainer()->query('Expiration'); $size = 0; if ($availableSpace < 0) { foreach ($files as $file) { - if ($availableSpace < 0) { + if ($availableSpace < 0 && $expiration->isExpired($file['mtime'], true)) { $tmp = self::delete($file['name'], $user, $file['mtime']); \OCP\Util::writeLog('files_trashbin', 'remove "' . $file['name'] . '" (' . $tmp . 'B) to meet the limit of trash bin size (50% of available quota)', \OCP\Util::INFO); $availableSpace += $tmp; @@ -691,20 +687,19 @@ class Trashbin { * * @param array $files list of files sorted by mtime * @param string $user - * @param int $limit files older then limit should be deleted - * @param int $retention_obligation max age of file in days * @return array size of deleted files and number of deleted files */ - protected static function deleteExpiredFiles($files, $user, $limit, $retention_obligation) { + protected static function deleteExpiredFiles($files, $user) { + $application = new Application(); + $expiration = $application->getContainer()->query('Expiration'); $size = 0; $count = 0; foreach ($files as $file) { $timestamp = $file['mtime']; $filename = $file['name']; - if ($timestamp <= $limit) { + if ($expiration->isExpired($timestamp)) { $count++; $size += self::delete($filename, $user, $timestamp); - \OCP\Util::writeLog('files_trashbin', 'remove "' . $filename . '" from trash bin because it is older than ' . $retention_obligation, \OCP\Util::INFO); } else { break; } |