Completed
Push — master ( 80388d...372d01 )
by Maxence
01:43
created

MountManager::removeMount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
4
/**
5
 * Circles - Bring cloud-users closer together.
6
 *
7
 * This file is licensed under the Affero General Public License version 3 or
8
 * later. See the COPYING file.
9
 *
10
 * @author Maxence Lange <[email protected]>
11
 * @copyright 2020
12
 * @license GNU AGPL version 3 or any later version
13
 *
14
 * This program is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Affero General Public License as
16
 * published by the Free Software Foundation, either version 3 of the
17
 * License, or (at your option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU Affero General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Affero General Public License
25
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
 *
27
 */
28
29
30
namespace OCA\Circles\GlobalScale\GSMount;
31
32
33
use OCA\Circles\Db\GSSharesRequest;
34
use OCA\Circles\Model\GlobalScale\GSShareMountpoint;
35
use OCP\Share\Exceptions\ShareNotFound;
36
37
38
/**
39
 * Class MountManager
40
 *
41
 * @package OCA\Circles\GlobalScale\GSMount
42
 */
43
class MountManager {
44
45
46
	/** @var string */
47
	private $userId;
48
49
	/** @var GSSharesRequest */
50
	private $gsSharesRequest;
51
52
53
	/**
54
	 * MountManager constructor.
55
	 *
56
	 * @param string $userId
57
	 * @param GSSharesRequest $gsSharesRequest
58
	 */
59
	public function __construct($userId, GSSharesRequest $gsSharesRequest) {
60
		$this->userId = $userId;
61
		$this->gsSharesRequest = $gsSharesRequest;
62
	}
63
64
65
	/**
66
	 * @param int $gsShareId
67
	 * @param string $target
68
	 *
69
	 * @return bool
70
	 */
71
	public function renameShare(int $gsShareId, string $target) {
72
		try {
73
			if ($target !== '-') {
74
				$target = $this->stripPath($target);
75
				$this->gsSharesRequest->getShareMountPointByPath($this->userId, $target);
76
77
				return false;
78
			}
79
		} catch (ShareNotFound $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
Bug introduced by
The class OCP\Share\Exceptions\ShareNotFound does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
80
		}
81
82
		$mountPoint = new GSShareMountpoint($gsShareId, $this->userId, $target);
83
		try {
84
			$this->gsSharesRequest->getShareMountPointById($gsShareId, $this->userId);
85
			$this->gsSharesRequest->updateShareMountPoint($mountPoint);
86
		} catch (ShareNotFound $e) {
0 ignored issues
show
Bug introduced by
The class OCP\Share\Exceptions\ShareNotFound does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
87
			$this->gsSharesRequest->generateShareMountPoint($mountPoint);
88
		}
89
90
		return true;
91
	}
92
93
94
	// TODO: implement !
95
	public function getMountManager() {
96
		return $this;
97
	}
98
99
	// TODO: implement !
100
	public function removeShare($mountPoint) {
0 ignored issues
show
Unused Code introduced by
The parameter $mountPoint is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
101
	}
102
103
	// TODO: implement !
104
	public function removeMount($mountPoint) {
0 ignored issues
show
Unused Code introduced by
The parameter $mountPoint is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
105
	}
106
107
108
	/**
109
	 * @param int $gsShareId
110
	 *
111
	 * @return bool
112
	 */
113
	public function unshare(int $gsShareId) {
114
		return $this->renameShare($gsShareId, '-');
115
	}
116
117
118
	/**
119
	 * remove '/user/files' from the path and trailing slashes
120
	 *
121
	 * @param string $path
122
	 *
123
	 * @return string
124
	 */
125
	protected function stripPath($path) {
126
		$prefix = '/' . $this->userId . '/files';
127
128
		return rtrim(substr($path, strlen($prefix)), '/');
129
	}
130
131
132
}
133