Completed
Push — master ( 53eb0f...62e19d )
by Lukas
35:26 queued 21:10
created

CachedMountInfo::getRootId()   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 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Robin Appelman <[email protected]>
6
 *
7
 * @license AGPL-3.0
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License, version 3,
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
23
namespace OC\Files\Config;
24
25
use OC\Files\Filesystem;
26
use OCP\Files\Config\ICachedMountInfo;
27
use OCP\Files\Node;
28
use OCP\IUser;
29
30
class CachedMountInfo implements ICachedMountInfo {
31
	/**
32
	 * @var IUser
33
	 */
34
	protected $user;
35
36
	/**
37
	 * @var int
38
	 */
39
	protected $storageId;
40
41
	/**
42
	 * @var int
43
	 */
44
	protected $rootId;
45
46
	/**
47
	 * @var string
48
	 */
49
	protected $mountPoint;
50
51
	/**
52
	 * @var int|null
53
	 */
54
	protected $mountId;
55
56
	/**
57
	 * @var string
58
	 */
59
	protected $rootInternalPath;
60
61
	/**
62
	 * CachedMountInfo constructor.
63
	 *
64
	 * @param IUser $user
65
	 * @param int $storageId
66
	 * @param int $rootId
67
	 * @param string $mountPoint
68
	 * @param int|null $mountId
69
	 * @param string $rootInternalPath
70
	 */
71
	public function __construct(IUser $user, $storageId, $rootId, $mountPoint, $mountId = null, $rootInternalPath = '') {
72
		$this->user = $user;
73
		$this->storageId = $storageId;
74
		$this->rootId = $rootId;
75
		$this->mountPoint = $mountPoint;
76
		$this->mountId = $mountId;
77
		$this->rootInternalPath = $rootInternalPath;
78
	}
79
80
	/**
81
	 * @return IUser
82
	 */
83
	public function getUser() {
84
		return $this->user;
85
	}
86
87
	/**
88
	 * @return int the numeric storage id of the mount
89
	 */
90
	public function getStorageId() {
91
		return $this->storageId;
92
	}
93
94
	/**
95
	 * @return int the fileid of the root of the mount
96
	 */
97
	public function getRootId() {
98
		return $this->rootId;
99
	}
100
101
	/**
102
	 * @return Node the root node of the mount
103
	 */
104
	public function getMountPointNode() {
105
		// TODO injection etc
106
		Filesystem::initMountPoints($this->getUser()->getUID());
107
		$userNode = \OC::$server->getUserFolder($this->getUser()->getUID());
108
		$nodes = $userNode->getParent()->getById($this->getRootId());
109
		if (count($nodes) > 0) {
110
			return $nodes[0];
111
		} else {
112
			return null;
113
		}
114
	}
115
116
	/**
117
	 * @return string the mount point of the mount for the user
118
	 */
119
	public function getMountPoint() {
120
		return $this->mountPoint;
121
	}
122
123
	/**
124
	 * Get the id of the configured mount
125
	 *
126
	 * @return int|null mount id or null if not applicable
127
	 * @since 9.1.0
128
	 */
129
	public function getMountId() {
130
		return $this->mountId;
131
	}
132
133
	/**
134
	 * Get the internal path (within the storage) of the root of the mount
135
	 *
136
	 * @return string
137
	 */
138
	public function getRootInternalPath() {
139
		return $this->rootInternalPath;
140
	}
141
}
142