Completed
Push — master ( fb9cb6...dc5c4b )
by Morris
51:46 queued 21:25
created

VersionFile::put()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
namespace OCA\Files_Versions\Sabre;
25
26
use OCA\Files_Versions\Storage;
27
use OCP\Files\File;
28
use OCP\Files\Folder;
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 array */
36
	private $data;
37
38
	/** @var Folder */
39
	private $userRoot;
40
41
	public function __construct(array $data, Folder $userRoot) {
42
		$this->data = $data;
43
		$this->userRoot = $userRoot;
44
	}
45
46
	public function put($data) {
47
		throw new Forbidden();
48
	}
49
50
	public function get() {
51
		try {
52
			/** @var Folder $versions */
53
			$versions = $this->userRoot->get('files_versions');
54
			/** @var File $version */
55
			$version = $versions->get($this->data['path'].'.v'.$this->data['version']);
56
		} catch (NotFoundException $e) {
57
			throw new NotFound();
58
		}
59
60
		return $version->fopen('rb');
61
	}
62
63
	public function getContentType(): string {
64
		return $this->data['mimetype'];
65
	}
66
67
	public function getETag(): string {
68
		return $this->data['version'];
69
	}
70
71
	public function getSize(): int {
72
		return $this->data['size'];
73
	}
74
75
	public function delete() {
76
		throw new Forbidden();
77
	}
78
79
	public function getName(): string {
80
		return $this->data['version'];
81
	}
82
83
	public function setName($name) {
84
		throw new Forbidden();
85
	}
86
87
	public function getLastModified(): int {
88
		return (int)$this->data['version'];
89
	}
90
91
	public function rollBack(): bool {
92
		return Storage::rollback($this->data['path'], $this->data['version']);
93
	}
94
}
95