1<?php
2/**
3 * @author Morris Jobke <hey@morrisjobke.de>
4 * @author Robin Appelman <icewind@owncloud.com>
5 * @author Robin McCorkell <robin@mccorkell.me.uk>
6 * @author Vincent Petry <pvince81@owncloud.com>
7 *
8 * @copyright Copyright (c) 2018, ownCloud GmbH
9 * @license AGPL-3.0
10 *
11 * This code is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Affero General Public License, version 3,
13 * as published by the Free Software Foundation.
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, version 3,
21 * along with this program.  If not, see <http://www.gnu.org/licenses/>
22 *
23 */
24
25namespace OC\Files\External;
26
27use OC\Files\Mount\MountPoint;
28use OC\Files\Mount\MoveableMount;
29use OCP\Files\External\Service\IUserStoragesService;
30
31/**
32 * Person mount points can be moved by the user
33 */
34class PersonalMount extends MountPoint implements MoveableMount {
35	/** @var IUserStoragesService */
36	protected $storagesService;
37
38	/** @var int */
39	protected $numericStorageId;
40
41	/**
42	 * @param IUserStoragesService $storagesService
43	 * @param int $storageId
44	 * @param \OCP\Files\Storage $storage
45	 * @param string $mountpoint
46	 * @param array $arguments (optional) configuration for the storage backend
47	 * @param \OCP\Files\Storage\IStorageFactory $loader
48	 * @param array $mountOptions mount specific options
49	 */
50	public function __construct(
51		IUserStoragesService $storagesService,
52		$storageId,
53		$storage,
54		$mountpoint,
55		$arguments = null,
56		$loader = null,
57		$mountOptions = null
58	) {
59		parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions);
60		$this->storagesService = $storagesService;
61		$this->numericStorageId = $storageId;
62	}
63
64	/**
65	 * Move the mount point to $target
66	 *
67	 * @param string $target the target mount point
68	 * @return bool
69	 */
70	public function moveMount($target) {
71		$storage = $this->storagesService->getStorage($this->numericStorageId);
72		// remove "/$user/files" prefix
73		$targetParts = \explode('/', \trim($target, '/'), 3);
74		$storage->setMountPoint($targetParts[2]);
75		$this->storagesService->updateStorage($storage);
76		$this->setMountPoint($target);
77		return true;
78	}
79
80	/**
81	 * Remove the mount points
82	 *
83	 * @return bool
84	 */
85	public function removeMount() {
86		$this->storagesService->removeStorage($this->numericStorageId);
87		return true;
88	}
89
90	/**
91	 * Returns true
92	 *
93	 * @param string $target unused
94	 * @return bool true
95	 */
96	public function isTargetAllowed($target) {
97		// note: home storage check already done in View
98		return true;
99	}
100}
101