From e2516a2b65185bd3081361d0b8f25e6eaf7d698f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Wed, 6 Feb 2013 16:23:22 +0100 Subject: [PATCH] allow to delete single files from the trash bin permanently --- apps/files/js/fileactions.js | 2 + apps/files_trashbin/ajax/delete.php | 24 ++++++++++++ .../js/disableDefaultActions.js | 1 + apps/files_trashbin/js/trash.js | 25 ++++++++++++ apps/files_trashbin/lib/trash.php | 39 +++++++++++++++++++ 5 files changed, 91 insertions(+) create mode 100644 apps/files_trashbin/ajax/delete.php diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index c30f1bcddd..af3fc48391 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -115,6 +115,8 @@ var FileActions = { // NOTE: Temporary fix to allow unsharing of files in root of Shared folder if ($('#dir').val() == '/Shared') { var html = ''; + } else if (typeof trashBinApp !== 'undefined' && trashBinApp) { + var html = ''; } else { var html = ''; } diff --git a/apps/files_trashbin/ajax/delete.php b/apps/files_trashbin/ajax/delete.php new file mode 100644 index 0000000000..fe41f53d49 --- /dev/null +++ b/apps/files_trashbin/ajax/delete.php @@ -0,0 +1,24 @@ + array("filename" => $file))); +} else { + OCP\JSON::error(array("data" => array("message" => "Couldn't delete ".$file. " permanently"))); +} + diff --git a/apps/files_trashbin/js/disableDefaultActions.js b/apps/files_trashbin/js/disableDefaultActions.js index 56b95407dd..27c3e13db4 100644 --- a/apps/files_trashbin/js/disableDefaultActions.js +++ b/apps/files_trashbin/js/disableDefaultActions.js @@ -1,3 +1,4 @@ /* 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 f1241fce51..6c810e4c2b 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -22,6 +22,31 @@ $(document).ready(function() { }); }; + 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 = ''; + deleteAction[0].outerHTML = newHTML; + + $.post(OC.filePath('files_trashbin','ajax','delete.php'), + {file:tr.attr('data-file') }, + function(result){ + if ( result.status == 'success' ) { + var row = document.getElementById(result.data.filename); + row.parentNode.removeChild(row); + } else { + deleteAction[0].outerHTML = oldHTML; + OC.dialogs.alert(result.data.message, 'Error'); + } + }); + + }); + // Sets the select_all checkbox behaviour : $('#select_all').click(function() { if($(this).attr('checked')){ diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index a7eff3d44e..bf98b6dfe8 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -150,6 +150,45 @@ class Trashbin { return false; } + /** + * delete file from trash bin permanently + * @param $filename path to the file + * @param $timestamp of deletion time + * @return true/false + */ + public static function delete($filename, $timestamp=null) { + + $user = \OCP\User::getUser(); + $view = new \OC_FilesystemView('/'.$user); + + if ( $timestamp ) { + $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?'); + $query->execute(array($user,$filename,$timestamp))->fetchAll(); + $file = $filename.'.d'.$timestamp; + } else { + $file = $filename; + } + + if ( \OCP\App::isEnabled('files_versions') ) { + if ($view->is_dir('versions_trashbin/'.$file)) { + $view->unlink('versions_trashbin/'.$file); + } else if ( $versions = self::getVersionsFromTrash($file, $timestamp) ) { + foreach ($versions as $v) { + if ($timestamp ) { + $view->unlink('versions_trashbin/'.$filename.'.v'.$v.'.d'.$timestamp); + } else { + $view->unlink('versions_trashbin/'.$file.'.v'.$v); + } + } + } + } + + $view->unlink('/files_trashbin/'.$file); + + return true; + } + + /** * clean up the trash bin */