delete.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Björn Schießle <bjoern@schiessle.org>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Vincent Petry <pvince81@owncloud.com>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. OCP\JSON::checkLoggedIn();
  28. OCP\JSON::callCheck();
  29. \OC::$server->getSession()->close();
  30. $folder = isset($_POST['dir']) ? $_POST['dir'] : '/';
  31. // "empty trash" command
  32. if (isset($_POST['allfiles']) && (string)$_POST['allfiles'] === 'true'){
  33. $deleteAll = true;
  34. if ($folder === '/' || $folder === '') {
  35. OCA\Files_Trashbin\Trashbin::deleteAll();
  36. $list = array();
  37. } else {
  38. $list[] = $folder;
  39. $folder = dirname($folder);
  40. }
  41. }
  42. else {
  43. $deleteAll = false;
  44. $files = (string)$_POST['files'];
  45. $list = json_decode($files);
  46. }
  47. $folder = rtrim($folder, '/') . '/';
  48. $error = array();
  49. $success = array();
  50. $i = 0;
  51. foreach ($list as $file) {
  52. if ($folder === '/') {
  53. $file = ltrim($file, '/');
  54. $delimiter = strrpos($file, '.d');
  55. $filename = substr($file, 0, $delimiter);
  56. $timestamp = substr($file, $delimiter+2);
  57. } else {
  58. $filename = $folder . '/' . $file;
  59. $timestamp = null;
  60. }
  61. OCA\Files_Trashbin\Trashbin::delete($filename, \OCP\User::getUser(), $timestamp);
  62. if (OCA\Files_Trashbin\Trashbin::file_exists($filename, $timestamp)) {
  63. $error[] = $filename;
  64. \OCP\Util::writeLog('trashbin','can\'t delete ' . $filename . ' permanently.', \OCP\Util::ERROR);
  65. }
  66. // only list deleted files if not deleting everything
  67. else if (!$deleteAll) {
  68. $success[$i]['filename'] = $file;
  69. $success[$i]['timestamp'] = $timestamp;
  70. $i++;
  71. }
  72. }
  73. if ( $error ) {
  74. $filelist = '';
  75. foreach ( $error as $e ) {
  76. $filelist .= $e.', ';
  77. }
  78. $l = \OC::$server->getL10N('files_trashbin');
  79. $message = $l->t("Couldn't delete %s permanently", array(rtrim($filelist, ', ')));
  80. OCP\JSON::error(array("data" => array("message" => $message,
  81. "success" => $success, "error" => $error)));
  82. } else {
  83. OCP\JSON::success(array("data" => array("success" => $success)));
  84. }