]> source.dussan.org Git - nextcloud-server.git/commitdiff
Style cleanup files_trashbin
authorBart Visscher <bartv@thisnet.nl>
Thu, 14 Feb 2013 21:46:28 +0000 (22:46 +0100)
committerBart Visscher <bartv@thisnet.nl>
Thu, 21 Feb 2013 22:47:21 +0000 (23:47 +0100)
apps/files_trashbin/lib/trash.php

index 8d54a471b422ab719fa317a59cef6365d6e9bd68..2b8b32c3a16154c9db5610b718499e55e281e6c1 100644 (file)
 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
@@ -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) ) {\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);
@@ -70,12 +73,15 @@ class Trashbin {
        \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
                        }
@@ -121,7 +127,8 @@ class Trashbin {
                        $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);
@@ -131,7 +138,7 @@ class Trashbin {
                        // 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
                        }
@@ -165,16 +172,21 @@ class Trashbin {
                                        $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
@@ -280,7 +292,8 @@ class Trashbin {
                $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);
 
@@ -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');\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;
@@ -418,7 +436,8 @@ class Trashbin {
                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) {