undelete.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. OCP\JSON::checkLoggedIn();
  3. OCP\JSON::callCheck();
  4. \OC::$server->getSession()->close();
  5. $files = $_POST['files'];
  6. $dir = '/';
  7. if (isset($_POST['dir'])) {
  8. $dir = rtrim($_POST['dir'], '/'). '/';
  9. }
  10. $allFiles = false;
  11. if (isset($_POST['allfiles']) and $_POST['allfiles'] === 'true') {
  12. $allFiles = true;
  13. $list = array();
  14. $dirListing = true;
  15. if ($dir === '' || $dir === '/') {
  16. $dirListing = false;
  17. }
  18. foreach (OCA\Files_Trashbin\Helper::getTrashFiles($dir, \OCP\User::getUser()) as $file) {
  19. $fileName = $file['name'];
  20. if (!$dirListing) {
  21. $fileName .= '.d' . $file['mtime'];
  22. }
  23. $list[] = $fileName;
  24. }
  25. } else {
  26. $list = json_decode($files);
  27. }
  28. $error = array();
  29. $success = array();
  30. $i = 0;
  31. foreach ($list as $file) {
  32. $path = $dir . '/' . $file;
  33. if ($dir === '/') {
  34. $file = ltrim($file, '/');
  35. $delimiter = strrpos($file, '.d');
  36. $filename = substr($file, 0, $delimiter);
  37. $timestamp = substr($file, $delimiter+2);
  38. } else {
  39. $path_parts = pathinfo($file);
  40. $filename = $path_parts['basename'];
  41. $timestamp = null;
  42. }
  43. if ( !OCA\Files_Trashbin\Trashbin::restore($path, $filename, $timestamp) ) {
  44. $error[] = $filename;
  45. OC_Log::write('trashbin', 'can\'t restore ' . $filename, OC_Log::ERROR);
  46. } else {
  47. $success[$i]['filename'] = $file;
  48. $success[$i]['timestamp'] = $timestamp;
  49. $i++;
  50. }
  51. }
  52. if ( $error ) {
  53. $filelist = '';
  54. foreach ( $error as $e ) {
  55. $filelist .= $e.', ';
  56. }
  57. $l = OC::$server->getL10N('files_trashbin');
  58. $message = $l->t("Couldn't restore %s", array(rtrim($filelist, ', ')));
  59. OCP\JSON::error(array("data" => array("message" => $message,
  60. "success" => $success, "error" => $error)));
  61. } else {
  62. OCP\JSON::success(array("data" => array("success" => $success)));
  63. }