diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2013-02-06 11:27:32 -0800 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2013-02-06 11:27:32 -0800 |
commit | e522872408e4fab2277d6deee475d0241ad6a825 (patch) | |
tree | 697feaa2795eeef06ead5524ac6bf6352d2e2333 | |
parent | ad644b4e08ddee30dddbe9a2311f0de3d3c5fae4 (diff) | |
parent | fd171a4f3407a4c4c01b7eac256e2b1a9f920f25 (diff) | |
download | nextcloud-server-e522872408e4fab2277d6deee475d0241ad6a825.tar.gz nextcloud-server-e522872408e4fab2277d6deee475d0241ad6a825.zip |
Merge pull request #1498 from schiesbn/delete_trash
delete files from trash bin permanently
-rw-r--r-- | apps/files/js/fileactions.js | 2 | ||||
-rw-r--r-- | apps/files_trashbin/ajax/delete.php | 24 | ||||
-rw-r--r-- | apps/files_trashbin/js/disableDefaultActions.js | 1 | ||||
-rw-r--r-- | apps/files_trashbin/js/trash.js | 25 | ||||
-rw-r--r-- | apps/files_trashbin/lib/trash.php | 39 |
5 files changed, 91 insertions, 0 deletions
diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index c30f1bcddd8..af3fc483910 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 = '<a href="#" original-title="' + t('files', 'Unshare') + '" class="action delete" />'; + } else if (typeof trashBinApp !== 'undefined' && trashBinApp) { + var html = '<a href="#" original-title="' + t('files', 'Delete permanently') + '" class="action delete" />'; } else { var html = '<a href="#" original-title="' + t('files', 'Delete') + '" class="action delete" />'; } diff --git a/apps/files_trashbin/ajax/delete.php b/apps/files_trashbin/ajax/delete.php new file mode 100644 index 00000000000..a166ce55c88 --- /dev/null +++ b/apps/files_trashbin/ajax/delete.php @@ -0,0 +1,24 @@ +<?php + +OCP\JSON::checkLoggedIn(); +OCP\JSON::callCheck(); + +$file = $_REQUEST['file']; + +$path_parts = pathinfo($file); +if ($path_parts['dirname'] == '.') { + $delimiter = strrpos($file, '.d'); + $filename = substr($file, 0, $delimiter); + $timestamp = substr($file, $delimiter+2); +} else { + $filename = $file; + $timestamp = null; +} + +if (OCA_Trash\Trashbin::delete($filename, $timestamp)) { + error_log("feinifeini"); + OCP\JSON::success(array("data" => 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 56b95407dd3..27c3e13db4d 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 f1241fce51e..6c810e4c2bd 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 = '<img class="move2trash" data-action="Delete" title="'+t('files', 'delete file permanently')+'" src="'+ OC.imagePath('core', 'loading.gif') +'"></a>'; + 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 a7eff3d44e0..e41dcb096c9 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -151,6 +151,45 @@ class Trashbin { } /**
+ * 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));
+ $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
*/
private static function expire() { |