summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2013-12-02 04:33:37 -0800
committerVincent Petry <pvince81@owncloud.com>2013-12-02 04:33:37 -0800
commita81d4175ba1d0625a0096c6383f1af4505eb1d4d (patch)
treedd96cc4d9b84111b2bf3538122586361ced53a2c /apps
parentc2e83e635d0ad0fda4dbf9c89c06b45f59bc3b24 (diff)
parentfac2f2a6261e53f7948731291c011f21143891cd (diff)
downloadnextcloud-server-a81d4175ba1d0625a0096c6383f1af4505eb1d4d.tar.gz
nextcloud-server-a81d4175ba1d0625a0096c6383f1af4505eb1d4d.zip
Merge pull request #6148 from owncloud/fix_trash_restore
Fix restore anbd delete operations in trash bin
Diffstat (limited to 'apps')
-rw-r--r--apps/files_trashbin/ajax/delete.php32
-rw-r--r--apps/files_trashbin/ajax/undelete.php1
-rw-r--r--apps/files_trashbin/js/trash.js9
-rw-r--r--apps/files_trashbin/lib/trashbin.php15
4 files changed, 39 insertions, 18 deletions
diff --git a/apps/files_trashbin/ajax/delete.php b/apps/files_trashbin/ajax/delete.php
index 5498250dbf5..75d481768ad 100644
--- a/apps/files_trashbin/ajax/delete.php
+++ b/apps/files_trashbin/ajax/delete.php
@@ -4,14 +4,24 @@ OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
// "empty trash" command
-$deleteAll = false;
if (isset($_POST['allfiles']) and $_POST['allfiles'] === 'true'){
- $user = \OCP\User::getUser();
- $list = OCA\Files_Trashbin\Helper::getTrashFiles('/');
$deleteAll = true;
- $dirlisting = '0';
+ $folder = isset($_POST['dir']) ? $_POST['dir'] : '/';
+ if ($folder === '/' || $folder === '') {
+ OCA\Files_Trashbin\Trashbin::deleteAll();
+ $list = array();
+ } else {
+ $dirname = dirname($folder);
+ if ( $dirname !== '/' && $dirname !== '.' ) {
+ $dirlisting = '1';
+ } else {
+ $dirlisting = '0';
+ }
+ $list[] = $folder;
+ }
}
else {
+ $deleteAll = false;
$files = $_POST['files'];
$dirlisting = $_POST['dirlisting'];
$list = json_decode($files);
@@ -19,19 +29,13 @@ else {
$error = array();
$success = array();
-
$i = 0;
foreach ($list as $file) {
if ( $dirlisting === '0') {
- if ($deleteAll) {
- $filename = $file['name'];
- $timestamp = $file['timestamp'];
- }
- else {
- $delimiter = strrpos($file, '.d');
- $filename = substr($file, 0, $delimiter);
- $timestamp = substr($file, $delimiter+2);
- }
+ $file = ltrim($file, '/');
+ $delimiter = strrpos($file, '.d');
+ $filename = substr($file, 0, $delimiter);
+ $timestamp = substr($file, $delimiter+2);
} else {
$filename = $file;
$timestamp = null;
diff --git a/apps/files_trashbin/ajax/undelete.php b/apps/files_trashbin/ajax/undelete.php
index e39004cc0d5..876ad269a70 100644
--- a/apps/files_trashbin/ajax/undelete.php
+++ b/apps/files_trashbin/ajax/undelete.php
@@ -13,6 +13,7 @@ $success = array();
$i = 0;
foreach ($list as $file) {
if ( $dirlisting === '0') {
+ $file = ltrim($file, '/');
$delimiter = strrpos($file, '.d');
$filename = substr($file, 0, $delimiter);
$timestamp = substr($file, $delimiter+2);
diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js
index 84c23d66992..b157fdf1025 100644
--- a/apps/files_trashbin/js/trash.js
+++ b/apps/files_trashbin/js/trash.js
@@ -8,7 +8,7 @@ $(document).ready(function() {
deleteAction.removeClass('delete-icon').addClass('progress-icon');
disableActions();
$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'),
- {files: JSON.stringify([filename]), dirlisting: tr.attr('data-dirlisting')},
+ {files: JSON.stringify([$('#dir').val() + '/' + filename]), dirlisting: tr.attr('data-dirlisting')},
function(result) {
for (var i = 0; i < result.data.success.length; i++) {
var row = document.getElementById(result.data.success[i].filename);
@@ -35,7 +35,7 @@ $(document).ready(function() {
deleteAction.removeClass('delete-icon').addClass('progress-icon');
disableActions();
$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'),
- {files: JSON.stringify([filename]), dirlisting: tr.attr('data-dirlisting')},
+ {files: JSON.stringify([$('#dir').val() + '/' +filename]), dirlisting: tr.attr('data-dirlisting')},
function(result) {
for (var i = 0; i < result.data.success.length; i++) {
var row = document.getElementById(result.data.success[i].filename);
@@ -136,7 +136,8 @@ $(document).ready(function() {
var params = {};
if (allFiles) {
params = {
- allfiles: true
+ allfiles: true,
+ dir: $('#dir').val()
};
}
else {
@@ -229,7 +230,7 @@ function getSelectedFiles(property){
elements.each(function(i,element){
var file={
name:$(element).attr('data-filename'),
- file:$(element).attr('data-file'),
+ file:$('#dir').val() + "/" + $(element).attr('data-file'),
timestamp:$(element).attr('data-timestamp'),
type:$(element).attr('data-type'),
dirlisting:$(element).attr('data-dirlisting')
diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php
index bb6bdd547a0..48d43b059fa 100644
--- a/apps/files_trashbin/lib/trashbin.php
+++ b/apps/files_trashbin/lib/trashbin.php
@@ -565,6 +565,21 @@ class Trashbin {
}
/**
+ * @brief delete all files from the trash
+ */
+ public static function deleteAll() {
+ $user = \OCP\User::getUser();
+ $view = new \OC\Files\View('/' . $user);
+ $view->deleteAll('files_trashbin');
+ self::setTrashbinSize($user, 0);
+ $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=?');
+ $query->execute(array($user));
+
+ return true;
+ }
+
+
+ /**
* @brief delete file from trash bin permanently
*
* @param $filename path to the file