expire files in trash bin after 30 days

This commit is contained in:
Björn Schießle 2013-01-18 15:12:38 +01:00
parent 8e57fe1a08
commit 655a20f963
1 changed files with 29 additions and 3 deletions

View File

@ -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));
}
/**