Passed
Push — master ( 9e596d...9f70c6 )
by Christoph
15:44 queued 10s
created

DeletedCalendarObject::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * @copyright 2021 Christoph Wurst <[email protected]>
7
 *
8
 * @author 2021 Christoph Wurst <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 */
25
26
namespace OCA\DAV\CalDAV\Trashbin;
27
28
use OCA\DAV\CalDAV\CalDavBackend;
29
use OCA\DAV\CalDAV\IRestorable;
30
use Sabre\CalDAV\ICalendarObject;
31
use Sabre\DAV\Exception\Forbidden;
32
33
class DeletedCalendarObject implements ICalendarObject, IRestorable {
34
35
	/** @var string */
36
	private $name;
37
38
	/** @var mixed[] */
39
	private $objectData;
40
41
	/** @var CalDavBackend */
42
	private $calDavBackend;
43
44
	public function __construct(string $name,
45
								array $objectData,
46
								CalDavBackend $calDavBackend) {
47
		$this->name = $name;
48
		$this->objectData = $objectData;
49
		$this->calDavBackend = $calDavBackend;
50
	}
51
52
	public function delete() {
53
		throw new Forbidden();
54
	}
55
56
	public function getName() {
57
		return $this->name;
58
	}
59
60
	public function setName($name) {
61
		throw new Forbidden();
62
	}
63
64
	public function getLastModified() {
65
		return 0;
66
	}
67
68
	public function put($data) {
69
		throw new Forbidden();
70
	}
71
72
	public function get() {
73
		return $this->objectData['calendardata'];
74
	}
75
76
	public function getContentType() {
77
		$mime = 'text/calendar; charset=utf-8';
78
		if (isset($this->objectData['component']) && $this->objectData['component']) {
79
			$mime .= '; component='.$this->objectData['component'];
80
		}
81
82
		return $mime;
83
	}
84
85
	public function getETag() {
86
		return $this->objectData['etag'];
87
	}
88
89
	public function getSize() {
90
		return (int) $this->objectData['size'];
91
	}
92
93
	public function restore(): void {
94
		$this->calDavBackend->restoreCalendarObject($this->objectData);
95
	}
96
}
97