namespace OCA\Files_Trashbin;\r
\r
class Trashbin {
-
- const DEFAULT_RETENTION_OBLIGATION=180; // how long do we keep files in the trash bin if no other value is defined in the config file (unit: days)
- const DEFAULTMAXSIZE=50; // unit: percentage; 50% of available disk space/quota
+ // 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=180;
+
+ // unit: percentage; 50% of available disk space/quota
+ const DEFAULTMAXSIZE=50;
/**
* move file to the trash bin
$trashbinSize += self::copy_recursive($file_path, 'files_trashbin/'.$deleted.'.d'.$timestamp, $view);
if ( $view->file_exists('files_trashbin/'.$deleted.'.d'.$timestamp) ) {\r
- $query = \OC_DB::prepare("INSERT INTO *PREFIX*files_trash (id,timestamp,location,type,mime,user) VALUES (?,?,?,?,?,?)");\r
+ $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/'.$deleted.'.d'.$timestamp);
\r
if ( \OCP\App::isEnabled('files_versions') ) {\r
if ( $view->is_dir('files_versions'.$file_path) ) {
- $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_versions/'.$file_path));\r
+ $trashbinSize += self::calculateSize(
+ new \OC_FilesystemView('/'. $user.'/files_versions/'.$file_path)
+ );
$view->rename('files_versions'.$file_path, 'versions_trashbin/'. $deleted.'.d'.$timestamp);\r
} else if ( $versions = \OCA\Files_Versions\Storage::getVersions($file_path) ) {\r
foreach ($versions as $v) {
$trashbinSize += $view->filesize('files_versions'.$v['path'].'.v'.$v['version']);\r
- $view->rename('files_versions'.$v['path'].'.v'.$v['version'], 'versions_trashbin/'. $deleted.'.v'.$v['version'].'.d'.$timestamp);\r
+ $view->rename('files_versions'.$v['path'].'.v'.$v['version'],
+ 'versions_trashbin/'. $deleted.'.v'.$v['version'].'.d'.$timestamp);
}\r
}\r
}
$trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin'));\r
}
if ( $timestamp ) {
- $query = \OC_DB::prepare('SELECT location,type FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?');\r
+ $query = \OC_DB::prepare('SELECT location,type FROM *PREFIX*files_trash'
+ .' WHERE user=? AND id=? AND timestamp=?');
$result = $query->execute(array($user,$filename,$timestamp))->fetchAll();
if ( count($result) != 1 ) {
\OC_Log::write('files_trashbin', 'trash bin database inconsistent!', \OC_Log::ERROR);
// if location no longer exists, restore file in the root directory\r
$location = $result[0]['location'];\r
if ( $result[0]['location'] != '/' &&
- (!$view->is_dir('files'.$result[0]['location']) ||
+ (!$view->is_dir('files'.$result[0]['location']) ||
!$view->isUpdatable('files'.$result[0]['location'])) ) {\r
$location = '';\r
}
$versionedFile = $file;
}\r
if ( $result[0]['type'] == 'dir' ) {
- $trashbinSize -= self::calculateSize(new \OC_FilesystemView('/'.$user.'/'.'versions_trashbin/'. $file));\r
- $view->rename(\OC_Filesystem::normalizePath('versions_trashbin/'. $file), \OC_Filesystem::normalizePath('files_versions/'.$location.'/'.$filename.$ext));\r
+ $trashbinSize -= self::calculateSize(
+ new \OC_FilesystemView('/'.$user.'/'.'versions_trashbin/'. $file)
+ );
+ $view->rename(\OC_Filesystem::normalizePath('versions_trashbin/'. $file),
+ \OC_Filesystem::normalizePath('files_versions/'.$location.'/'.$filename.$ext));
} else if ( $versions = self::getVersionsFromTrash($versionedFile, $timestamp) ) {\r
foreach ($versions as $v) {
if ($timestamp ) {
$trashbinSize -= $view->filesize('versions_trashbin/'.$versionedFile.'.v'.$v.'.d'.$timestamp);
- $view->rename('versions_trashbin/'.$versionedFile.'.v'.$v.'.d'.$timestamp, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v);
+ $view->rename('versions_trashbin/'.$versionedFile.'.v'.$v.'.d'.$timestamp,
+ 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v);
} else {
$trashbinSize -= $view->filesize('versions_trashbin/'.$versionedFile.'.v'.$v);
- $view->rename('versions_trashbin/'.$versionedFile.'.v'.$v, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v);
+ $view->rename('versions_trashbin/'.$versionedFile.'.v'.$v,
+ 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v);
}\r
}\r
}\r
$query = \OC_DB::prepare('SELECT location,type,id,timestamp FROM *PREFIX*files_trash WHERE user=?');\r
$result = $query->execute(array($user))->fetchAll();
- $retention_obligation = \OC_Config::getValue('trashbin_retention_obligation', self::DEFAULT_RETENTION_OBLIGATION);
+ $retention_obligation = \OC_Config::getValue('trashbin_retention_obligation',
+ self::DEFAULT_RETENTION_OBLIGATION);
$limit = time() - ($retention_obligation * 86400);
$filename = $r['id'];
if ( $r['timestamp'] < $limit ) {
if ($view->is_dir('files_trashbin/'.$filename.'.d'.$timestamp)) {
- $size += self::calculateSize(new \OC_FilesystemView('/'.$user.'/files_trashbin/'.$filename.'.d'.$timestamp));
+ $size += self::calculateSize(
+ new \OC_FilesystemView('/'.$user.'/files_trashbin/'.$filename.'.d'.$timestamp)
+ );
} else {
$size += $view->filesize('files_trashbin/'.$filename.'.d'.$timestamp);
}
$view->unlink('files_trashbin/'.$filename.'.d'.$timestamp);
if ($r['type'] == 'dir') {
- $size += self::calculateSize(new \OC_FilesystemView('/'.$user.'/versions_trashbin/'.$filename.'.d'.$timestamp));
+ $size += self::calculateSize(
+ new \OC_FilesystemView('/'.$user.'/versions_trashbin/'.$filename.'.d'.$timestamp)
+ );
$view->unlink('versions_trashbin/'.$filename.'.d'.$timestamp);
} else if ( $versions = self::getVersionsFromTrash($filename, $timestamp) ) {
foreach ($versions as $v) {
$availableSpace = $availableSpace + $size;
// if size limit for trash bin reached, delete oldest files in trash bin
if ($availableSpace < 0) {
- $query = \OC_DB::prepare('SELECT location,type,id,timestamp FROM *PREFIX*files_trash WHERE user=? ORDER BY timestamp ASC');\r
+ $query = \OC_DB::prepare('SELECT location,type,id,timestamp FROM *PREFIX*files_trash'
+ .' WHERE user=? ORDER BY timestamp ASC');
$result = $query->execute(array($user))->fetchAll();
$length = count($result);
$i = 0;
if (!file_exists($root)) {
return 0;
}
- $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($root), \RecursiveIteratorIterator::CHILD_FIRST);\r
+ $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($root),
+ \RecursiveIteratorIterator::CHILD_FIRST);\r
$size = 0;\r
\r
foreach ($iterator as $path) {