fix delete files from trash bin

This commit is contained in:
Bjoern Schiessle 2013-12-02 11:39:53 +01:00
parent 71589e65d2
commit 8ce3ea3e2c
3 changed files with 34 additions and 16 deletions

View File

@ -6,10 +6,18 @@ OCP\JSON::callCheck();
// "empty trash" command // "empty trash" command
$deleteAll = false; $deleteAll = false;
if (isset($_POST['allfiles']) and $_POST['allfiles'] === 'true'){ if (isset($_POST['allfiles']) and $_POST['allfiles'] === 'true'){
$user = \OCP\User::getUser(); $folder = isset($_POST['dir']) ? $_POST['dir'] : '/';
$list = OCA\Files_Trashbin\Helper::getTrashFiles('/'); if ($folder === '/') {
$deleteAll = true; OCA\Files_Trashbin\Trashbin::deleteAll();
$dirlisting = '0'; $list = array();
} else {
if ( strlen(dirname($folder)) > 1 ) {
$dirlisting = '1';
} else {
$dirlisting = '0';
}
$list[] = $folder;
}
} }
else { else {
$files = $_POST['files']; $files = $_POST['files'];
@ -19,19 +27,13 @@ else {
$error = array(); $error = array();
$success = array(); $success = array();
$i = 0; $i = 0;
foreach ($list as $file) { foreach ($list as $file) {
if ( $dirlisting === '0') { if ( $dirlisting === '0') {
if ($deleteAll) { $file = ltrim($file, '/');
$filename = $file['name']; $delimiter = strrpos($file, '.d');
$timestamp = $file['timestamp']; $filename = substr($file, 0, $delimiter);
} $timestamp = substr($file, $delimiter+2);
else {
$delimiter = strrpos($file, '.d');
$filename = substr($file, 0, $delimiter);
$timestamp = substr($file, $delimiter+2);
}
} else { } else {
$filename = $file; $filename = $file;
$timestamp = null; $timestamp = null;

View File

@ -35,7 +35,7 @@ $(document).ready(function() {
deleteAction.removeClass('delete-icon').addClass('progress-icon'); deleteAction.removeClass('delete-icon').addClass('progress-icon');
disableActions(); disableActions();
$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), $.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) { function(result) {
for (var i = 0; i < result.data.success.length; i++) { for (var i = 0; i < result.data.success.length; i++) {
var row = document.getElementById(result.data.success[i].filename); var row = document.getElementById(result.data.success[i].filename);
@ -136,7 +136,8 @@ $(document).ready(function() {
var params = {}; var params = {};
if (allFiles) { if (allFiles) {
params = { params = {
allfiles: true allfiles: true,
dir: $('#dir').val()
}; };
} }
else { else {

View File

@ -564,6 +564,21 @@ class Trashbin {
return $size; return $size;
} }
/**
* @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 * @brief delete file from trash bin permanently
* *