]> source.dussan.org Git - nextcloud-server.git/commitdiff
allow to delete single files from the trash bin permanently
authorBjörn Schießle <schiessle@owncloud.com>
Wed, 6 Feb 2013 15:23:22 +0000 (16:23 +0100)
committerBjörn Schießle <schiessle@owncloud.com>
Wed, 6 Feb 2013 15:23:22 +0000 (16:23 +0100)
apps/files/js/fileactions.js
apps/files_trashbin/ajax/delete.php [new file with mode: 0644]
apps/files_trashbin/js/disableDefaultActions.js
apps/files_trashbin/js/trash.js
apps/files_trashbin/lib/trash.php

index c30f1bcddd8396feaeb194d65a28441db35e4010..af3fc483910a616a39a4ac0319798bc195c27a74 100644 (file)
@@ -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 (file)
index 0000000..fe41f53
--- /dev/null
@@ -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;
+}
+sleep(5);
+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")));
+}
+
index 56b95407dd34cb105f90f8f00776dfffd5b185f5..27c3e13db4d12d05a8c8e9796b031d72c1232247 100644 (file)
@@ -1,3 +1,4 @@
 /* disable download and sharing actions */\r
 var disableDownloadActions = true;\r
 var disableSharing = true;\r
+var trashBinApp = true;
\ No newline at end of file
index f1241fce51e2b9e6fcdedb106bae72667e95e006..6c810e4c2bd017ac92e8ad1b2e62f1c3ebd2c31b 100644 (file)
@@ -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')){
index a7eff3d44e0bdf1539e2b6f8515242d2b328427e..bf98b6dfe805aed237d4e49a8d7e0e4d051e073b 100644 (file)
@@ -150,6 +150,45 @@ class Trashbin {
                return false;
        }
        
+       /**\r
+        * delete file from trash bin permanently\r
+        * @param $filename path to the file
+        * @param $timestamp of deletion time\r
+        * @return true/false\r
+        */\r
+       public static function delete($filename, $timestamp=null) {\r
+       \r
+               $user = \OCP\User::getUser();\r
+               $view = new \OC_FilesystemView('/'.$user);\r
+       \r
+               if ( $timestamp ) {\r
+                       $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?');\r
+                       $query->execute(array($user,$filename,$timestamp))->fetchAll();\r
+                       $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);
+                                       }
+                               }
+                       }
+               }\r
+       
+               $view->unlink('/files_trashbin/'.$file);
+               \r
+               return true;\r
+       }
+       
+       
        /**\r
         * clean up the trash bin\r
         */\r