|
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\GSShare; |
|
35
|
|
|
use OCA\Files_Sharing\External\Manager; |
|
36
|
|
|
use OCA\Files_Sharing\External\Mount; |
|
|
|
|
|
|
37
|
|
|
use OCP\AppFramework\QueryException; |
|
38
|
|
|
use OCP\Federation\ICloudIdManager; |
|
39
|
|
|
use OCP\Files\Config\IMountProvider; |
|
40
|
|
|
use OCP\Files\Mount\IMountPoint; |
|
41
|
|
|
use OCP\Files\Storage\IStorageFactory; |
|
42
|
|
|
use OCP\IUser; |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
class MountProvider implements IMountProvider { |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
/** @var MountManager */ |
|
52
|
|
|
private $mountManager; |
|
53
|
|
|
|
|
54
|
|
|
/** @var ICloudIdManager */ |
|
55
|
|
|
private $cloudIdManager; |
|
56
|
|
|
|
|
57
|
|
|
/** @var GSSharesRequest */ |
|
58
|
|
|
private $gsSharesRequest; |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* MountProvider constructor. |
|
63
|
|
|
* |
|
64
|
|
|
* @param MountManager $mountManager |
|
65
|
|
|
* @param ICloudIdManager $cloudIdManager |
|
66
|
|
|
* @param GSSharesRequest $gsSharesRequest |
|
67
|
|
|
*/ |
|
68
|
|
|
public function __construct( |
|
69
|
|
|
MountManager $mountManager, ICloudIdManager $cloudIdManager, GSSharesRequest $gsSharesRequest |
|
70
|
|
|
) { |
|
71
|
|
|
$this->mountManager = $mountManager; |
|
72
|
|
|
$this->cloudIdManager = $cloudIdManager; |
|
73
|
|
|
$this->gsSharesRequest = $gsSharesRequest; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param IUser $user |
|
79
|
|
|
* @param IStorageFactory $loader |
|
80
|
|
|
* |
|
81
|
|
|
* @return IMountPoint[] |
|
82
|
|
|
* @throws QueryException |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getMountsForUser(IUser $user, IStorageFactory $loader): array { |
|
85
|
|
|
$manager = \OC::$server->query(Manager::class); |
|
86
|
|
|
$shares = $this->gsSharesRequest->getForUser($user->getUID()); |
|
87
|
|
|
|
|
88
|
|
|
$mounts = []; |
|
89
|
|
|
foreach ($shares as $share) { |
|
90
|
|
|
$mounts[] = $this->generateMount($share, $user->getUID(), $manager, $loader); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return $mounts; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param GSShare $share |
|
99
|
|
|
* @param string $userId |
|
100
|
|
|
* @param Manager $manager |
|
101
|
|
|
* @param IStorageFactory $storageFactory |
|
102
|
|
|
* |
|
103
|
|
|
* @return Mount |
|
104
|
|
|
*/ |
|
105
|
|
|
public function generateMount( |
|
106
|
|
|
GSShare $share, string $userId, Manager $manager, IStorageFactory $storageFactory |
|
107
|
|
|
) { |
|
108
|
|
|
$data = $share->toMount($userId, $_SERVER['REQUEST_SCHEME']); |
|
109
|
|
|
$data['manager'] = $manager; |
|
110
|
|
|
$data['cloudId'] = $this->cloudIdManager->getCloudId($data['owner'], $data['remote']); |
|
111
|
|
|
$data['certificateManager'] = \OC::$server->getCertificateManager($userId); |
|
112
|
|
|
$data['HttpClientService'] = \OC::$server->getHTTPClientService(); |
|
113
|
|
|
|
|
114
|
|
|
return new Mount(self::STORAGE, $share->getMountPoint($userId), $data, $manager, $storageFactory); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: