summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2013-01-18 15:12:38 +0100
committerBjörn Schießle <schiessle@owncloud.com>2013-01-18 15:12:38 +0100
commit8fdcd72d7f5fa9a0f2f84c63a1bc91211265cb19 (patch)
treeb257b703a42df318dcdc852b046ed3368bdaeb15
parentca14af2fdd2d0160315f252b151970d78ec77ab6 (diff)
downloadnextcloud-server-8fdcd72d7f5fa9a0f2f84c63a1bc91211265cb19.tar.gz
nextcloud-server-8fdcd72d7f5fa9a0f2f84c63a1bc91211265cb19.zip
expire files in trash bin after 30 days
-rw-r--r--apps/files_trashbin/lib/trash.php32
1 files changed, 29 insertions, 3 deletions
diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php
index 322f5679b7d..1b0b9cef4bd 100644
--- a/apps/files_trashbin/lib/trash.php
+++ b/apps/files_trashbin/lib/trash.php
@@ -23,6 +23,8 @@
namespace OCA_Trash;
class Trashbin {
+
+ const DELETEAFTER=30; // how long do we keep files in the trash bin (number of days)
/**
* move file to the trash bin
@@ -124,9 +126,33 @@ class Trashbin {
/**
* clean up the trash bin
*/
- private static function expire() {
- //TODO: implement expire function
- return true;
+ private static function expire() {
+
+ $view = new \OC_FilesystemView('/'.\OCP\User::getUser());
+ $user = \OCP\User::getUser();
+
+ $query = \OC_DB::prepare('SELECT location,type,id,timestamp FROM *PREFIX*files_trash WHERE user=?');
+ $result = $query->execute(array($user))->fetchAll();
+
+ $limit = time() - (self::DELETEAFTER * 86400);
+
+ foreach ( $result as $r ) {
+ $timestamp = $r['timestamp'];
+ $filename = $r['id'];
+ if ( $r['timestamp'] < $limit ) {
+ $view->unlink('files_trashbin/'.$filename.'.d'.$timestamp);
+ if ($r['type'] == 'dir') {
+ $view->unlink('versions_trashbin/'.$filename.'.d'.$timestamp);
+ } else if ( $versions = self::getVersionsFromTrash($filename, $timestamp) ) {
+ foreach ($versions as $v) {
+ $view->unlink('versions_trashbin/'.$filename.'.v'.$v.'.d'.$timestamp);
+ }
+ }
+ }
+ }
+
+ $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND timestamp<?');
+ $query->execute(array($user,$limit));
}
/**