From 80c8666d3abae0a4004e48ad9f580397e98c6ac0 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 30 Oct 2013 22:34:37 +0100 Subject: Deleting all files in trash now only sends a single flag To prevent having to send the list of all files for deletion, only set a flag "allfiles". This should make it a bit smoother when deleting 5000+ files. Also fixes some "empty trash" message issues. --- apps/files_trashbin/ajax/delete.php | 39 ++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'apps/files_trashbin/ajax') diff --git a/apps/files_trashbin/ajax/delete.php b/apps/files_trashbin/ajax/delete.php index 92361b65f63..5498250dbf5 100644 --- a/apps/files_trashbin/ajax/delete.php +++ b/apps/files_trashbin/ajax/delete.php @@ -3,10 +3,19 @@ OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); -$files = $_POST['files']; -$dirlisting = $_POST['dirlisting']; -$list = json_decode($files); - +// "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'; +} +else { + $files = $_POST['files']; + $dirlisting = $_POST['dirlisting']; + $list = json_decode($files); +} $error = array(); $success = array(); @@ -14,22 +23,30 @@ $success = array(); $i = 0; foreach ($list as $file) { if ( $dirlisting === '0') { - $delimiter = strrpos($file, '.d'); - $filename = substr($file, 0, $delimiter); - $timestamp = substr($file, $delimiter+2); + if ($deleteAll) { + $filename = $file['name']; + $timestamp = $file['timestamp']; + } + else { + $delimiter = strrpos($file, '.d'); + $filename = substr($file, 0, $delimiter); + $timestamp = substr($file, $delimiter+2); + } } else { $filename = $file; $timestamp = null; } OCA\Files_Trashbin\Trashbin::delete($filename, $timestamp); - if (!OCA\Files_Trashbin\Trashbin::file_exists($filename, $timestamp)) { + if (OCA\Files_Trashbin\Trashbin::file_exists($filename, $timestamp)) { + $error[] = $filename; + OC_Log::write('trashbin','can\'t delete ' . $filename . ' permanently.', OC_Log::ERROR); + } + // only list deleted files if not deleting everything + else if (!$deleteAll) { $success[$i]['filename'] = $file; $success[$i]['timestamp'] = $timestamp; $i++; - } else { - $error[] = $filename; - OC_Log::write('trashbin','can\'t delete ' . $filename . ' permanently.', OC_Log::ERROR); } } -- cgit v1.2.3