Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. }