1
0

VersionFile.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Robin Appelman <robin@icewind.nl>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  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
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\Files_Versions\Sabre;
  26. use OCA\Files_Versions\Versions\IVersion;
  27. use OCA\Files_Versions\Versions\IVersionManager;
  28. use OCP\Files\NotFoundException;
  29. use Sabre\DAV\Exception\Forbidden;
  30. use Sabre\DAV\Exception\NotFound;
  31. use Sabre\DAV\IFile;
  32. class VersionFile implements IFile {
  33. /** @var IVersion */
  34. private $version;
  35. /** @var IVersionManager */
  36. private $versionManager;
  37. public function __construct(IVersion $version, IVersionManager $versionManager) {
  38. $this->version = $version;
  39. $this->versionManager = $versionManager;
  40. }
  41. public function put($data) {
  42. throw new Forbidden();
  43. }
  44. public function get() {
  45. try {
  46. return $this->versionManager->read($this->version);
  47. } catch (NotFoundException $e) {
  48. throw new NotFound();
  49. }
  50. }
  51. public function getContentType(): string {
  52. return $this->version->getMimeType();
  53. }
  54. public function getETag(): string {
  55. return (string)$this->version->getRevisionId();
  56. }
  57. public function getSize(): int {
  58. return $this->version->getSize();
  59. }
  60. public function delete() {
  61. throw new Forbidden();
  62. }
  63. public function getName(): string {
  64. return (string)$this->version->getRevisionId();
  65. }
  66. public function setName($name) {
  67. throw new Forbidden();
  68. }
  69. public function getLastModified(): int {
  70. return $this->version->getTimestamp();
  71. }
  72. public function rollBack() {
  73. $this->versionManager->rollback($this->version);
  74. }
  75. public function getVersion(): IVersion {
  76. return $this->version;
  77. }
  78. }