UploadFolder.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\DAV\Upload;
  26. use OCA\DAV\Connector\Sabre\Directory;
  27. use Sabre\DAV\Exception\Forbidden;
  28. use Sabre\DAV\ICollection;
  29. class UploadFolder implements ICollection {
  30. /** @var Directory */
  31. private $node;
  32. /** @var CleanupService */
  33. private $cleanupService;
  34. public function __construct(Directory $node, CleanupService $cleanupService) {
  35. $this->node = $node;
  36. $this->cleanupService = $cleanupService;
  37. }
  38. public function createFile($name, $data = null) {
  39. // TODO: verify name - should be a simple number
  40. $this->node->createFile($name, $data);
  41. }
  42. public function createDirectory($name) {
  43. throw new Forbidden('Permission denied to create file (filename ' . $name . ')');
  44. }
  45. public function getChild($name) {
  46. if ($name === '.file') {
  47. return new FutureFile($this->node, '.file');
  48. }
  49. return new UploadFile($this->node->getChild($name));
  50. }
  51. public function getChildren() {
  52. $tmpChildren = $this->node->getChildren();
  53. $children = [];
  54. $children[] = new FutureFile($this->node, '.file');
  55. foreach ($tmpChildren as $child) {
  56. $children[] = new UploadFile($child);
  57. }
  58. return $children;
  59. }
  60. public function childExists($name) {
  61. if ($name === '.file') {
  62. return true;
  63. }
  64. return $this->node->childExists($name);
  65. }
  66. public function delete() {
  67. $this->node->delete();
  68. // Background cleanup job is not needed anymore
  69. $this->cleanupService->removeJob($this->getName());
  70. }
  71. public function getName() {
  72. return $this->node->getName();
  73. }
  74. public function setName($name) {
  75. throw new Forbidden('Permission denied to rename this folder');
  76. }
  77. public function getLastModified() {
  78. return $this->node->getLastModified();
  79. }
  80. }