TrashFile.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Files_Trashbin\Sabre;
  25. use OCP\Files\FileInfo;
  26. use Sabre\DAV\Exception\Forbidden;
  27. use Sabre\DAV\IFile;
  28. class TrashFile implements IFile, ITrash {
  29. /** @var string */
  30. private $userId;
  31. /** @var FileInfo */
  32. private $data;
  33. public function __construct(string $userId, FileInfo $data) {
  34. $this->userId = $userId;
  35. $this->data = $data;
  36. }
  37. public function put($data) {
  38. throw new Forbidden();
  39. }
  40. public function get() {
  41. return $this->data->getStorage()->fopen($this->data->getInternalPath().'.d'.$this->getLastModified(), 'rb');
  42. }
  43. public function getContentType(): string {
  44. return $this->data->getMimetype();
  45. }
  46. public function getETag(): string {
  47. return $this->data->getEtag();
  48. }
  49. public function getSize(): int {
  50. return $this->data->getSize();
  51. }
  52. public function delete() {
  53. \OCA\Files_Trashbin\Trashbin::delete($this->data->getName(), $this->userId, $this->getLastModified());
  54. }
  55. public function getName(): string {
  56. return $this->data->getName() . '.d' . $this->getLastModified();
  57. }
  58. public function setName($name) {
  59. throw new Forbidden();
  60. }
  61. public function getLastModified(): int {
  62. return $this->data->getMtime();
  63. }
  64. public function restore(): bool {
  65. return \OCA\Files_Trashbin\Trashbin::restore($this->getName(), $this->data->getName(), $this->getLastModified());
  66. }
  67. public function getFilename(): string {
  68. return $this->data->getName();
  69. }
  70. public function getOriginalLocation(): string {
  71. return $this->data['extraData'];
  72. }
  73. public function getDeletionTime(): int {
  74. return $this->getLastModified();
  75. }
  76. public function getFileId(): int {
  77. return $this->data->getId();
  78. }
  79. }