diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index 8d54a471b4..2b8b32c3a1 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -23,9 +23,11 @@ namespace OCA\Files_Trashbin; 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 @@ -60,7 +62,8 @@ class Trashbin { $trashbinSize += self::copy_recursive($file_path, 'files_trashbin/'.$deleted.'.d'.$timestamp, $view); if ( $view->file_exists('files_trashbin/'.$deleted.'.d'.$timestamp) ) { - $query = \OC_DB::prepare("INSERT INTO *PREFIX*files_trash (id,timestamp,location,type,mime,user) VALUES (?,?,?,?,?,?)"); + $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); @@ -70,12 +73,15 @@ class Trashbin { if ( \OCP\App::isEnabled('files_versions') ) { if ( $view->is_dir('files_versions'.$file_path) ) { - $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_versions/'.$file_path)); + $trashbinSize += self::calculateSize( + new \OC_FilesystemView('/'. $user.'/files_versions/'.$file_path) + ); $view->rename('files_versions'.$file_path, 'versions_trashbin/'. $deleted.'.d'.$timestamp); } else if ( $versions = \OCA\Files_Versions\Storage::getVersions($file_path) ) { foreach ($versions as $v) { $trashbinSize += $view->filesize('files_versions'.$v['path'].'.v'.$v['version']); - $view->rename('files_versions'.$v['path'].'.v'.$v['version'], 'versions_trashbin/'. $deleted.'.v'.$v['version'].'.d'.$timestamp); + $view->rename('files_versions'.$v['path'].'.v'.$v['version'], + 'versions_trashbin/'. $deleted.'.v'.$v['version'].'.d'.$timestamp); } } } @@ -121,7 +127,8 @@ class Trashbin { $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin')); } if ( $timestamp ) { - $query = \OC_DB::prepare('SELECT location,type FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?'); + $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); @@ -131,7 +138,7 @@ class Trashbin { // if location no longer exists, restore file in the root directory $location = $result[0]['location']; if ( $result[0]['location'] != '/' && - (!$view->is_dir('files'.$result[0]['location']) || + (!$view->is_dir('files'.$result[0]['location']) || !$view->isUpdatable('files'.$result[0]['location'])) ) { $location = ''; } @@ -165,16 +172,21 @@ class Trashbin { $versionedFile = $file; } if ( $result[0]['type'] == 'dir' ) { - $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)); + $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) ) { 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); } } } @@ -280,7 +292,8 @@ class Trashbin { $query = \OC_DB::prepare('SELECT location,type,id,timestamp FROM *PREFIX*files_trash WHERE user=?'); $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); @@ -289,13 +302,17 @@ class Trashbin { $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) { @@ -312,7 +329,8 @@ class Trashbin { $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'); + $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; @@ -418,7 +436,8 @@ class Trashbin { if (!file_exists($root)) { return 0; } - $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($root), \RecursiveIteratorIterator::CHILD_FIRST); + $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($root), + \RecursiveIteratorIterator::CHILD_FIRST); $size = 0; foreach ($iterator as $path) {