UploadHome.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\DAV\Upload;
  24. use OC\Files\Filesystem;
  25. use OC\Files\View;
  26. use OCA\DAV\Connector\Sabre\Directory;
  27. use Sabre\DAV\Exception\Forbidden;
  28. use Sabre\DAV\ICollection;
  29. class UploadHome implements ICollection {
  30. /**
  31. * UploadHome constructor.
  32. *
  33. * @param array $principalInfo
  34. */
  35. public function __construct($principalInfo) {
  36. $this->principalInfo = $principalInfo;
  37. }
  38. function createFile($name, $data = null) {
  39. throw new Forbidden('Permission denied to create file (filename ' . $name . ')');
  40. }
  41. function createDirectory($name) {
  42. $this->impl()->createDirectory($name);
  43. }
  44. function getChild($name) {
  45. return new UploadFolder($this->impl()->getChild($name));
  46. }
  47. function getChildren() {
  48. return array_map(function($node) {
  49. return new UploadFolder($node);
  50. }, $this->impl()->getChildren());
  51. }
  52. function childExists($name) {
  53. return !is_null($this->getChild($name));
  54. }
  55. function delete() {
  56. $this->impl()->delete();
  57. }
  58. function getName() {
  59. return 'uploads';
  60. }
  61. function setName($name) {
  62. throw new Forbidden('Permission denied to rename this folder');
  63. }
  64. function getLastModified() {
  65. return $this->impl()->getLastModified();
  66. }
  67. /**
  68. * @return Directory
  69. */
  70. private function impl() {
  71. $rootView = new View();
  72. $user = \OC::$server->getUserSession()->getUser();
  73. Filesystem::initMountPoints($user->getUID());
  74. if (!$rootView->file_exists('/' . $user->getUID() . '/uploads')) {
  75. $rootView->mkdir('/' . $user->getUID() . '/uploads');
  76. }
  77. $view = new View('/' . $user->getUID() . '/uploads');
  78. $rootInfo = $view->getFileInfo('');
  79. $impl = new Directory($view, $rootInfo);
  80. return $impl;
  81. }
  82. }