1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* @copyright 2018, Roeland Jago Douma <[email protected]> |
5
|
|
|
* |
6
|
|
|
* @author Roeland Jago Douma <[email protected]> |
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
|
|
|
|
25
|
|
|
namespace OCA\Files_Versions\Sabre; |
26
|
|
|
|
27
|
|
|
use OCA\Files_Versions\Versions\IVersion; |
28
|
|
|
use OCA\Files_Versions\Versions\IVersionManager; |
29
|
|
|
use OCP\Files\NotFoundException; |
30
|
|
|
use Sabre\DAV\Exception\Forbidden; |
31
|
|
|
use Sabre\DAV\Exception\NotFound; |
32
|
|
|
use Sabre\DAV\IFile; |
33
|
|
|
|
34
|
|
|
class VersionFile implements IFile { |
35
|
|
|
/** @var IVersion */ |
36
|
|
|
private $version; |
37
|
|
|
|
38
|
|
|
/** @var IVersionManager */ |
39
|
|
|
private $versionManager; |
40
|
|
|
|
41
|
|
|
public function __construct(IVersion $version, IVersionManager $versionManager) { |
42
|
|
|
$this->version = $version; |
43
|
|
|
$this->versionManager = $versionManager; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function put($data) { |
47
|
|
|
throw new Forbidden(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function get() { |
51
|
|
|
try { |
52
|
|
|
return $this->versionManager->read($this->version); |
53
|
|
|
} catch (NotFoundException $e) { |
54
|
|
|
throw new NotFound(); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getContentType(): string { |
59
|
|
|
return $this->version->getMimeType(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getETag(): string { |
63
|
|
|
return (string)$this->version->getRevisionId(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getSize(): int { |
67
|
|
|
return $this->version->getSize(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function delete() { |
71
|
|
|
throw new Forbidden(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getName(): string { |
75
|
|
|
return (string)$this->version->getRevisionId(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function setName($name) { |
79
|
|
|
throw new Forbidden(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getLastModified(): int { |
83
|
|
|
return $this->version->getTimestamp(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function rollBack() { |
87
|
|
|
$this->versionManager->rollback($this->version); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getVersion(): IVersion { |
91
|
|
|
return $this->version; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|