Completed
Push — master ( 3e5138...d2cc48 )
by Morris
22:18
created

PropfindPlugin::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
rs 9.4285
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_Trashbin\Sabre;
26
27
use OCA\DAV\Connector\Sabre\FilesPlugin;
28
use Sabre\DAV\INode;
29
use Sabre\DAV\PropFind;
30
use Sabre\DAV\Server;
31
use Sabre\DAV\ServerPlugin;
32
33
class PropfindPlugin extends ServerPlugin {
34
35
	const TRASHBIN_FILENAME = '{http://nextcloud.org/ns}trashbin-filename';
36
	const TRASHBIN_ORIGINAL_LOCATION = '{http://nextcloud.org/ns}trashbin-original-location';
37
	const TRASHBIN_DELETION_TIME = '{http://nextcloud.org/ns}trashbin-deletion-time';
38
39
	/** @var Server */
40
	private $server;
41
42
	public function __construct() {
43
	}
44
45
	public function initialize(Server $server) {
46
		$this->server = $server;
47
48
		$this->server->on('propFind', [$this, 'propFind']);
49
	}
50
51
52
	public function propFind(PropFind $propFind, INode $node) {
53
		if (!($node instanceof ITrash)) {
54
			return;
55
		}
56
57
		$propFind->handle(self::TRASHBIN_FILENAME, function() use ($node) {
58
			return $node->getFilename();
59
		});
60
61
		$propFind->handle(self::TRASHBIN_ORIGINAL_LOCATION, function() use ($node) {
62
			return $node->getOriginalLocation();
63
		});
64
65
		$propFind->handle(self::TRASHBIN_DELETION_TIME, function () use ($node) {
66
			return $node->getDeletionTime();
67
		});
68
69
		$propFind->handle(FilesPlugin::SIZE_PROPERTYNAME, function () use ($node) {
70
			return $node->getSize();
71
		});
72
73
		$propFind->handle(FilesPlugin::FILEID_PROPERTYNAME, function () use ($node) {
74
			return $node->getFileId();
75
		});
76
	}
77
78
}
79