diff options
author | Bart Visscher <bartv@thisnet.nl> | 2013-02-22 17:21:57 +0100 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2013-02-22 19:05:36 +0100 |
commit | bb75dfc021a68bcd9526ef40f78bca4910798345 (patch) | |
tree | 30185c8198f4da87f180214bf1f2076ec48f3777 /apps/files_trashbin | |
parent | 78fce834058a38a7dbcc5310e16095c743434bc6 (diff) | |
download | nextcloud-server-bb75dfc021a68bcd9526ef40f78bca4910798345.tar.gz nextcloud-server-bb75dfc021a68bcd9526ef40f78bca4910798345.zip |
Whitespace fixes
Diffstat (limited to 'apps/files_trashbin')
-rw-r--r-- | apps/files_trashbin/ajax/delete.php | 2 | ||||
-rw-r--r-- | apps/files_trashbin/ajax/undelete.php | 4 | ||||
-rw-r--r-- | apps/files_trashbin/appinfo/app.php | 6 | ||||
-rw-r--r-- | apps/files_trashbin/index.php | 28 | ||||
-rw-r--r-- | apps/files_trashbin/js/disableDefaultActions.js | 6 | ||||
-rw-r--r-- | apps/files_trashbin/js/trash.js | 24 | ||||
-rw-r--r-- | apps/files_trashbin/lib/hooks.php | 40 | ||||
-rw-r--r-- | apps/files_trashbin/lib/trash.php | 322 | ||||
-rw-r--r-- | apps/files_trashbin/templates/part.list.php | 1 |
9 files changed, 216 insertions, 217 deletions
diff --git a/apps/files_trashbin/ajax/delete.php b/apps/files_trashbin/ajax/delete.php index 34f35c39ccb..1834fb54003 100644 --- a/apps/files_trashbin/ajax/delete.php +++ b/apps/files_trashbin/ajax/delete.php @@ -20,7 +20,7 @@ foreach ($list as $file) { $filename = $file; $timestamp = null; } - + OCA\Files_Trashbin\Trashbin::delete($filename, $timestamp); if (!OCA\Files_Trashbin\Trashbin::file_exists($filename, $timestamp)) { $success[$i]['filename'] = $file; diff --git a/apps/files_trashbin/ajax/undelete.php b/apps/files_trashbin/ajax/undelete.php index 93f2aaf1fa2..80de3c31f91 100644 --- a/apps/files_trashbin/ajax/undelete.php +++ b/apps/files_trashbin/ajax/undelete.php @@ -1,4 +1,4 @@ -<?php +<?php OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); @@ -21,7 +21,7 @@ foreach ($list as $file) { $filename = $path_parts['basename']; $timestamp = null; } - + if ( !OCA\Files_Trashbin\Trashbin::restore($file, $filename, $timestamp) ) { $error[] = $filename; } else { diff --git a/apps/files_trashbin/appinfo/app.php b/apps/files_trashbin/appinfo/app.php index b1a15cd13d1..7c04e583db1 100644 --- a/apps/files_trashbin/appinfo/app.php +++ b/apps/files_trashbin/appinfo/app.php @@ -1,7 +1,7 @@ <?php -OC::$CLASSPATH['OCA\Files_Trashbin\Hooks'] = 'apps/files_trashbin/lib/hooks.php';
-OC::$CLASSPATH['OCA\Files_Trashbin\Trashbin'] = 'apps/files_trashbin/lib/trash.php';
+OC::$CLASSPATH['OCA\Files_Trashbin\Hooks'] = 'apps/files_trashbin/lib/hooks.php'; +OC::$CLASSPATH['OCA\Files_Trashbin\Trashbin'] = 'apps/files_trashbin/lib/trash.php'; + -
OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA\Files_Trashbin\Hooks", "remove_hook"); diff --git a/apps/files_trashbin/index.php b/apps/files_trashbin/index.php index d0b3030dbf8..4615df3586f 100644 --- a/apps/files_trashbin/index.php +++ b/apps/files_trashbin/index.php @@ -1,6 +1,6 @@ <?php -// Check if we are a user
+// Check if we are a user OCP\User::checkLoggedIn(); OCP\Util::addScript('files_trashbin', 'trash'); @@ -19,7 +19,7 @@ $dir = isset($_GET['dir']) ? stripslashes($_GET['dir']) : ''; $result = array(); if ($dir) { $dirlisting = true; - $view = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files_trashbin');
+ $view = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files_trashbin'); $fullpath = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath($dir); $dirContent = opendir($fullpath); $i = 0; @@ -36,10 +36,10 @@ if ($dir) { 'type' => $view->is_dir($dir.'/'.$entryName) ? 'dir' : 'file', 'location' => $dir, ); - }
+ } } closedir($dirContent); - + } else { $dirlisting = false; $query = \OC_DB::prepare('SELECT id,location,timestamp,type,mime FROM *PREFIX*files_trash WHERE user=?'); @@ -67,28 +67,28 @@ foreach ($result as $r) { $files[] = $i; } -// Make breadcrumb
+// Make breadcrumb $pathtohere = ''; -$breadcrumb = array();
-foreach (explode('/', $dir) as $i) {
+$breadcrumb = array(); +foreach (explode('/', $dir) as $i) { if ($i != '') { if ( preg_match('/^(.+)\.d[0-9]+$/', $i, $match) ) { $name = $match[1]; } else { $name = $i; - }
- $pathtohere .= '/' . $i;
- $breadcrumb[] = array('dir' => $pathtohere, 'name' => $name);
- }
+ } + $pathtohere .= '/' . $i; + $breadcrumb[] = array('dir' => $pathtohere, 'name' => $name); + } } -$breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
-$breadcrumbNav->assign('breadcrumb', $breadcrumb, false);
+$breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', ''); +$breadcrumbNav->assign('breadcrumb', $breadcrumb, false); $breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php') . '?dir=', false); $list = new OCP\Template('files_trashbin', 'part.list', ''); $list->assign('files', $files, false); -$list->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php'). '?dir='.$dir, false);
+$list->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php'). '?dir='.$dir, false); $list->assign('downloadURL', OCP\Util::linkTo('files_trashbin', 'download.php') . '?file='.$dir, false); $list->assign('disableSharing', true); $list->assign('dirlisting', $dirlisting); diff --git a/apps/files_trashbin/js/disableDefaultActions.js b/apps/files_trashbin/js/disableDefaultActions.js index 27c3e13db4d..df08bfb1a50 100644 --- a/apps/files_trashbin/js/disableDefaultActions.js +++ b/apps/files_trashbin/js/disableDefaultActions.js @@ -1,4 +1,4 @@ -/* disable download and sharing actions */
-var disableDownloadActions = true;
-var disableSharing = true;
+/* disable download and sharing actions */ +var disableDownloadActions = true; +var disableSharing = true; var trashBinApp = true;
\ No newline at end of file diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 208cc88f0fd..7769def535e 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -19,22 +19,22 @@ $(document).ready(function() { OC.dialogs.alert(result.data.message, 'Error'); } }); - + }); }; - + FileActions.register('all', 'Delete', OC.PERMISSION_READ, function () { return OC.imagePath('core', 'actions/delete'); }, function (filename) { $('.tipsy').remove(); - + var tr=$('tr').filterAttr('data-file', filename); var deleteAction = $('tr').filterAttr('data-file',filename).children("td.date").children(".action.delete"); var oldHTML = deleteAction[0].outerHTML; var newHTML = '<img class="move2trash" data-action="Delete" title="'+t('files', 'delete file permanently')+'" src="'+ OC.imagePath('core', 'loading.gif') +'"></a>'; var files = tr.attr('data-file'); deleteAction[0].outerHTML = newHTML; - + $.post(OC.filePath('files_trashbin','ajax','delete.php'), {files:JSON.stringify([files]), dirlisting:tr.attr('data-dirlisting') }, function(result){ @@ -46,9 +46,9 @@ $(document).ready(function() { OC.dialogs.alert(result.data.message, 'Error'); } }); - + }); - + // Sets the select_all checkbox behaviour : $('#select_all').click(function() { if($(this).attr('checked')){ @@ -91,18 +91,18 @@ $(document).ready(function() { } processSelection(); }); - + $('.undelete').click('click',function(event) { var spinner = '<img class="move2trash" title="'+t('files_trashbin', 'perform restore operation')+'" src="'+ OC.imagePath('core', 'loader.gif') +'"></a>'; var files=getSelectedFiles('file'); var fileslist = JSON.stringify(files); var dirlisting=getSelectedFiles('dirlisting')[0]; - + for (var i=0; i<files.length; i++) { var undeleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date"); undeleteAction[0].innerHTML = undeleteAction[0].innerHTML+spinner; } - + $.post(OC.filePath('files_trashbin','ajax','undelete.php'), {files:fileslist, dirlisting:dirlisting}, function(result){ @@ -115,19 +115,19 @@ $(document).ready(function() { } }); }); - + $('.delete').click('click',function(event) { console.log("delete selected"); var spinner = '<img class="move2trash" title="'+t('files_trashbin', 'Delete permanently')+'" src="'+ OC.imagePath('core', 'loading.gif') +'"></a>'; var files=getSelectedFiles('file'); var fileslist = JSON.stringify(files); var dirlisting=getSelectedFiles('dirlisting')[0]; - + for (var i=0; i<files.length; i++) { var deleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date"); deleteAction[0].innerHTML = deleteAction[0].innerHTML+spinner; } - + $.post(OC.filePath('files_trashbin','ajax','delete.php'), {files:fileslist, dirlisting:dirlisting}, function(result){ diff --git a/apps/files_trashbin/lib/hooks.php b/apps/files_trashbin/lib/hooks.php index d6a62d447b8..9081706a2c5 100644 --- a/apps/files_trashbin/lib/hooks.php +++ b/apps/files_trashbin/lib/hooks.php @@ -1,23 +1,23 @@ <?php -/**
- * ownCloud - trash bin
- *
- * @author Bjoern Schiessle
- * @copyright 2013 Bjoern Schiessle schiessle@owncloud.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
+/** + * ownCloud - trash bin + * + * @author Bjoern Schiessle + * @copyright 2013 Bjoern Schiessle schiessle@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * */ /** @@ -36,7 +36,7 @@ class Hooks { * to copy the file to the trash bin */ public static function remove_hook($params) { - + if ( \OCP\App::isEnabled('files_trashbin') ) { $path = $params['path']; Trashbin::move2trash($path); diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index 2b8b32c3a16..8355c7252b0 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -1,67 +1,67 @@ <?php -/**
- * ownCloud - trash bin
- *
- * @author Bjoern Schiessle
- * @copyright 2013 Bjoern Schiessle schiessle@owncloud.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- */
- -namespace OCA\Files_Trashbin;
-
+/** + * ownCloud - trash bin + * + * @author Bjoern Schiessle + * @copyright 2013 Bjoern Schiessle schiessle@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Files_Trashbin; + class Trashbin { // 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 - * + * * @param $file_path path to the deleted file/directory relative to the files root directory */ public static function move2trash($file_path) { $user = \OCP\User::getUser(); - $view = new \OC_FilesystemView('/'. $user);
- if (!$view->is_dir('files_trashbin')) {
- $view->mkdir('files_trashbin');
- $view->mkdir("versions_trashbin");
- }
-
- $path_parts = pathinfo($file_path);
-
- $deleted = $path_parts['basename'];
- $location = $path_parts['dirname'];
- $timestamp = time();
- $mime = $view->getMimeType('files'.$file_path);
-
- if ( $view->is_dir('files'.$file_path) ) {
- $type = 'dir';
- } else {
- $type = 'file';
+ $view = new \OC_FilesystemView('/'. $user); + if (!$view->is_dir('files_trashbin')) { + $view->mkdir('files_trashbin'); + $view->mkdir("versions_trashbin"); } -
- if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) {
+ + $path_parts = pathinfo($file_path); + + $deleted = $path_parts['basename']; + $location = $path_parts['dirname']; + $timestamp = time(); + $mime = $view->getMimeType('files'.$file_path); + + if ( $view->is_dir('files'.$file_path) ) { + $type = 'dir'; + } else { + $type = 'file'; + } + + if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) { $trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin')); - $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin'));
+ $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin')); } $trashbinSize += self::copy_recursive($file_path, 'files_trashbin/'.$deleted.'.d'.$timestamp, $view); - if ( $view->file_exists('files_trashbin/'.$deleted.'.d'.$timestamp) ) {
+ 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 (?,?,?,?,?,?)"); $result = $query->execute(array($deleted, $timestamp, $location, $type, $mime, $user)); @@ -69,49 +69,49 @@ class Trashbin { $view->deleteAll('files_trashbin/'.$deleted.'.d'.$timestamp); \OC_Log::write('files_trashbin', 'trash bin database couldn\'t be updated', \OC_log::ERROR); return; - }
-
- if ( \OCP\App::isEnabled('files_versions') ) {
+ } + + 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) ); - $view->rename('files_versions'.$file_path, 'versions_trashbin/'. $deleted.'.d'.$timestamp);
- } else if ( $versions = \OCA\Files_Versions\Storage::getVersions($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']);
+ $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); - }
- }
+ } + } } } else { \OC_Log::write('files_trashbin', 'Couldn\'t move '.$file_path.' to the trash bin', \OC_log::ERROR); } - - // get available disk space for user
- $quota = \OCP\Util::computerFileSize(\OC_Preferences::getValue($user, 'files', 'quota'));
- if ( $quota == null ) {
- $quota = \OCP\Util::computerFileSize(\OC_Appconfig::getValue('files', 'default_quota'));
- }
- if ( $quota == null ) {
- $quota = \OC\Files\Filesystem::free_space('/');
+ + // get available disk space for user + $quota = \OCP\Util::computerFileSize(\OC_Preferences::getValue($user, 'files', 'quota')); + if ( $quota == null ) { + $quota = \OCP\Util::computerFileSize(\OC_Appconfig::getValue('files', 'default_quota')); + } + if ( $quota == null ) { + $quota = \OC\Files\Filesystem::free_space('/'); } - - // calculate available space for trash bin
- $rootInfo = $view->getFileInfo('/files');
- $free = $quota-$rootInfo['size']; // remaining free space for user
- if ( $free > 0 ) {
- $availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - $trashbinSize; // how much space can be used for versions
- } else {
- $availableSpace = $free-$trashbinSize;
+ + // calculate available space for trash bin + $rootInfo = $view->getFileInfo('/files'); + $free = $quota-$rootInfo['size']; // remaining free space for user + if ( $free > 0 ) { + $availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - $trashbinSize; // how much space can be used for versions + } else { + $availableSpace = $free-$trashbinSize; } - + $trashbinSize -= self::expire($availableSpace); - \OCP\Config::setAppValue('files_trashbin', 'size', $trashbinSize);
+ \OCP\Config::setAppValue('files_trashbin', 'size', $trashbinSize); } - - + + /** * restore files from trash bin * @param $file path to the deleted file @@ -121,10 +121,10 @@ class Trashbin { public static function restore($file, $filename, $timestamp) { $user = \OCP\User::getUser(); $view = new \OC_FilesystemView('/'.$user); - - if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) {
- $trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin'));
- $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin'));
+ + if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) { + $trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin')); + $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin')); } if ( $timestamp ) { $query = \OC_DB::prepare('SELECT location,type FROM *PREFIX*files_trash' @@ -134,13 +134,13 @@ class Trashbin { \OC_Log::write('files_trashbin', 'trash bin database inconsistent!', \OC_Log::ERROR); return false; } - - // if location no longer exists, restore file in the root directory
- $location = $result[0]['location'];
- if ( $result[0]['location'] != '/' && + + // 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->isUpdatable('files'.$result[0]['location'])) ) {
- $location = '';
+ !$view->isUpdatable('files'.$result[0]['location'])) ) { + $location = ''; } } else { $path_parts = pathinfo($filename); @@ -150,10 +150,10 @@ class Trashbin { ); $location = ''; } - + $source = \OC_Filesystem::normalizePath('files_trashbin/'.$file); $target = \OC_Filesystem::normalizePath('files/'.$location.'/'.$filename); - + // we need a extension in case a file/dir with the same name already exists $ext = self::getUniqueExtension($location, $filename, $view); $mtime = $view->filemtime($source); @@ -170,14 +170,14 @@ class Trashbin { $versionedFile = $filename; } else { $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)); - } else if ( $versions = self::getVersionsFromTrash($versionedFile, $timestamp) ) {
+ } else if ( $versions = self::getVersionsFromTrash($versionedFile, $timestamp) ) { foreach ($versions as $v) { if ($timestamp ) { $trashbinSize -= $view->filesize('versions_trashbin/'.$versionedFile.'.v'.$v.'.d'.$timestamp); @@ -187,13 +187,13 @@ class Trashbin { $trashbinSize -= $view->filesize('versions_trashbin/'.$versionedFile.'.v'.$v); $view->rename('versions_trashbin/'.$versionedFile.'.v'.$v, 'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v); - }
- }
- }
+ } + } + } } if ( $timestamp ) { - $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?');
+ $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?'); $query->execute(array($user,$filename,$timestamp)); } @@ -205,31 +205,31 @@ class Trashbin { return false; } - - /**
- * delete file from trash bin permanently
+ + /** + * delete file from trash bin permanently * @param $filename path to the file - * @param $timestamp of deletion time
- * @return size of deleted files
- */
- public static function delete($filename, $timestamp=null) {
- $user = \OCP\User::getUser();
+ * @param $timestamp of deletion time + * @return size of deleted files + */ + public static function delete($filename, $timestamp=null) { + $user = \OCP\User::getUser(); $view = new \OC_FilesystemView('/'.$user); - $size = 0;
- - if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) {
- $trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin'));
- $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin'));
+ $size = 0; + + if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) { + $trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin')); + $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin')); } -
- if ( $timestamp ) {
- $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?');
- $query->execute(array($user,$filename,$timestamp));
+ + if ( $timestamp ) { + $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?'); + $query->execute(array($user,$filename,$timestamp)); $file = $filename.'.d'.$timestamp; } else { $file = $filename; } - + if ( \OCP\App::isEnabled('files_versions') ) { if ($view->is_dir('versions_trashbin/'.$file)) { $size += self::calculateSize(new \OC_Filesystemview('/'.$user.'/versions_trashbin/'.$file)); @@ -245,8 +245,8 @@ class Trashbin { } } } - }
- + } + if ($view->is_dir('/files_trashbin/'.$file)) { $size += self::calculateSize(new \OC_Filesystemview('/'.$user.'/files_trashbin/'.$file)); } else { @@ -255,8 +255,8 @@ class Trashbin { $view->unlink('/files_trashbin/'.$file); $trashbinSize -= $size; \OCP\Config::setAppValue('files_trashbin', 'size', $trashbinSize); -
- return $size;
+ + return $size; } /** @@ -279,22 +279,22 @@ class Trashbin { return $view->file_exists($target); } - /**
+ /** * clean up the trash bin - * @param max. available disk space for trashbin
- */
+ * @param max. available disk space for trashbin + */ private static function expire($availableSpace) { - + $user = \OCP\User::getUser(); $view = new \OC_FilesystemView('/'.$user); $size = 0; - - $query = \OC_DB::prepare('SELECT location,type,id,timestamp FROM *PREFIX*files_trash WHERE user=?');
+ + $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); - + $limit = time() - ($retention_obligation * 86400); foreach ( $result as $r ) { @@ -318,14 +318,14 @@ class Trashbin { foreach ($versions as $v) { $size += $view->filesize('versions_trashbin/'.$filename.'.v'.$v.'.d'.$timestamp); $view->unlink('versions_trashbin/'.$filename.'.v'.$v.'.d'.$timestamp); - } + } } } } - - $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND timestamp<?');
+ + $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND timestamp<?'); $query->execute(array($user,$limit)); - + $availableSpace = $availableSpace + $size; // if size limit for trash bin reached, delete oldest files in trash bin if ($availableSpace < 0) { @@ -340,15 +340,15 @@ class Trashbin { $size += $tmp; $i++; } - + } - - return $size;
+ + return $size; } - + /** * recursive copy to copy a whole directory - * + * * @param $source source path, relative to the users files directory * @param $destination destination path relative to the users root directoy * @param $view file view for the users root directory @@ -375,7 +375,7 @@ class Trashbin { } return $size; } - + /** * find all versions which belong to the file we want to restore * @param $filename name of the file which should be restored @@ -383,7 +383,7 @@ class Trashbin { */ private static function getVersionsFromTrash($filename, $timestamp) { $view = new \OC_FilesystemView('/'.\OCP\User::getUser().'/versions_trashbin'); - $versionsName = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath($filename);
+ $versionsName = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath($filename); $versions = array(); if ($timestamp ) { // fetch for old versions @@ -391,20 +391,20 @@ class Trashbin { $offset = -strlen($timestamp)-2; } else { $matches = glob( $versionsName.'.v*' ); - }
-
+ } + foreach( $matches as $ma ) { if ( $timestamp ) { - $parts = explode( '.v', substr($ma, 0, $offset) );
+ $parts = explode( '.v', substr($ma, 0, $offset) ); $versions[] = ( end( $parts ) ); } else { - $parts = explode( '.v', $ma );
+ $parts = explode( '.v', $ma ); $versions[] = ( end( $parts ) ); } } return $versions; } - + /** * find unique extension for restored file if a file with the same name already exists * @param $location where the file should be restored @@ -413,40 +413,40 @@ class Trashbin { * @return string with unique extension */ private static function getUniqueExtension($location, $filename, $view) { - $ext = '';
- if ( $view->file_exists('files'.$location.'/'.$filename) ) {
- $tmpext = '.restored';
- $ext = $tmpext;
- $i = 1;
- while ( $view->file_exists('files'.$location.'/'.$filename.$ext) ) {
- $ext = $tmpext.$i;
- $i++;
- }
+ $ext = ''; + if ( $view->file_exists('files'.$location.'/'.$filename) ) { + $tmpext = '.restored'; + $ext = $tmpext; + $i = 1; + while ( $view->file_exists('files'.$location.'/'.$filename.$ext) ) { + $ext = $tmpext.$i; + $i++; + } } return $ext; } - /**
+ /** * @brief get the size from a given root folder - * @param $view file view on the root folder
- * @return size of the folder
- */
- private static function calculateSize($view) {
- $root = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath('');
+ * @param $view file view on the root folder + * @return size of the folder + */ + private static function calculateSize($view) { + $root = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath(''); if (!file_exists($root)) { return 0; } $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($root), - \RecursiveIteratorIterator::CHILD_FIRST);
- $size = 0;
-
+ \RecursiveIteratorIterator::CHILD_FIRST); + $size = 0; + foreach ($iterator as $path) { $relpath = substr($path, strlen($root)-1); if ( !$view->is_dir($relpath) ) { $size += $view->filesize($relpath); - }
- }
- return $size;
+ } + } + return $size; } - -}
+ +} diff --git a/apps/files_trashbin/templates/part.list.php b/apps/files_trashbin/templates/part.list.php index 2de0d7ee91a..dea0a43cd4c 100644 --- a/apps/files_trashbin/templates/part.list.php +++ b/apps/files_trashbin/templates/part.list.php @@ -69,4 +69,3 @@ </td> </tr> <?php endforeach; -
\ No newline at end of file |