1
0

undelete.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 Morris Jobke <hey@morrisjobke.de>
  9. * @author Robin Appelman <robin@icewind.nl>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. * @author Thomas Müller <thomas.mueller@tmit.eu>
  12. * @author Vincent Petry <pvince81@owncloud.com>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. use OCP\ILogger;
  30. \OC_JSON::checkLoggedIn();
  31. \OC_JSON::callCheck();
  32. \OC::$server->getSession()->close();
  33. $dir = '/';
  34. if (isset($_POST['dir'])) {
  35. $dir = rtrim((string)$_POST['dir'], '/'). '/';
  36. }
  37. $allFiles = false;
  38. if (isset($_POST['allfiles']) && (string)$_POST['allfiles'] === 'true') {
  39. $allFiles = true;
  40. $list = array();
  41. $dirListing = true;
  42. if ($dir === '' || $dir === '/') {
  43. $dirListing = false;
  44. }
  45. foreach (OCA\Files_Trashbin\Helper::getTrashFiles($dir, \OCP\User::getUser()) as $file) {
  46. $fileName = $file['name'];
  47. if (!$dirListing) {
  48. $fileName .= '.d' . $file['mtime'];
  49. }
  50. $list[] = $fileName;
  51. }
  52. } else {
  53. $list = json_decode($_POST['files']);
  54. }
  55. $error = array();
  56. $success = array();
  57. $i = 0;
  58. foreach ($list as $file) {
  59. $path = $dir . '/' . $file;
  60. if ($dir === '/') {
  61. $file = ltrim($file, '/');
  62. $delimiter = strrpos($file, '.d');
  63. $filename = substr($file, 0, $delimiter);
  64. $timestamp = substr($file, $delimiter+2);
  65. } else {
  66. $path_parts = pathinfo($file);
  67. $filename = $path_parts['basename'];
  68. $timestamp = null;
  69. }
  70. if ( !OCA\Files_Trashbin\Trashbin::restore($path, $filename, $timestamp) ) {
  71. $error[] = $filename;
  72. \OCP\Util::writeLog('trashbin', 'can\'t restore ' . $filename, ILogger::ERROR);
  73. } else {
  74. $success[$i]['filename'] = $file;
  75. $success[$i]['timestamp'] = $timestamp;
  76. $i++;
  77. }
  78. }
  79. if ( $error ) {
  80. $filelist = '';
  81. foreach ( $error as $e ) {
  82. $filelist .= $e.', ';
  83. }
  84. $l = OC::$server->getL10N('files_trashbin');
  85. $message = $l->t("Couldn't restore %s", array(rtrim($filelist, ', ')));
  86. \OC_JSON::error(array("data" => array("message" => $message,
  87. "success" => $success, "error" => $error)));
  88. } else {
  89. \OC_JSON::success(array("data" => array("success" => $success)));
  90. }