Completed
Pull Request — master (#362)
by Maxence
01:55 queued 11s
created

Mount::moveMount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
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 daita\MySmallPhpTools\Traits\TArrayTools;
34
use Exception;
35
use OC\Files\Mount\MountPoint;
36
use OC\Files\Mount\MoveableMount;
37
38
39
/**
40
 * Class Mount
41
 *
42
 * @package OCA\Circles\GlobalScale\GSMount
43
 */
44
class Mount extends MountPoint implements MoveableMount {
45
46
47
	use TArrayTools;
48
49
50
	/** @var MountManager */
51
	protected $mountManager;
52
53
	/** @var int */
54
	private $gsShareId = -1;
55
56
	/**
57
	 * Mount constructor.
58
	 *
59
	 * @param $storage
60
	 * @param string $mountPoint
61
	 * @param array $options
62
	 * @param MountManager $manager
63
	 * @param null $loader
64
	 *
65
	 * @throws Exception
66
	 */
67
	public function __construct(
68
		$storage, string $mountPoint, array $options, MountManager $manager, $loader = null
69
	) {
70
		parent::__construct($storage, $mountPoint, $options, $loader);
71
		$this->gsShareId = $this->getInt('gsShareId', $options);
72
		$this->mountManager = $manager;
73
	}
74
75
76
	/**
77
	 * Move the mount point to $target
78
	 *
79
	 * @param string $target the target mount point
80
	 *
81
	 * @return bool
82
	 */
83
	public function moveMount($target) {
84
		$result = $this->mountManager->renameShare($this->gsShareId, $target);
85
		$this->setMountPoint($target);
86
87
		return $result;
88
	}
89
90
	/**
91
	 * Remove the mount points
92
	 *
93
	 * @return mixed
94
	 * @return bool
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use boolean.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
95
	 */
96
	public function removeMount() {
97
		return $this->mountManager->unshare($this->gsShareId);
98
	}
99
100
101
	/**
102
	 * Get the type of mount point, used to distinguish things like shares and external storages
103
	 * in the web interface
104
	 *
105
	 * @return string
106
	 */
107
	public function getMountType() {
108
		return 'shared';
109
	}
110
}
111
112