@@ -45,105 +45,105 @@ |
||
45 | 45 | */ |
46 | 46 | class RetryJob extends Job { |
47 | 47 | |
48 | - /** @var bool */ |
|
49 | - private $retainJob = true; |
|
50 | - |
|
51 | - /** @var Notifications */ |
|
52 | - private $notifications; |
|
53 | - |
|
54 | - /** @var int max number of attempts to send the request */ |
|
55 | - private $maxTry = 20; |
|
56 | - |
|
57 | - /** @var int how much time should be between two tries (10 minutes) */ |
|
58 | - private $interval = 600; |
|
59 | - |
|
60 | - /** |
|
61 | - * UnShare constructor. |
|
62 | - * |
|
63 | - * @param Notifications $notifications |
|
64 | - */ |
|
65 | - public function __construct(Notifications $notifications = null) { |
|
66 | - if ($notifications) { |
|
67 | - $this->notifications = $notifications; |
|
68 | - } else { |
|
69 | - $addressHandler = new AddressHandler( |
|
70 | - \OC::$server->getURLGenerator(), |
|
71 | - \OC::$server->getL10N('federatedfilesharing'), |
|
72 | - \OC::$server->getCloudIdManager() |
|
73 | - ); |
|
74 | - $this->notifications = new Notifications( |
|
75 | - $addressHandler, |
|
76 | - \OC::$server->getHTTPClientService(), |
|
77 | - \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
78 | - \OC::$server->getJobList(), |
|
79 | - \OC::$server->getCloudFederationProviderManager(), |
|
80 | - \OC::$server->getCloudFederationFactory() |
|
81 | - ); |
|
82 | - } |
|
83 | - |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * run the job, then remove it from the jobList |
|
88 | - * |
|
89 | - * @param JobList $jobList |
|
90 | - * @param ILogger|null $logger |
|
91 | - */ |
|
92 | - public function execute($jobList, ILogger $logger = null) { |
|
93 | - |
|
94 | - if ($this->shouldRun($this->argument)) { |
|
95 | - parent::execute($jobList, $logger); |
|
96 | - $jobList->remove($this, $this->argument); |
|
97 | - if ($this->retainJob) { |
|
98 | - $this->reAddJob($jobList, $this->argument); |
|
99 | - } |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - protected function run($argument) { |
|
104 | - $remote = $argument['remote']; |
|
105 | - $remoteId = $argument['remoteId']; |
|
106 | - $token = $argument['token']; |
|
107 | - $action = $argument['action']; |
|
108 | - $data = json_decode($argument['data'], true); |
|
109 | - $try = (int)$argument['try'] + 1; |
|
110 | - |
|
111 | - $result = $this->notifications->sendUpdateToRemote($remote, $remoteId, $token, $action, $data, $try); |
|
112 | - |
|
113 | - if ($result === true || $try > $this->maxTry) { |
|
114 | - $this->retainJob = false; |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * re-add background job with new arguments |
|
120 | - * |
|
121 | - * @param IJobList $jobList |
|
122 | - * @param array $argument |
|
123 | - */ |
|
124 | - protected function reAddJob(IJobList $jobList, array $argument) { |
|
125 | - $jobList->add(RetryJob::class, |
|
126 | - [ |
|
127 | - 'remote' => $argument['remote'], |
|
128 | - 'remoteId' => $argument['remoteId'], |
|
129 | - 'token' => $argument['token'], |
|
130 | - 'data' => $argument['data'], |
|
131 | - 'action' => $argument['action'], |
|
132 | - 'try' => (int)$argument['try'] + 1, |
|
133 | - 'lastRun' => time() |
|
134 | - ] |
|
135 | - ); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * test if it is time for the next run |
|
140 | - * |
|
141 | - * @param array $argument |
|
142 | - * @return bool |
|
143 | - */ |
|
144 | - protected function shouldRun(array $argument) { |
|
145 | - $lastRun = (int)$argument['lastRun']; |
|
146 | - return ((time() - $lastRun) > $this->interval); |
|
147 | - } |
|
48 | + /** @var bool */ |
|
49 | + private $retainJob = true; |
|
50 | + |
|
51 | + /** @var Notifications */ |
|
52 | + private $notifications; |
|
53 | + |
|
54 | + /** @var int max number of attempts to send the request */ |
|
55 | + private $maxTry = 20; |
|
56 | + |
|
57 | + /** @var int how much time should be between two tries (10 minutes) */ |
|
58 | + private $interval = 600; |
|
59 | + |
|
60 | + /** |
|
61 | + * UnShare constructor. |
|
62 | + * |
|
63 | + * @param Notifications $notifications |
|
64 | + */ |
|
65 | + public function __construct(Notifications $notifications = null) { |
|
66 | + if ($notifications) { |
|
67 | + $this->notifications = $notifications; |
|
68 | + } else { |
|
69 | + $addressHandler = new AddressHandler( |
|
70 | + \OC::$server->getURLGenerator(), |
|
71 | + \OC::$server->getL10N('federatedfilesharing'), |
|
72 | + \OC::$server->getCloudIdManager() |
|
73 | + ); |
|
74 | + $this->notifications = new Notifications( |
|
75 | + $addressHandler, |
|
76 | + \OC::$server->getHTTPClientService(), |
|
77 | + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
78 | + \OC::$server->getJobList(), |
|
79 | + \OC::$server->getCloudFederationProviderManager(), |
|
80 | + \OC::$server->getCloudFederationFactory() |
|
81 | + ); |
|
82 | + } |
|
83 | + |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * run the job, then remove it from the jobList |
|
88 | + * |
|
89 | + * @param JobList $jobList |
|
90 | + * @param ILogger|null $logger |
|
91 | + */ |
|
92 | + public function execute($jobList, ILogger $logger = null) { |
|
93 | + |
|
94 | + if ($this->shouldRun($this->argument)) { |
|
95 | + parent::execute($jobList, $logger); |
|
96 | + $jobList->remove($this, $this->argument); |
|
97 | + if ($this->retainJob) { |
|
98 | + $this->reAddJob($jobList, $this->argument); |
|
99 | + } |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + protected function run($argument) { |
|
104 | + $remote = $argument['remote']; |
|
105 | + $remoteId = $argument['remoteId']; |
|
106 | + $token = $argument['token']; |
|
107 | + $action = $argument['action']; |
|
108 | + $data = json_decode($argument['data'], true); |
|
109 | + $try = (int)$argument['try'] + 1; |
|
110 | + |
|
111 | + $result = $this->notifications->sendUpdateToRemote($remote, $remoteId, $token, $action, $data, $try); |
|
112 | + |
|
113 | + if ($result === true || $try > $this->maxTry) { |
|
114 | + $this->retainJob = false; |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * re-add background job with new arguments |
|
120 | + * |
|
121 | + * @param IJobList $jobList |
|
122 | + * @param array $argument |
|
123 | + */ |
|
124 | + protected function reAddJob(IJobList $jobList, array $argument) { |
|
125 | + $jobList->add(RetryJob::class, |
|
126 | + [ |
|
127 | + 'remote' => $argument['remote'], |
|
128 | + 'remoteId' => $argument['remoteId'], |
|
129 | + 'token' => $argument['token'], |
|
130 | + 'data' => $argument['data'], |
|
131 | + 'action' => $argument['action'], |
|
132 | + 'try' => (int)$argument['try'] + 1, |
|
133 | + 'lastRun' => time() |
|
134 | + ] |
|
135 | + ); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * test if it is time for the next run |
|
140 | + * |
|
141 | + * @param array $argument |
|
142 | + * @return bool |
|
143 | + */ |
|
144 | + protected function shouldRun(array $argument) { |
|
145 | + $lastRun = (int)$argument['lastRun']; |
|
146 | + return ((time() - $lastRun) > $this->interval); |
|
147 | + } |
|
148 | 148 | |
149 | 149 | } |
@@ -131,18 +131,18 @@ discard block |
||
131 | 131 | * @param int $remoteId |
132 | 132 | * @return Mount|null |
133 | 133 | */ |
134 | - public function addShare($remote, $token, $password, $name, $owner, $accepted=false, $user = null, $remoteId = -1) { |
|
134 | + public function addShare($remote, $token, $password, $name, $owner, $accepted = false, $user = null, $remoteId = -1) { |
|
135 | 135 | |
136 | 136 | $user = $user ? $user : $this->uid; |
137 | 137 | $accepted = $accepted ? 1 : 0; |
138 | - $name = Filesystem::normalizePath('/' . $name); |
|
138 | + $name = Filesystem::normalizePath('/'.$name); |
|
139 | 139 | |
140 | 140 | if (!$accepted) { |
141 | 141 | // To avoid conflicts with the mount point generation later, |
142 | 142 | // we only use a temporary mount point name here. The real |
143 | 143 | // mount point name will be generated when accepting the share, |
144 | 144 | // using the original share item name. |
145 | - $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
145 | + $tmpMountPointName = '{{TemporaryMountPointName#'.$name.'}}'; |
|
146 | 146 | $mountPoint = $tmpMountPointName; |
147 | 147 | $hash = md5($tmpMountPointName); |
148 | 148 | $data = [ |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | $i = 1; |
162 | 162 | while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
163 | 163 | // The external share already exists for the user |
164 | - $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
164 | + $data['mountpoint'] = $tmpMountPointName.'-'.$i; |
|
165 | 165 | $data['mountpoint_hash'] = md5($data['mountpoint']); |
166 | 166 | $i++; |
167 | 167 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | } |
170 | 170 | |
171 | 171 | $mountPoint = Files::buildNotExistingFileName('/', $name); |
172 | - $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
172 | + $mountPoint = Filesystem::normalizePath('/'.$mountPoint); |
|
173 | 173 | $hash = md5($mountPoint); |
174 | 174 | |
175 | 175 | $query = $this->connection->prepare(' |
@@ -290,14 +290,14 @@ discard block |
||
290 | 290 | |
291 | 291 | $result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback); |
292 | 292 | |
293 | - if($result === true) { |
|
293 | + if ($result === true) { |
|
294 | 294 | return true; |
295 | 295 | } |
296 | 296 | |
297 | 297 | $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING'); |
298 | 298 | $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
299 | 299 | |
300 | - $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; |
|
300 | + $url = rtrim($remote, '/').$endpoint.'/'.$remoteId.'/'.$feedback.'?format='.\OCP\Share::RESPONSE_FORMAT; |
|
301 | 301 | $fields = array('token' => $token); |
302 | 302 | |
303 | 303 | $client = $this->clientService->newClient(); |
@@ -354,13 +354,13 @@ discard block |
||
354 | 354 | * @return string |
355 | 355 | */ |
356 | 356 | protected function stripPath($path) { |
357 | - $prefix = '/' . $this->uid . '/files'; |
|
357 | + $prefix = '/'.$this->uid.'/files'; |
|
358 | 358 | return rtrim(substr($path, strlen($prefix)), '/'); |
359 | 359 | } |
360 | 360 | |
361 | 361 | public function getMount($data) { |
362 | 362 | $data['manager'] = $this; |
363 | - $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
363 | + $mountPoint = '/'.$this->uid.'/files'.$data['mountpoint']; |
|
364 | 364 | $data['mountpoint'] = $mountPoint; |
365 | 365 | $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
366 | 366 | return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | WHERE `mountpoint_hash` = ? |
401 | 401 | AND `user` = ? |
402 | 402 | '); |
403 | - $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
403 | + $result = (bool) $query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
404 | 404 | |
405 | 405 | return $result; |
406 | 406 | } |
@@ -435,9 +435,9 @@ discard block |
||
435 | 435 | WHERE `mountpoint_hash` = ? |
436 | 436 | AND `user` = ? |
437 | 437 | '); |
438 | - $result = (bool)$query->execute(array($hash, $this->uid)); |
|
438 | + $result = (bool) $query->execute(array($hash, $this->uid)); |
|
439 | 439 | |
440 | - if($result) { |
|
440 | + if ($result) { |
|
441 | 441 | $this->removeReShares($id); |
442 | 442 | } |
443 | 443 | |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | |
459 | 459 | |
460 | 460 | $query->delete('federated_reshares') |
461 | - ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
461 | + ->where($query->expr()->in('share_id', $query->createFunction('('.$select.')'))); |
|
462 | 462 | $query->execute(); |
463 | 463 | |
464 | 464 | $deleteReShares = $this->connection->getQueryBuilder(); |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | |
483 | 483 | if ($result) { |
484 | 484 | $shares = $getShare->fetchAll(); |
485 | - foreach($shares as $share) { |
|
485 | + foreach ($shares as $share) { |
|
486 | 486 | $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
487 | 487 | } |
488 | 488 | } |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | DELETE FROM `*PREFIX*share_external` |
492 | 492 | WHERE `user` = ? |
493 | 493 | '); |
494 | - return (bool)$query->execute(array($uid)); |
|
494 | + return (bool) $query->execute(array($uid)); |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | /** |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | * |
325 | 325 | * @param string $remoteDomain |
326 | 326 | * @param string $token |
327 | - * @param $remoteId id of the share |
|
327 | + * @param integer $remoteId id of the share |
|
328 | 328 | * @param string $feedback |
329 | 329 | * @return bool |
330 | 330 | */ |
@@ -421,6 +421,9 @@ discard block |
||
421 | 421 | return $result; |
422 | 422 | } |
423 | 423 | |
424 | + /** |
|
425 | + * @param string $mountPoint |
|
426 | + */ |
|
424 | 427 | public function removeShare($mountPoint) { |
425 | 428 | |
426 | 429 | $mountPointObj = $this->mountManager->find($mountPoint); |
@@ -44,512 +44,512 @@ |
||
44 | 44 | use OCP\Share; |
45 | 45 | |
46 | 46 | class Manager { |
47 | - const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - private $uid; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var IDBConnection |
|
56 | - */ |
|
57 | - private $connection; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var \OC\Files\Mount\Manager |
|
61 | - */ |
|
62 | - private $mountManager; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var IStorageFactory |
|
66 | - */ |
|
67 | - private $storageLoader; |
|
68 | - |
|
69 | - /** |
|
70 | - * @var IClientService |
|
71 | - */ |
|
72 | - private $clientService; |
|
73 | - |
|
74 | - /** |
|
75 | - * @var IManager |
|
76 | - */ |
|
77 | - private $notificationManager; |
|
78 | - |
|
79 | - /** |
|
80 | - * @var IDiscoveryService |
|
81 | - */ |
|
82 | - private $discoveryService; |
|
83 | - |
|
84 | - /** @var ICloudFederationProviderManager */ |
|
85 | - private $cloudFederationProviderManager; |
|
86 | - |
|
87 | - /** @var ICloudFederationFactory */ |
|
88 | - private $cloudFederationFactory; |
|
89 | - |
|
90 | - /** |
|
91 | - * @param IDBConnection $connection |
|
92 | - * @param \OC\Files\Mount\Manager $mountManager |
|
93 | - * @param IStorageFactory $storageLoader |
|
94 | - * @param IClientService $clientService |
|
95 | - * @param IManager $notificationManager |
|
96 | - * @param IDiscoveryService $discoveryService |
|
97 | - * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
98 | - * @param ICloudFederationFactory $cloudFederationFactory |
|
99 | - * @param string $uid |
|
100 | - */ |
|
101 | - public function __construct(IDBConnection $connection, |
|
102 | - \OC\Files\Mount\Manager $mountManager, |
|
103 | - IStorageFactory $storageLoader, |
|
104 | - IClientService $clientService, |
|
105 | - IManager $notificationManager, |
|
106 | - IDiscoveryService $discoveryService, |
|
107 | - ICloudFederationProviderManager $cloudFederationProviderManager, |
|
108 | - ICloudFederationFactory $cloudFederationFactory, |
|
109 | - $uid) { |
|
110 | - $this->connection = $connection; |
|
111 | - $this->mountManager = $mountManager; |
|
112 | - $this->storageLoader = $storageLoader; |
|
113 | - $this->clientService = $clientService; |
|
114 | - $this->uid = $uid; |
|
115 | - $this->notificationManager = $notificationManager; |
|
116 | - $this->discoveryService = $discoveryService; |
|
117 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
118 | - $this->cloudFederationFactory = $cloudFederationFactory; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * add new server-to-server share |
|
123 | - * |
|
124 | - * @param string $remote |
|
125 | - * @param string $token |
|
126 | - * @param string $password |
|
127 | - * @param string $name |
|
128 | - * @param string $owner |
|
129 | - * @param boolean $accepted |
|
130 | - * @param string $user |
|
131 | - * @param int $remoteId |
|
132 | - * @return Mount|null |
|
133 | - */ |
|
134 | - public function addShare($remote, $token, $password, $name, $owner, $accepted=false, $user = null, $remoteId = -1) { |
|
135 | - |
|
136 | - $user = $user ? $user : $this->uid; |
|
137 | - $accepted = $accepted ? 1 : 0; |
|
138 | - $name = Filesystem::normalizePath('/' . $name); |
|
139 | - |
|
140 | - if (!$accepted) { |
|
141 | - // To avoid conflicts with the mount point generation later, |
|
142 | - // we only use a temporary mount point name here. The real |
|
143 | - // mount point name will be generated when accepting the share, |
|
144 | - // using the original share item name. |
|
145 | - $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
146 | - $mountPoint = $tmpMountPointName; |
|
147 | - $hash = md5($tmpMountPointName); |
|
148 | - $data = [ |
|
149 | - 'remote' => $remote, |
|
150 | - 'share_token' => $token, |
|
151 | - 'password' => $password, |
|
152 | - 'name' => $name, |
|
153 | - 'owner' => $owner, |
|
154 | - 'user' => $user, |
|
155 | - 'mountpoint' => $mountPoint, |
|
156 | - 'mountpoint_hash' => $hash, |
|
157 | - 'accepted' => $accepted, |
|
158 | - 'remote_id' => $remoteId, |
|
159 | - ]; |
|
160 | - |
|
161 | - $i = 1; |
|
162 | - while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
|
163 | - // The external share already exists for the user |
|
164 | - $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
165 | - $data['mountpoint_hash'] = md5($data['mountpoint']); |
|
166 | - $i++; |
|
167 | - } |
|
168 | - return null; |
|
169 | - } |
|
170 | - |
|
171 | - $mountPoint = Files::buildNotExistingFileName('/', $name); |
|
172 | - $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
173 | - $hash = md5($mountPoint); |
|
174 | - |
|
175 | - $query = $this->connection->prepare(' |
|
47 | + const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + private $uid; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var IDBConnection |
|
56 | + */ |
|
57 | + private $connection; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var \OC\Files\Mount\Manager |
|
61 | + */ |
|
62 | + private $mountManager; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var IStorageFactory |
|
66 | + */ |
|
67 | + private $storageLoader; |
|
68 | + |
|
69 | + /** |
|
70 | + * @var IClientService |
|
71 | + */ |
|
72 | + private $clientService; |
|
73 | + |
|
74 | + /** |
|
75 | + * @var IManager |
|
76 | + */ |
|
77 | + private $notificationManager; |
|
78 | + |
|
79 | + /** |
|
80 | + * @var IDiscoveryService |
|
81 | + */ |
|
82 | + private $discoveryService; |
|
83 | + |
|
84 | + /** @var ICloudFederationProviderManager */ |
|
85 | + private $cloudFederationProviderManager; |
|
86 | + |
|
87 | + /** @var ICloudFederationFactory */ |
|
88 | + private $cloudFederationFactory; |
|
89 | + |
|
90 | + /** |
|
91 | + * @param IDBConnection $connection |
|
92 | + * @param \OC\Files\Mount\Manager $mountManager |
|
93 | + * @param IStorageFactory $storageLoader |
|
94 | + * @param IClientService $clientService |
|
95 | + * @param IManager $notificationManager |
|
96 | + * @param IDiscoveryService $discoveryService |
|
97 | + * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
98 | + * @param ICloudFederationFactory $cloudFederationFactory |
|
99 | + * @param string $uid |
|
100 | + */ |
|
101 | + public function __construct(IDBConnection $connection, |
|
102 | + \OC\Files\Mount\Manager $mountManager, |
|
103 | + IStorageFactory $storageLoader, |
|
104 | + IClientService $clientService, |
|
105 | + IManager $notificationManager, |
|
106 | + IDiscoveryService $discoveryService, |
|
107 | + ICloudFederationProviderManager $cloudFederationProviderManager, |
|
108 | + ICloudFederationFactory $cloudFederationFactory, |
|
109 | + $uid) { |
|
110 | + $this->connection = $connection; |
|
111 | + $this->mountManager = $mountManager; |
|
112 | + $this->storageLoader = $storageLoader; |
|
113 | + $this->clientService = $clientService; |
|
114 | + $this->uid = $uid; |
|
115 | + $this->notificationManager = $notificationManager; |
|
116 | + $this->discoveryService = $discoveryService; |
|
117 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
118 | + $this->cloudFederationFactory = $cloudFederationFactory; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * add new server-to-server share |
|
123 | + * |
|
124 | + * @param string $remote |
|
125 | + * @param string $token |
|
126 | + * @param string $password |
|
127 | + * @param string $name |
|
128 | + * @param string $owner |
|
129 | + * @param boolean $accepted |
|
130 | + * @param string $user |
|
131 | + * @param int $remoteId |
|
132 | + * @return Mount|null |
|
133 | + */ |
|
134 | + public function addShare($remote, $token, $password, $name, $owner, $accepted=false, $user = null, $remoteId = -1) { |
|
135 | + |
|
136 | + $user = $user ? $user : $this->uid; |
|
137 | + $accepted = $accepted ? 1 : 0; |
|
138 | + $name = Filesystem::normalizePath('/' . $name); |
|
139 | + |
|
140 | + if (!$accepted) { |
|
141 | + // To avoid conflicts with the mount point generation later, |
|
142 | + // we only use a temporary mount point name here. The real |
|
143 | + // mount point name will be generated when accepting the share, |
|
144 | + // using the original share item name. |
|
145 | + $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
146 | + $mountPoint = $tmpMountPointName; |
|
147 | + $hash = md5($tmpMountPointName); |
|
148 | + $data = [ |
|
149 | + 'remote' => $remote, |
|
150 | + 'share_token' => $token, |
|
151 | + 'password' => $password, |
|
152 | + 'name' => $name, |
|
153 | + 'owner' => $owner, |
|
154 | + 'user' => $user, |
|
155 | + 'mountpoint' => $mountPoint, |
|
156 | + 'mountpoint_hash' => $hash, |
|
157 | + 'accepted' => $accepted, |
|
158 | + 'remote_id' => $remoteId, |
|
159 | + ]; |
|
160 | + |
|
161 | + $i = 1; |
|
162 | + while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
|
163 | + // The external share already exists for the user |
|
164 | + $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
165 | + $data['mountpoint_hash'] = md5($data['mountpoint']); |
|
166 | + $i++; |
|
167 | + } |
|
168 | + return null; |
|
169 | + } |
|
170 | + |
|
171 | + $mountPoint = Files::buildNotExistingFileName('/', $name); |
|
172 | + $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
173 | + $hash = md5($mountPoint); |
|
174 | + |
|
175 | + $query = $this->connection->prepare(' |
|
176 | 176 | INSERT INTO `*PREFIX*share_external` |
177 | 177 | (`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `accepted`, `remote_id`) |
178 | 178 | VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
179 | 179 | '); |
180 | - $query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId)); |
|
181 | - |
|
182 | - $options = array( |
|
183 | - 'remote' => $remote, |
|
184 | - 'token' => $token, |
|
185 | - 'password' => $password, |
|
186 | - 'mountpoint' => $mountPoint, |
|
187 | - 'owner' => $owner |
|
188 | - ); |
|
189 | - return $this->mountShare($options); |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * get share |
|
194 | - * |
|
195 | - * @param int $id share id |
|
196 | - * @return mixed share of false |
|
197 | - */ |
|
198 | - public function getShare($id) { |
|
199 | - $getShare = $this->connection->prepare(' |
|
180 | + $query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId)); |
|
181 | + |
|
182 | + $options = array( |
|
183 | + 'remote' => $remote, |
|
184 | + 'token' => $token, |
|
185 | + 'password' => $password, |
|
186 | + 'mountpoint' => $mountPoint, |
|
187 | + 'owner' => $owner |
|
188 | + ); |
|
189 | + return $this->mountShare($options); |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * get share |
|
194 | + * |
|
195 | + * @param int $id share id |
|
196 | + * @return mixed share of false |
|
197 | + */ |
|
198 | + public function getShare($id) { |
|
199 | + $getShare = $this->connection->prepare(' |
|
200 | 200 | SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
201 | 201 | FROM `*PREFIX*share_external` |
202 | 202 | WHERE `id` = ? AND `user` = ?'); |
203 | - $result = $getShare->execute(array($id, $this->uid)); |
|
204 | - |
|
205 | - return $result ? $getShare->fetch() : false; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * accept server-to-server share |
|
210 | - * |
|
211 | - * @param int $id |
|
212 | - * @return bool True if the share could be accepted, false otherwise |
|
213 | - */ |
|
214 | - public function acceptShare($id) { |
|
215 | - |
|
216 | - $share = $this->getShare($id); |
|
217 | - $result = false; |
|
218 | - |
|
219 | - if ($share) { |
|
220 | - \OC_Util::setupFS($this->uid); |
|
221 | - $shareFolder = Helper::getShareFolder(); |
|
222 | - $mountPoint = Files::buildNotExistingFileName($shareFolder, $share['name']); |
|
223 | - $mountPoint = Filesystem::normalizePath($mountPoint); |
|
224 | - $hash = md5($mountPoint); |
|
225 | - |
|
226 | - $acceptShare = $this->connection->prepare(' |
|
203 | + $result = $getShare->execute(array($id, $this->uid)); |
|
204 | + |
|
205 | + return $result ? $getShare->fetch() : false; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * accept server-to-server share |
|
210 | + * |
|
211 | + * @param int $id |
|
212 | + * @return bool True if the share could be accepted, false otherwise |
|
213 | + */ |
|
214 | + public function acceptShare($id) { |
|
215 | + |
|
216 | + $share = $this->getShare($id); |
|
217 | + $result = false; |
|
218 | + |
|
219 | + if ($share) { |
|
220 | + \OC_Util::setupFS($this->uid); |
|
221 | + $shareFolder = Helper::getShareFolder(); |
|
222 | + $mountPoint = Files::buildNotExistingFileName($shareFolder, $share['name']); |
|
223 | + $mountPoint = Filesystem::normalizePath($mountPoint); |
|
224 | + $hash = md5($mountPoint); |
|
225 | + |
|
226 | + $acceptShare = $this->connection->prepare(' |
|
227 | 227 | UPDATE `*PREFIX*share_external` |
228 | 228 | SET `accepted` = ?, |
229 | 229 | `mountpoint` = ?, |
230 | 230 | `mountpoint_hash` = ? |
231 | 231 | WHERE `id` = ? AND `user` = ?'); |
232 | - $updated = $acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid)); |
|
233 | - if ($updated === true) { |
|
234 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); |
|
235 | - \OC_Hook::emit(Share::class, 'federated_share_added', ['server' => $share['remote']]); |
|
236 | - $result = true; |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - // Make sure the user has no notification for something that does not exist anymore. |
|
241 | - $this->processNotification($id); |
|
242 | - |
|
243 | - return $result; |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * decline server-to-server share |
|
248 | - * |
|
249 | - * @param int $id |
|
250 | - * @return bool True if the share could be declined, false otherwise |
|
251 | - */ |
|
252 | - public function declineShare($id) { |
|
253 | - |
|
254 | - $share = $this->getShare($id); |
|
255 | - |
|
256 | - if ($share) { |
|
257 | - $removeShare = $this->connection->prepare(' |
|
232 | + $updated = $acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid)); |
|
233 | + if ($updated === true) { |
|
234 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); |
|
235 | + \OC_Hook::emit(Share::class, 'federated_share_added', ['server' => $share['remote']]); |
|
236 | + $result = true; |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + // Make sure the user has no notification for something that does not exist anymore. |
|
241 | + $this->processNotification($id); |
|
242 | + |
|
243 | + return $result; |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * decline server-to-server share |
|
248 | + * |
|
249 | + * @param int $id |
|
250 | + * @return bool True if the share could be declined, false otherwise |
|
251 | + */ |
|
252 | + public function declineShare($id) { |
|
253 | + |
|
254 | + $share = $this->getShare($id); |
|
255 | + |
|
256 | + if ($share) { |
|
257 | + $removeShare = $this->connection->prepare(' |
|
258 | 258 | DELETE FROM `*PREFIX*share_external` WHERE `id` = ? AND `user` = ?'); |
259 | - $removeShare->execute(array($id, $this->uid)); |
|
260 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
261 | - |
|
262 | - $this->processNotification($id); |
|
263 | - return true; |
|
264 | - } |
|
265 | - |
|
266 | - return false; |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * @param int $remoteShare |
|
271 | - */ |
|
272 | - public function processNotification($remoteShare) { |
|
273 | - $filter = $this->notificationManager->createNotification(); |
|
274 | - $filter->setApp('files_sharing') |
|
275 | - ->setUser($this->uid) |
|
276 | - ->setObject('remote_share', (int) $remoteShare); |
|
277 | - $this->notificationManager->markProcessed($filter); |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * inform remote server whether server-to-server share was accepted/declined |
|
282 | - * |
|
283 | - * @param string $remote |
|
284 | - * @param string $token |
|
285 | - * @param int $remoteId Share id on the remote host |
|
286 | - * @param string $feedback |
|
287 | - * @return boolean |
|
288 | - */ |
|
289 | - private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { |
|
290 | - |
|
291 | - $result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback); |
|
292 | - |
|
293 | - if($result === true) { |
|
294 | - return true; |
|
295 | - } |
|
296 | - |
|
297 | - $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING'); |
|
298 | - $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
299 | - |
|
300 | - $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; |
|
301 | - $fields = array('token' => $token); |
|
302 | - |
|
303 | - $client = $this->clientService->newClient(); |
|
304 | - |
|
305 | - try { |
|
306 | - $response = $client->post( |
|
307 | - $url, |
|
308 | - [ |
|
309 | - 'body' => $fields, |
|
310 | - 'connect_timeout' => 10, |
|
311 | - ] |
|
312 | - ); |
|
313 | - } catch (\Exception $e) { |
|
314 | - return false; |
|
315 | - } |
|
316 | - |
|
317 | - $status = json_decode($response->getBody(), true); |
|
318 | - |
|
319 | - return ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * try send accept message to ocm end-point |
|
324 | - * |
|
325 | - * @param string $remoteDomain |
|
326 | - * @param string $token |
|
327 | - * @param $remoteId id of the share |
|
328 | - * @param string $feedback |
|
329 | - * @return bool |
|
330 | - */ |
|
331 | - protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) { |
|
332 | - switch ($feedback) { |
|
333 | - case 'accept': |
|
334 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
335 | - $notification->setMessage( |
|
336 | - 'SHARE_ACCEPTED', |
|
337 | - 'file', |
|
338 | - $remoteId, |
|
339 | - [ |
|
340 | - 'sharedSecret' => $token, |
|
341 | - 'message' => 'Recipient accept the share' |
|
342 | - ] |
|
343 | - |
|
344 | - ); |
|
345 | - return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
346 | - case 'decline': |
|
347 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
348 | - $notification->setMessage( |
|
349 | - 'SHARE_DECLINED', |
|
350 | - 'file', |
|
351 | - $remoteId, |
|
352 | - [ |
|
353 | - 'sharedSecret' => $token, |
|
354 | - 'message' => 'Recipient declined the share' |
|
355 | - ] |
|
356 | - |
|
357 | - ); |
|
358 | - return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
359 | - } |
|
360 | - |
|
361 | - return false; |
|
362 | - |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - /** |
|
367 | - * remove '/user/files' from the path and trailing slashes |
|
368 | - * |
|
369 | - * @param string $path |
|
370 | - * @return string |
|
371 | - */ |
|
372 | - protected function stripPath($path) { |
|
373 | - $prefix = '/' . $this->uid . '/files'; |
|
374 | - return rtrim(substr($path, strlen($prefix)), '/'); |
|
375 | - } |
|
376 | - |
|
377 | - public function getMount($data) { |
|
378 | - $data['manager'] = $this; |
|
379 | - $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
380 | - $data['mountpoint'] = $mountPoint; |
|
381 | - $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
|
382 | - return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * @param array $data |
|
387 | - * @return Mount |
|
388 | - */ |
|
389 | - protected function mountShare($data) { |
|
390 | - $mount = $this->getMount($data); |
|
391 | - $this->mountManager->addMount($mount); |
|
392 | - return $mount; |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * @return \OC\Files\Mount\Manager |
|
397 | - */ |
|
398 | - public function getMountManager() { |
|
399 | - return $this->mountManager; |
|
400 | - } |
|
401 | - |
|
402 | - /** |
|
403 | - * @param string $source |
|
404 | - * @param string $target |
|
405 | - * @return bool |
|
406 | - */ |
|
407 | - public function setMountPoint($source, $target) { |
|
408 | - $source = $this->stripPath($source); |
|
409 | - $target = $this->stripPath($target); |
|
410 | - $sourceHash = md5($source); |
|
411 | - $targetHash = md5($target); |
|
412 | - |
|
413 | - $query = $this->connection->prepare(' |
|
259 | + $removeShare->execute(array($id, $this->uid)); |
|
260 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
261 | + |
|
262 | + $this->processNotification($id); |
|
263 | + return true; |
|
264 | + } |
|
265 | + |
|
266 | + return false; |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * @param int $remoteShare |
|
271 | + */ |
|
272 | + public function processNotification($remoteShare) { |
|
273 | + $filter = $this->notificationManager->createNotification(); |
|
274 | + $filter->setApp('files_sharing') |
|
275 | + ->setUser($this->uid) |
|
276 | + ->setObject('remote_share', (int) $remoteShare); |
|
277 | + $this->notificationManager->markProcessed($filter); |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * inform remote server whether server-to-server share was accepted/declined |
|
282 | + * |
|
283 | + * @param string $remote |
|
284 | + * @param string $token |
|
285 | + * @param int $remoteId Share id on the remote host |
|
286 | + * @param string $feedback |
|
287 | + * @return boolean |
|
288 | + */ |
|
289 | + private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { |
|
290 | + |
|
291 | + $result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback); |
|
292 | + |
|
293 | + if($result === true) { |
|
294 | + return true; |
|
295 | + } |
|
296 | + |
|
297 | + $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING'); |
|
298 | + $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
299 | + |
|
300 | + $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; |
|
301 | + $fields = array('token' => $token); |
|
302 | + |
|
303 | + $client = $this->clientService->newClient(); |
|
304 | + |
|
305 | + try { |
|
306 | + $response = $client->post( |
|
307 | + $url, |
|
308 | + [ |
|
309 | + 'body' => $fields, |
|
310 | + 'connect_timeout' => 10, |
|
311 | + ] |
|
312 | + ); |
|
313 | + } catch (\Exception $e) { |
|
314 | + return false; |
|
315 | + } |
|
316 | + |
|
317 | + $status = json_decode($response->getBody(), true); |
|
318 | + |
|
319 | + return ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * try send accept message to ocm end-point |
|
324 | + * |
|
325 | + * @param string $remoteDomain |
|
326 | + * @param string $token |
|
327 | + * @param $remoteId id of the share |
|
328 | + * @param string $feedback |
|
329 | + * @return bool |
|
330 | + */ |
|
331 | + protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) { |
|
332 | + switch ($feedback) { |
|
333 | + case 'accept': |
|
334 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
335 | + $notification->setMessage( |
|
336 | + 'SHARE_ACCEPTED', |
|
337 | + 'file', |
|
338 | + $remoteId, |
|
339 | + [ |
|
340 | + 'sharedSecret' => $token, |
|
341 | + 'message' => 'Recipient accept the share' |
|
342 | + ] |
|
343 | + |
|
344 | + ); |
|
345 | + return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
346 | + case 'decline': |
|
347 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
348 | + $notification->setMessage( |
|
349 | + 'SHARE_DECLINED', |
|
350 | + 'file', |
|
351 | + $remoteId, |
|
352 | + [ |
|
353 | + 'sharedSecret' => $token, |
|
354 | + 'message' => 'Recipient declined the share' |
|
355 | + ] |
|
356 | + |
|
357 | + ); |
|
358 | + return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
359 | + } |
|
360 | + |
|
361 | + return false; |
|
362 | + |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + /** |
|
367 | + * remove '/user/files' from the path and trailing slashes |
|
368 | + * |
|
369 | + * @param string $path |
|
370 | + * @return string |
|
371 | + */ |
|
372 | + protected function stripPath($path) { |
|
373 | + $prefix = '/' . $this->uid . '/files'; |
|
374 | + return rtrim(substr($path, strlen($prefix)), '/'); |
|
375 | + } |
|
376 | + |
|
377 | + public function getMount($data) { |
|
378 | + $data['manager'] = $this; |
|
379 | + $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
380 | + $data['mountpoint'] = $mountPoint; |
|
381 | + $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
|
382 | + return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * @param array $data |
|
387 | + * @return Mount |
|
388 | + */ |
|
389 | + protected function mountShare($data) { |
|
390 | + $mount = $this->getMount($data); |
|
391 | + $this->mountManager->addMount($mount); |
|
392 | + return $mount; |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * @return \OC\Files\Mount\Manager |
|
397 | + */ |
|
398 | + public function getMountManager() { |
|
399 | + return $this->mountManager; |
|
400 | + } |
|
401 | + |
|
402 | + /** |
|
403 | + * @param string $source |
|
404 | + * @param string $target |
|
405 | + * @return bool |
|
406 | + */ |
|
407 | + public function setMountPoint($source, $target) { |
|
408 | + $source = $this->stripPath($source); |
|
409 | + $target = $this->stripPath($target); |
|
410 | + $sourceHash = md5($source); |
|
411 | + $targetHash = md5($target); |
|
412 | + |
|
413 | + $query = $this->connection->prepare(' |
|
414 | 414 | UPDATE `*PREFIX*share_external` |
415 | 415 | SET `mountpoint` = ?, `mountpoint_hash` = ? |
416 | 416 | WHERE `mountpoint_hash` = ? |
417 | 417 | AND `user` = ? |
418 | 418 | '); |
419 | - $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
419 | + $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
420 | 420 | |
421 | - return $result; |
|
422 | - } |
|
421 | + return $result; |
|
422 | + } |
|
423 | 423 | |
424 | - public function removeShare($mountPoint) { |
|
424 | + public function removeShare($mountPoint) { |
|
425 | 425 | |
426 | - $mountPointObj = $this->mountManager->find($mountPoint); |
|
427 | - $id = $mountPointObj->getStorage()->getCache()->getId(''); |
|
426 | + $mountPointObj = $this->mountManager->find($mountPoint); |
|
427 | + $id = $mountPointObj->getStorage()->getCache()->getId(''); |
|
428 | 428 | |
429 | - $mountPoint = $this->stripPath($mountPoint); |
|
430 | - $hash = md5($mountPoint); |
|
429 | + $mountPoint = $this->stripPath($mountPoint); |
|
430 | + $hash = md5($mountPoint); |
|
431 | 431 | |
432 | - $getShare = $this->connection->prepare(' |
|
432 | + $getShare = $this->connection->prepare(' |
|
433 | 433 | SELECT `remote`, `share_token`, `remote_id` |
434 | 434 | FROM `*PREFIX*share_external` |
435 | 435 | WHERE `mountpoint_hash` = ? AND `user` = ?'); |
436 | - $result = $getShare->execute(array($hash, $this->uid)); |
|
437 | - |
|
438 | - if ($result) { |
|
439 | - try { |
|
440 | - $share = $getShare->fetch(); |
|
441 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
442 | - } catch (\Exception $e) { |
|
443 | - // if we fail to notify the remote (probably cause the remote is down) |
|
444 | - // we still want the share to be gone to prevent undeletable remotes |
|
445 | - } |
|
446 | - } |
|
447 | - $getShare->closeCursor(); |
|
448 | - |
|
449 | - $query = $this->connection->prepare(' |
|
436 | + $result = $getShare->execute(array($hash, $this->uid)); |
|
437 | + |
|
438 | + if ($result) { |
|
439 | + try { |
|
440 | + $share = $getShare->fetch(); |
|
441 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
442 | + } catch (\Exception $e) { |
|
443 | + // if we fail to notify the remote (probably cause the remote is down) |
|
444 | + // we still want the share to be gone to prevent undeletable remotes |
|
445 | + } |
|
446 | + } |
|
447 | + $getShare->closeCursor(); |
|
448 | + |
|
449 | + $query = $this->connection->prepare(' |
|
450 | 450 | DELETE FROM `*PREFIX*share_external` |
451 | 451 | WHERE `mountpoint_hash` = ? |
452 | 452 | AND `user` = ? |
453 | 453 | '); |
454 | - $result = (bool)$query->execute(array($hash, $this->uid)); |
|
455 | - |
|
456 | - if($result) { |
|
457 | - $this->removeReShares($id); |
|
458 | - } |
|
459 | - |
|
460 | - return $result; |
|
461 | - } |
|
462 | - |
|
463 | - /** |
|
464 | - * remove re-shares from share table and mapping in the federated_reshares table |
|
465 | - * |
|
466 | - * @param $mountPointId |
|
467 | - */ |
|
468 | - protected function removeReShares($mountPointId) { |
|
469 | - $selectQuery = $this->connection->getQueryBuilder(); |
|
470 | - $query = $this->connection->getQueryBuilder(); |
|
471 | - $selectQuery->select('id')->from('share') |
|
472 | - ->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId))); |
|
473 | - $select = $selectQuery->getSQL(); |
|
474 | - |
|
475 | - |
|
476 | - $query->delete('federated_reshares') |
|
477 | - ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
478 | - $query->execute(); |
|
479 | - |
|
480 | - $deleteReShares = $this->connection->getQueryBuilder(); |
|
481 | - $deleteReShares->delete('share') |
|
482 | - ->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId))); |
|
483 | - $deleteReShares->execute(); |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * remove all shares for user $uid if the user was deleted |
|
488 | - * |
|
489 | - * @param string $uid |
|
490 | - * @return bool |
|
491 | - */ |
|
492 | - public function removeUserShares($uid) { |
|
493 | - $getShare = $this->connection->prepare(' |
|
454 | + $result = (bool)$query->execute(array($hash, $this->uid)); |
|
455 | + |
|
456 | + if($result) { |
|
457 | + $this->removeReShares($id); |
|
458 | + } |
|
459 | + |
|
460 | + return $result; |
|
461 | + } |
|
462 | + |
|
463 | + /** |
|
464 | + * remove re-shares from share table and mapping in the federated_reshares table |
|
465 | + * |
|
466 | + * @param $mountPointId |
|
467 | + */ |
|
468 | + protected function removeReShares($mountPointId) { |
|
469 | + $selectQuery = $this->connection->getQueryBuilder(); |
|
470 | + $query = $this->connection->getQueryBuilder(); |
|
471 | + $selectQuery->select('id')->from('share') |
|
472 | + ->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId))); |
|
473 | + $select = $selectQuery->getSQL(); |
|
474 | + |
|
475 | + |
|
476 | + $query->delete('federated_reshares') |
|
477 | + ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
478 | + $query->execute(); |
|
479 | + |
|
480 | + $deleteReShares = $this->connection->getQueryBuilder(); |
|
481 | + $deleteReShares->delete('share') |
|
482 | + ->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId))); |
|
483 | + $deleteReShares->execute(); |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * remove all shares for user $uid if the user was deleted |
|
488 | + * |
|
489 | + * @param string $uid |
|
490 | + * @return bool |
|
491 | + */ |
|
492 | + public function removeUserShares($uid) { |
|
493 | + $getShare = $this->connection->prepare(' |
|
494 | 494 | SELECT `remote`, `share_token`, `remote_id` |
495 | 495 | FROM `*PREFIX*share_external` |
496 | 496 | WHERE `user` = ?'); |
497 | - $result = $getShare->execute(array($uid)); |
|
497 | + $result = $getShare->execute(array($uid)); |
|
498 | 498 | |
499 | - if ($result) { |
|
500 | - $shares = $getShare->fetchAll(); |
|
501 | - foreach($shares as $share) { |
|
502 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
503 | - } |
|
504 | - } |
|
499 | + if ($result) { |
|
500 | + $shares = $getShare->fetchAll(); |
|
501 | + foreach($shares as $share) { |
|
502 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
503 | + } |
|
504 | + } |
|
505 | 505 | |
506 | - $query = $this->connection->prepare(' |
|
506 | + $query = $this->connection->prepare(' |
|
507 | 507 | DELETE FROM `*PREFIX*share_external` |
508 | 508 | WHERE `user` = ? |
509 | 509 | '); |
510 | - return (bool)$query->execute(array($uid)); |
|
511 | - } |
|
512 | - |
|
513 | - /** |
|
514 | - * return a list of shares which are not yet accepted by the user |
|
515 | - * |
|
516 | - * @return array list of open server-to-server shares |
|
517 | - */ |
|
518 | - public function getOpenShares() { |
|
519 | - return $this->getShares(false); |
|
520 | - } |
|
521 | - |
|
522 | - /** |
|
523 | - * return a list of shares which are accepted by the user |
|
524 | - * |
|
525 | - * @return array list of accepted server-to-server shares |
|
526 | - */ |
|
527 | - public function getAcceptedShares() { |
|
528 | - return $this->getShares(true); |
|
529 | - } |
|
530 | - |
|
531 | - /** |
|
532 | - * return a list of shares for the user |
|
533 | - * |
|
534 | - * @param bool|null $accepted True for accepted only, |
|
535 | - * false for not accepted, |
|
536 | - * null for all shares of the user |
|
537 | - * @return array list of open server-to-server shares |
|
538 | - */ |
|
539 | - private function getShares($accepted) { |
|
540 | - $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
|
510 | + return (bool)$query->execute(array($uid)); |
|
511 | + } |
|
512 | + |
|
513 | + /** |
|
514 | + * return a list of shares which are not yet accepted by the user |
|
515 | + * |
|
516 | + * @return array list of open server-to-server shares |
|
517 | + */ |
|
518 | + public function getOpenShares() { |
|
519 | + return $this->getShares(false); |
|
520 | + } |
|
521 | + |
|
522 | + /** |
|
523 | + * return a list of shares which are accepted by the user |
|
524 | + * |
|
525 | + * @return array list of accepted server-to-server shares |
|
526 | + */ |
|
527 | + public function getAcceptedShares() { |
|
528 | + return $this->getShares(true); |
|
529 | + } |
|
530 | + |
|
531 | + /** |
|
532 | + * return a list of shares for the user |
|
533 | + * |
|
534 | + * @param bool|null $accepted True for accepted only, |
|
535 | + * false for not accepted, |
|
536 | + * null for all shares of the user |
|
537 | + * @return array list of open server-to-server shares |
|
538 | + */ |
|
539 | + private function getShares($accepted) { |
|
540 | + $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
|
541 | 541 | FROM `*PREFIX*share_external` |
542 | 542 | WHERE `user` = ?'; |
543 | - $parameters = [$this->uid]; |
|
544 | - if (!is_null($accepted)) { |
|
545 | - $query .= ' AND `accepted` = ?'; |
|
546 | - $parameters[] = (int) $accepted; |
|
547 | - } |
|
548 | - $query .= ' ORDER BY `id` ASC'; |
|
549 | - |
|
550 | - $shares = $this->connection->prepare($query); |
|
551 | - $result = $shares->execute($parameters); |
|
552 | - |
|
553 | - return $result ? $shares->fetchAll() : []; |
|
554 | - } |
|
543 | + $parameters = [$this->uid]; |
|
544 | + if (!is_null($accepted)) { |
|
545 | + $query .= ' AND `accepted` = ?'; |
|
546 | + $parameters[] = (int) $accepted; |
|
547 | + } |
|
548 | + $query .= ' ORDER BY `id` ASC'; |
|
549 | + |
|
550 | + $shares = $this->connection->prepare($query); |
|
551 | + $result = $shares->execute($parameters); |
|
552 | + |
|
553 | + return $result ? $shares->fetchAll() : []; |
|
554 | + } |
|
555 | 555 | } |
@@ -45,136 +45,136 @@ |
||
45 | 45 | use OCA\Files_Sharing\External\Manager; |
46 | 46 | |
47 | 47 | class Application extends App { |
48 | - public function __construct(array $urlParams = array()) { |
|
49 | - parent::__construct('files_sharing', $urlParams); |
|
48 | + public function __construct(array $urlParams = array()) { |
|
49 | + parent::__construct('files_sharing', $urlParams); |
|
50 | 50 | |
51 | - $container = $this->getContainer(); |
|
52 | - /** @var IServerContainer $server */ |
|
53 | - $server = $container->getServer(); |
|
51 | + $container = $this->getContainer(); |
|
52 | + /** @var IServerContainer $server */ |
|
53 | + $server = $container->getServer(); |
|
54 | 54 | |
55 | - /** |
|
56 | - * Controllers |
|
57 | - */ |
|
58 | - $container->registerService('ShareController', function (SimpleContainer $c) use ($server) { |
|
59 | - $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
60 | - return new ShareController( |
|
61 | - $c->query('AppName'), |
|
62 | - $c->query('Request'), |
|
63 | - $server->getConfig(), |
|
64 | - $server->getURLGenerator(), |
|
65 | - $server->getUserManager(), |
|
66 | - $server->getLogger(), |
|
67 | - $server->getActivityManager(), |
|
68 | - $server->getShareManager(), |
|
69 | - $server->getSession(), |
|
70 | - $server->getPreviewManager(), |
|
71 | - $server->getRootFolder(), |
|
72 | - $federatedSharingApp->getFederatedShareProvider(), |
|
73 | - $server->getEventDispatcher(), |
|
74 | - $server->getL10N($c->query('AppName')), |
|
75 | - $server->query(Defaults::class) |
|
76 | - ); |
|
77 | - }); |
|
78 | - $container->registerService('ExternalSharesController', function (SimpleContainer $c) { |
|
79 | - return new ExternalSharesController( |
|
80 | - $c->query('AppName'), |
|
81 | - $c->query('Request'), |
|
82 | - $c->query('ExternalManager'), |
|
83 | - $c->query('HttpClientService') |
|
84 | - ); |
|
85 | - }); |
|
55 | + /** |
|
56 | + * Controllers |
|
57 | + */ |
|
58 | + $container->registerService('ShareController', function (SimpleContainer $c) use ($server) { |
|
59 | + $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
60 | + return new ShareController( |
|
61 | + $c->query('AppName'), |
|
62 | + $c->query('Request'), |
|
63 | + $server->getConfig(), |
|
64 | + $server->getURLGenerator(), |
|
65 | + $server->getUserManager(), |
|
66 | + $server->getLogger(), |
|
67 | + $server->getActivityManager(), |
|
68 | + $server->getShareManager(), |
|
69 | + $server->getSession(), |
|
70 | + $server->getPreviewManager(), |
|
71 | + $server->getRootFolder(), |
|
72 | + $federatedSharingApp->getFederatedShareProvider(), |
|
73 | + $server->getEventDispatcher(), |
|
74 | + $server->getL10N($c->query('AppName')), |
|
75 | + $server->query(Defaults::class) |
|
76 | + ); |
|
77 | + }); |
|
78 | + $container->registerService('ExternalSharesController', function (SimpleContainer $c) { |
|
79 | + return new ExternalSharesController( |
|
80 | + $c->query('AppName'), |
|
81 | + $c->query('Request'), |
|
82 | + $c->query('ExternalManager'), |
|
83 | + $c->query('HttpClientService') |
|
84 | + ); |
|
85 | + }); |
|
86 | 86 | |
87 | - /** |
|
88 | - * Core class wrappers |
|
89 | - */ |
|
90 | - $container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) { |
|
91 | - return $server->getHTTPClientService(); |
|
92 | - }); |
|
93 | - $container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) { |
|
94 | - return $server->getCloudIdManager(); |
|
95 | - }); |
|
96 | - $container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) { |
|
97 | - $user = $server->getUserSession()->getUser(); |
|
98 | - $uid = $user ? $user->getUID() : null; |
|
99 | - return new \OCA\Files_Sharing\External\Manager( |
|
100 | - $server->getDatabaseConnection(), |
|
101 | - \OC\Files\Filesystem::getMountManager(), |
|
102 | - \OC\Files\Filesystem::getLoader(), |
|
103 | - $server->getHTTPClientService(), |
|
104 | - $server->getNotificationManager(), |
|
105 | - $server->query(\OCP\OCS\IDiscoveryService::class), |
|
106 | - $server->getCloudFederationProviderManager(), |
|
107 | - $server->getCloudFederationFactory(), |
|
108 | - $uid |
|
109 | - ); |
|
110 | - }); |
|
111 | - $container->registerAlias(Manager::class, 'ExternalManager'); |
|
87 | + /** |
|
88 | + * Core class wrappers |
|
89 | + */ |
|
90 | + $container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) { |
|
91 | + return $server->getHTTPClientService(); |
|
92 | + }); |
|
93 | + $container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) { |
|
94 | + return $server->getCloudIdManager(); |
|
95 | + }); |
|
96 | + $container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) { |
|
97 | + $user = $server->getUserSession()->getUser(); |
|
98 | + $uid = $user ? $user->getUID() : null; |
|
99 | + return new \OCA\Files_Sharing\External\Manager( |
|
100 | + $server->getDatabaseConnection(), |
|
101 | + \OC\Files\Filesystem::getMountManager(), |
|
102 | + \OC\Files\Filesystem::getLoader(), |
|
103 | + $server->getHTTPClientService(), |
|
104 | + $server->getNotificationManager(), |
|
105 | + $server->query(\OCP\OCS\IDiscoveryService::class), |
|
106 | + $server->getCloudFederationProviderManager(), |
|
107 | + $server->getCloudFederationFactory(), |
|
108 | + $uid |
|
109 | + ); |
|
110 | + }); |
|
111 | + $container->registerAlias(Manager::class, 'ExternalManager'); |
|
112 | 112 | |
113 | - /** |
|
114 | - * Middleware |
|
115 | - */ |
|
116 | - $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) { |
|
117 | - return new SharingCheckMiddleware( |
|
118 | - $c->query('AppName'), |
|
119 | - $server->getConfig(), |
|
120 | - $server->getAppManager(), |
|
121 | - $c['ControllerMethodReflector'], |
|
122 | - $server->getShareManager(), |
|
123 | - $server->getRequest() |
|
124 | - ); |
|
125 | - }); |
|
113 | + /** |
|
114 | + * Middleware |
|
115 | + */ |
|
116 | + $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) { |
|
117 | + return new SharingCheckMiddleware( |
|
118 | + $c->query('AppName'), |
|
119 | + $server->getConfig(), |
|
120 | + $server->getAppManager(), |
|
121 | + $c['ControllerMethodReflector'], |
|
122 | + $server->getShareManager(), |
|
123 | + $server->getRequest() |
|
124 | + ); |
|
125 | + }); |
|
126 | 126 | |
127 | - $container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) { |
|
128 | - return new OCSShareAPIMiddleware( |
|
129 | - $server->getShareManager(), |
|
130 | - $server->getL10N($c->query('AppName')) |
|
131 | - ); |
|
132 | - }); |
|
127 | + $container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) { |
|
128 | + return new OCSShareAPIMiddleware( |
|
129 | + $server->getShareManager(), |
|
130 | + $server->getL10N($c->query('AppName')) |
|
131 | + ); |
|
132 | + }); |
|
133 | 133 | |
134 | - $container->registerService(ShareInfoMiddleware::class, function () use ($server) { |
|
135 | - return new ShareInfoMiddleware( |
|
136 | - $server->getShareManager() |
|
137 | - ); |
|
138 | - }); |
|
134 | + $container->registerService(ShareInfoMiddleware::class, function () use ($server) { |
|
135 | + return new ShareInfoMiddleware( |
|
136 | + $server->getShareManager() |
|
137 | + ); |
|
138 | + }); |
|
139 | 139 | |
140 | - // Execute middlewares |
|
141 | - $container->registerMiddleWare('SharingCheckMiddleware'); |
|
142 | - $container->registerMiddleWare('OCSShareAPIMiddleware'); |
|
143 | - $container->registerMiddleWare(ShareInfoMiddleware::class); |
|
140 | + // Execute middlewares |
|
141 | + $container->registerMiddleWare('SharingCheckMiddleware'); |
|
142 | + $container->registerMiddleWare('OCSShareAPIMiddleware'); |
|
143 | + $container->registerMiddleWare(ShareInfoMiddleware::class); |
|
144 | 144 | |
145 | - $container->registerService('MountProvider', function (IContainer $c) { |
|
146 | - /** @var \OCP\IServerContainer $server */ |
|
147 | - $server = $c->query('ServerContainer'); |
|
148 | - return new MountProvider( |
|
149 | - $server->getConfig(), |
|
150 | - $server->getShareManager(), |
|
151 | - $server->getLogger() |
|
152 | - ); |
|
153 | - }); |
|
145 | + $container->registerService('MountProvider', function (IContainer $c) { |
|
146 | + /** @var \OCP\IServerContainer $server */ |
|
147 | + $server = $c->query('ServerContainer'); |
|
148 | + return new MountProvider( |
|
149 | + $server->getConfig(), |
|
150 | + $server->getShareManager(), |
|
151 | + $server->getLogger() |
|
152 | + ); |
|
153 | + }); |
|
154 | 154 | |
155 | - $container->registerService('ExternalMountProvider', function (IContainer $c) { |
|
156 | - /** @var \OCP\IServerContainer $server */ |
|
157 | - $server = $c->query('ServerContainer'); |
|
158 | - return new \OCA\Files_Sharing\External\MountProvider( |
|
159 | - $server->getDatabaseConnection(), |
|
160 | - function() use ($c) { |
|
161 | - return $c->query('ExternalManager'); |
|
162 | - }, |
|
163 | - $server->getCloudIdManager() |
|
164 | - ); |
|
165 | - }); |
|
155 | + $container->registerService('ExternalMountProvider', function (IContainer $c) { |
|
156 | + /** @var \OCP\IServerContainer $server */ |
|
157 | + $server = $c->query('ServerContainer'); |
|
158 | + return new \OCA\Files_Sharing\External\MountProvider( |
|
159 | + $server->getDatabaseConnection(), |
|
160 | + function() use ($c) { |
|
161 | + return $c->query('ExternalManager'); |
|
162 | + }, |
|
163 | + $server->getCloudIdManager() |
|
164 | + ); |
|
165 | + }); |
|
166 | 166 | |
167 | - /* |
|
167 | + /* |
|
168 | 168 | * Register capabilities |
169 | 169 | */ |
170 | - $container->registerCapability(Capabilities::class); |
|
171 | - } |
|
170 | + $container->registerCapability(Capabilities::class); |
|
171 | + } |
|
172 | 172 | |
173 | - public function registerMountProviders() { |
|
174 | - /** @var \OCP\IServerContainer $server */ |
|
175 | - $server = $this->getContainer()->query('ServerContainer'); |
|
176 | - $mountProviderCollection = $server->getMountProviderCollection(); |
|
177 | - $mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider')); |
|
178 | - $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider')); |
|
179 | - } |
|
173 | + public function registerMountProviders() { |
|
174 | + /** @var \OCP\IServerContainer $server */ |
|
175 | + $server = $this->getContainer()->query('ServerContainer'); |
|
176 | + $mountProviderCollection = $server->getMountProviderCollection(); |
|
177 | + $mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider')); |
|
178 | + $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider')); |
|
179 | + } |
|
180 | 180 | } |
@@ -32,33 +32,33 @@ |
||
32 | 32 | |
33 | 33 | class Hooks { |
34 | 34 | |
35 | - public static function deleteUser($params) { |
|
36 | - $manager = new External\Manager( |
|
37 | - \OC::$server->getDatabaseConnection(), |
|
38 | - \OC\Files\Filesystem::getMountManager(), |
|
39 | - \OC\Files\Filesystem::getLoader(), |
|
40 | - \OC::$server->getHTTPClientService(), |
|
41 | - \OC::$server->getNotificationManager(), |
|
42 | - \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
43 | - \OC::$server->getCloudFederationProviderManager(), |
|
44 | - \OC::$server->getCloudFederationFactory(), |
|
45 | - $params['uid']); |
|
35 | + public static function deleteUser($params) { |
|
36 | + $manager = new External\Manager( |
|
37 | + \OC::$server->getDatabaseConnection(), |
|
38 | + \OC\Files\Filesystem::getMountManager(), |
|
39 | + \OC\Files\Filesystem::getLoader(), |
|
40 | + \OC::$server->getHTTPClientService(), |
|
41 | + \OC::$server->getNotificationManager(), |
|
42 | + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
43 | + \OC::$server->getCloudFederationProviderManager(), |
|
44 | + \OC::$server->getCloudFederationFactory(), |
|
45 | + $params['uid']); |
|
46 | 46 | |
47 | - $manager->removeUserShares($params['uid']); |
|
48 | - } |
|
47 | + $manager->removeUserShares($params['uid']); |
|
48 | + } |
|
49 | 49 | |
50 | - public static function unshareChildren($params) { |
|
51 | - $path = Filesystem::getView()->getAbsolutePath($params['path']); |
|
52 | - $view = new \OC\Files\View('/'); |
|
50 | + public static function unshareChildren($params) { |
|
51 | + $path = Filesystem::getView()->getAbsolutePath($params['path']); |
|
52 | + $view = new \OC\Files\View('/'); |
|
53 | 53 | |
54 | - // find share mount points within $path and unmount them |
|
55 | - $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
56 | - $mountedShares = $mountManager->findIn($path); |
|
57 | - foreach ($mountedShares as $mount) { |
|
58 | - if ($mount->getStorage()->instanceOfStorage(ISharedStorage::class)) { |
|
59 | - $mountPoint = $mount->getMountPoint(); |
|
60 | - $view->unlink($mountPoint); |
|
61 | - } |
|
62 | - } |
|
63 | - } |
|
54 | + // find share mount points within $path and unmount them |
|
55 | + $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
56 | + $mountedShares = $mountManager->findIn($path); |
|
57 | + foreach ($mountedShares as $mount) { |
|
58 | + if ($mount->getStorage()->instanceOfStorage(ISharedStorage::class)) { |
|
59 | + $mountPoint = $mount->getMountPoint(); |
|
60 | + $view->unlink($mountPoint); |
|
61 | + } |
|
62 | + } |
|
63 | + } |
|
64 | 64 | } |
@@ -158,1869 +158,1869 @@ |
||
158 | 158 | * TODO: hookup all manager classes |
159 | 159 | */ |
160 | 160 | class Server extends ServerContainer implements IServerContainer { |
161 | - /** @var string */ |
|
162 | - private $webRoot; |
|
163 | - |
|
164 | - /** |
|
165 | - * @param string $webRoot |
|
166 | - * @param \OC\Config $config |
|
167 | - */ |
|
168 | - public function __construct($webRoot, \OC\Config $config) { |
|
169 | - parent::__construct(); |
|
170 | - $this->webRoot = $webRoot; |
|
171 | - |
|
172 | - // To find out if we are running from CLI or not |
|
173 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
174 | - |
|
175 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
176 | - return $c; |
|
177 | - }); |
|
178 | - |
|
179 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
180 | - $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
181 | - |
|
182 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
183 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
184 | - |
|
185 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
186 | - |
|
187 | - |
|
188 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
189 | - return new PreviewManager( |
|
190 | - $c->getConfig(), |
|
191 | - $c->getRootFolder(), |
|
192 | - $c->getAppDataDir('preview'), |
|
193 | - $c->getEventDispatcher(), |
|
194 | - $c->getSession()->get('user_id') |
|
195 | - ); |
|
196 | - }); |
|
197 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
198 | - |
|
199 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
200 | - return new \OC\Preview\Watcher( |
|
201 | - $c->getAppDataDir('preview') |
|
202 | - ); |
|
203 | - }); |
|
204 | - |
|
205 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
206 | - $view = new View(); |
|
207 | - $util = new Encryption\Util( |
|
208 | - $view, |
|
209 | - $c->getUserManager(), |
|
210 | - $c->getGroupManager(), |
|
211 | - $c->getConfig() |
|
212 | - ); |
|
213 | - return new Encryption\Manager( |
|
214 | - $c->getConfig(), |
|
215 | - $c->getLogger(), |
|
216 | - $c->getL10N('core'), |
|
217 | - new View(), |
|
218 | - $util, |
|
219 | - new ArrayCache() |
|
220 | - ); |
|
221 | - }); |
|
222 | - |
|
223 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
224 | - $util = new Encryption\Util( |
|
225 | - new View(), |
|
226 | - $c->getUserManager(), |
|
227 | - $c->getGroupManager(), |
|
228 | - $c->getConfig() |
|
229 | - ); |
|
230 | - return new Encryption\File( |
|
231 | - $util, |
|
232 | - $c->getRootFolder(), |
|
233 | - $c->getShareManager() |
|
234 | - ); |
|
235 | - }); |
|
236 | - |
|
237 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
238 | - $view = new View(); |
|
239 | - $util = new Encryption\Util( |
|
240 | - $view, |
|
241 | - $c->getUserManager(), |
|
242 | - $c->getGroupManager(), |
|
243 | - $c->getConfig() |
|
244 | - ); |
|
245 | - |
|
246 | - return new Encryption\Keys\Storage($view, $util); |
|
247 | - }); |
|
248 | - $this->registerService('TagMapper', function (Server $c) { |
|
249 | - return new TagMapper($c->getDatabaseConnection()); |
|
250 | - }); |
|
251 | - |
|
252 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
253 | - $tagMapper = $c->query('TagMapper'); |
|
254 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
255 | - }); |
|
256 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
257 | - |
|
258 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
259 | - $config = $c->getConfig(); |
|
260 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
261 | - return new $factoryClass($this); |
|
262 | - }); |
|
263 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
264 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
265 | - }); |
|
266 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
267 | - |
|
268 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
269 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
270 | - }); |
|
271 | - $this->registerService('RootFolder', function (Server $c) { |
|
272 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
273 | - $view = new View(); |
|
274 | - $root = new Root( |
|
275 | - $manager, |
|
276 | - $view, |
|
277 | - null, |
|
278 | - $c->getUserMountCache(), |
|
279 | - $this->getLogger(), |
|
280 | - $this->getUserManager() |
|
281 | - ); |
|
282 | - $connector = new HookConnector($root, $view); |
|
283 | - $connector->viewToNode(); |
|
284 | - |
|
285 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
286 | - $previewConnector->connectWatcher(); |
|
287 | - |
|
288 | - return $root; |
|
289 | - }); |
|
290 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
291 | - |
|
292 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
293 | - return new LazyRoot(function () use ($c) { |
|
294 | - return $c->query('RootFolder'); |
|
295 | - }); |
|
296 | - }); |
|
297 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
298 | - |
|
299 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
300 | - $config = $c->getConfig(); |
|
301 | - return new \OC\User\Manager($config); |
|
302 | - }); |
|
303 | - $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
304 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
305 | - |
|
306 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
307 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
308 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
309 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
310 | - }); |
|
311 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
312 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
313 | - }); |
|
314 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
315 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
316 | - }); |
|
317 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
318 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
319 | - }); |
|
320 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
321 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
322 | - }); |
|
323 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
324 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
325 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
326 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
327 | - }); |
|
328 | - return $groupManager; |
|
329 | - }); |
|
330 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
331 | - |
|
332 | - $this->registerService(Store::class, function (Server $c) { |
|
333 | - $session = $c->getSession(); |
|
334 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
335 | - $tokenProvider = $c->query(IProvider::class); |
|
336 | - } else { |
|
337 | - $tokenProvider = null; |
|
338 | - } |
|
339 | - $logger = $c->getLogger(); |
|
340 | - return new Store($session, $logger, $tokenProvider); |
|
341 | - }); |
|
342 | - $this->registerAlias(IStore::class, Store::class); |
|
343 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
344 | - $dbConnection = $c->getDatabaseConnection(); |
|
345 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
346 | - }); |
|
347 | - $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
|
348 | - $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
|
349 | - $crypto = $c->getCrypto(); |
|
350 | - $config = $c->getConfig(); |
|
351 | - $logger = $c->getLogger(); |
|
352 | - $timeFactory = new TimeFactory(); |
|
353 | - return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
354 | - }); |
|
355 | - $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
|
356 | - |
|
357 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
358 | - $manager = $c->getUserManager(); |
|
359 | - $session = new \OC\Session\Memory(''); |
|
360 | - $timeFactory = new TimeFactory(); |
|
361 | - // Token providers might require a working database. This code |
|
362 | - // might however be called when ownCloud is not yet setup. |
|
363 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
364 | - $defaultTokenProvider = $c->query(IProvider::class); |
|
365 | - } else { |
|
366 | - $defaultTokenProvider = null; |
|
367 | - } |
|
368 | - |
|
369 | - $dispatcher = $c->getEventDispatcher(); |
|
370 | - |
|
371 | - $userSession = new \OC\User\Session( |
|
372 | - $manager, |
|
373 | - $session, |
|
374 | - $timeFactory, |
|
375 | - $defaultTokenProvider, |
|
376 | - $c->getConfig(), |
|
377 | - $c->getSecureRandom(), |
|
378 | - $c->getLockdownManager(), |
|
379 | - $c->getLogger() |
|
380 | - ); |
|
381 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
382 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
383 | - }); |
|
384 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
385 | - /** @var $user \OC\User\User */ |
|
386 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
387 | - }); |
|
388 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
389 | - /** @var $user \OC\User\User */ |
|
390 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
391 | - $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
392 | - }); |
|
393 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
394 | - /** @var $user \OC\User\User */ |
|
395 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
396 | - }); |
|
397 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
398 | - /** @var $user \OC\User\User */ |
|
399 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
400 | - }); |
|
401 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
402 | - /** @var $user \OC\User\User */ |
|
403 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
404 | - }); |
|
405 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
406 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
407 | - }); |
|
408 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
409 | - /** @var $user \OC\User\User */ |
|
410 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
411 | - }); |
|
412 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
413 | - /** @var $user \OC\User\User */ |
|
414 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
415 | - }); |
|
416 | - $userSession->listen('\OC\User', 'logout', function () { |
|
417 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
418 | - }); |
|
419 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
420 | - /** @var $user \OC\User\User */ |
|
421 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
422 | - $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
423 | - }); |
|
424 | - return $userSession; |
|
425 | - }); |
|
426 | - $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
427 | - |
|
428 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
429 | - return new \OC\Authentication\TwoFactorAuth\Manager( |
|
430 | - $c->getAppManager(), |
|
431 | - $c->getSession(), |
|
432 | - $c->getConfig(), |
|
433 | - $c->getActivityManager(), |
|
434 | - $c->getLogger(), |
|
435 | - $c->query(IProvider::class), |
|
436 | - $c->query(ITimeFactory::class), |
|
437 | - $c->query(EventDispatcherInterface::class) |
|
438 | - ); |
|
439 | - }); |
|
440 | - |
|
441 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
442 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
443 | - |
|
444 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
445 | - return new \OC\AllConfig( |
|
446 | - $c->getSystemConfig() |
|
447 | - ); |
|
448 | - }); |
|
449 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
450 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
451 | - |
|
452 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
453 | - return new \OC\SystemConfig($config); |
|
454 | - }); |
|
455 | - |
|
456 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
457 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
458 | - }); |
|
459 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
460 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
461 | - |
|
462 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
463 | - return new \OC\L10N\Factory( |
|
464 | - $c->getConfig(), |
|
465 | - $c->getRequest(), |
|
466 | - $c->getUserSession(), |
|
467 | - \OC::$SERVERROOT |
|
468 | - ); |
|
469 | - }); |
|
470 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
471 | - |
|
472 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
473 | - $config = $c->getConfig(); |
|
474 | - $cacheFactory = $c->getMemCacheFactory(); |
|
475 | - $request = $c->getRequest(); |
|
476 | - return new \OC\URLGenerator( |
|
477 | - $config, |
|
478 | - $cacheFactory, |
|
479 | - $request |
|
480 | - ); |
|
481 | - }); |
|
482 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
483 | - |
|
484 | - $this->registerAlias('AppFetcher', AppFetcher::class); |
|
485 | - $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
486 | - |
|
487 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
488 | - return new Cache\File(); |
|
489 | - }); |
|
490 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
491 | - |
|
492 | - $this->registerService(Factory::class, function (Server $c) { |
|
493 | - |
|
494 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
495 | - ArrayCache::class, |
|
496 | - ArrayCache::class, |
|
497 | - ArrayCache::class |
|
498 | - ); |
|
499 | - $config = $c->getConfig(); |
|
500 | - $request = $c->getRequest(); |
|
501 | - $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
502 | - |
|
503 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
504 | - $v = \OC_App::getAppVersions(); |
|
505 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
506 | - $version = implode(',', $v); |
|
507 | - $instanceId = \OC_Util::getInstanceId(); |
|
508 | - $path = \OC::$SERVERROOT; |
|
509 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
510 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
511 | - $config->getSystemValue('memcache.local', null), |
|
512 | - $config->getSystemValue('memcache.distributed', null), |
|
513 | - $config->getSystemValue('memcache.locking', null) |
|
514 | - ); |
|
515 | - } |
|
516 | - return $arrayCacheFactory; |
|
517 | - |
|
518 | - }); |
|
519 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
520 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
521 | - |
|
522 | - $this->registerService('RedisFactory', function (Server $c) { |
|
523 | - $systemConfig = $c->getSystemConfig(); |
|
524 | - return new RedisFactory($systemConfig); |
|
525 | - }); |
|
526 | - |
|
527 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
528 | - return new \OC\Activity\Manager( |
|
529 | - $c->getRequest(), |
|
530 | - $c->getUserSession(), |
|
531 | - $c->getConfig(), |
|
532 | - $c->query(IValidator::class) |
|
533 | - ); |
|
534 | - }); |
|
535 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
536 | - |
|
537 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
538 | - return new \OC\Activity\EventMerger( |
|
539 | - $c->getL10N('lib') |
|
540 | - ); |
|
541 | - }); |
|
542 | - $this->registerAlias(IValidator::class, Validator::class); |
|
543 | - |
|
544 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
545 | - return new AvatarManager( |
|
546 | - $c->query(\OC\User\Manager::class), |
|
547 | - $c->getAppDataDir('avatar'), |
|
548 | - $c->getL10N('lib'), |
|
549 | - $c->getLogger(), |
|
550 | - $c->getConfig() |
|
551 | - ); |
|
552 | - }); |
|
553 | - $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
554 | - |
|
555 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
556 | - |
|
557 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
558 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
559 | - $factory = new LogFactory($c, $this->getSystemConfig()); |
|
560 | - $logger = $factory->get($logType); |
|
561 | - $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
562 | - |
|
563 | - return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
564 | - }); |
|
565 | - $this->registerAlias('Logger', \OCP\ILogger::class); |
|
566 | - |
|
567 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
568 | - return new LogFactory($c, $this->getSystemConfig()); |
|
569 | - }); |
|
570 | - |
|
571 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
572 | - $config = $c->getConfig(); |
|
573 | - return new \OC\BackgroundJob\JobList( |
|
574 | - $c->getDatabaseConnection(), |
|
575 | - $config, |
|
576 | - new TimeFactory() |
|
577 | - ); |
|
578 | - }); |
|
579 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
580 | - |
|
581 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
582 | - $cacheFactory = $c->getMemCacheFactory(); |
|
583 | - $logger = $c->getLogger(); |
|
584 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
585 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
586 | - } else { |
|
587 | - $router = new \OC\Route\Router($logger); |
|
588 | - } |
|
589 | - return $router; |
|
590 | - }); |
|
591 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
592 | - |
|
593 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
594 | - return new Search(); |
|
595 | - }); |
|
596 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
597 | - |
|
598 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
599 | - return new \OC\Security\RateLimiting\Limiter( |
|
600 | - $this->getUserSession(), |
|
601 | - $this->getRequest(), |
|
602 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
603 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
604 | - ); |
|
605 | - }); |
|
606 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
607 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
608 | - $this->getMemCacheFactory(), |
|
609 | - new \OC\AppFramework\Utility\TimeFactory() |
|
610 | - ); |
|
611 | - }); |
|
612 | - |
|
613 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
614 | - return new SecureRandom(); |
|
615 | - }); |
|
616 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
617 | - |
|
618 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
619 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
620 | - }); |
|
621 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
622 | - |
|
623 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
624 | - return new Hasher($c->getConfig()); |
|
625 | - }); |
|
626 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
627 | - |
|
628 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
629 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
630 | - }); |
|
631 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
632 | - |
|
633 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
634 | - $systemConfig = $c->getSystemConfig(); |
|
635 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
636 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
637 | - if (!$factory->isValidType($type)) { |
|
638 | - throw new \OC\DatabaseException('Invalid database type'); |
|
639 | - } |
|
640 | - $connectionParams = $factory->createConnectionParams(); |
|
641 | - $connection = $factory->getConnection($type, $connectionParams); |
|
642 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
643 | - return $connection; |
|
644 | - }); |
|
645 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
646 | - |
|
647 | - |
|
648 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
649 | - $user = \OC_User::getUser(); |
|
650 | - $uid = $user ? $user : null; |
|
651 | - return new ClientService( |
|
652 | - $c->getConfig(), |
|
653 | - new \OC\Security\CertificateManager( |
|
654 | - $uid, |
|
655 | - new View(), |
|
656 | - $c->getConfig(), |
|
657 | - $c->getLogger(), |
|
658 | - $c->getSecureRandom() |
|
659 | - ) |
|
660 | - ); |
|
661 | - }); |
|
662 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
663 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
664 | - $eventLogger = new EventLogger(); |
|
665 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
666 | - // In debug mode, module is being activated by default |
|
667 | - $eventLogger->activate(); |
|
668 | - } |
|
669 | - return $eventLogger; |
|
670 | - }); |
|
671 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
672 | - |
|
673 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
674 | - $queryLogger = new QueryLogger(); |
|
675 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
676 | - // In debug mode, module is being activated by default |
|
677 | - $queryLogger->activate(); |
|
678 | - } |
|
679 | - return $queryLogger; |
|
680 | - }); |
|
681 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
682 | - |
|
683 | - $this->registerService(TempManager::class, function (Server $c) { |
|
684 | - return new TempManager( |
|
685 | - $c->getLogger(), |
|
686 | - $c->getConfig() |
|
687 | - ); |
|
688 | - }); |
|
689 | - $this->registerAlias('TempManager', TempManager::class); |
|
690 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
691 | - |
|
692 | - $this->registerService(AppManager::class, function (Server $c) { |
|
693 | - return new \OC\App\AppManager( |
|
694 | - $c->getUserSession(), |
|
695 | - $c->query(\OC\AppConfig::class), |
|
696 | - $c->getGroupManager(), |
|
697 | - $c->getMemCacheFactory(), |
|
698 | - $c->getEventDispatcher() |
|
699 | - ); |
|
700 | - }); |
|
701 | - $this->registerAlias('AppManager', AppManager::class); |
|
702 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
703 | - |
|
704 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
705 | - return new DateTimeZone( |
|
706 | - $c->getConfig(), |
|
707 | - $c->getSession() |
|
708 | - ); |
|
709 | - }); |
|
710 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
711 | - |
|
712 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
713 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
714 | - |
|
715 | - return new DateTimeFormatter( |
|
716 | - $c->getDateTimeZone()->getTimeZone(), |
|
717 | - $c->getL10N('lib', $language) |
|
718 | - ); |
|
719 | - }); |
|
720 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
721 | - |
|
722 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
723 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
724 | - $listener = new UserMountCacheListener($mountCache); |
|
725 | - $listener->listen($c->getUserManager()); |
|
726 | - return $mountCache; |
|
727 | - }); |
|
728 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
729 | - |
|
730 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
731 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
732 | - $mountCache = $c->query('UserMountCache'); |
|
733 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
734 | - |
|
735 | - // builtin providers |
|
736 | - |
|
737 | - $config = $c->getConfig(); |
|
738 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
739 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
740 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
741 | - |
|
742 | - return $manager; |
|
743 | - }); |
|
744 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
745 | - |
|
746 | - $this->registerService('IniWrapper', function ($c) { |
|
747 | - return new IniGetWrapper(); |
|
748 | - }); |
|
749 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
750 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
751 | - if ($busClass) { |
|
752 | - list($app, $class) = explode('::', $busClass, 2); |
|
753 | - if ($c->getAppManager()->isInstalled($app)) { |
|
754 | - \OC_App::loadApp($app); |
|
755 | - return $c->query($class); |
|
756 | - } else { |
|
757 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
758 | - } |
|
759 | - } else { |
|
760 | - $jobList = $c->getJobList(); |
|
761 | - return new CronBus($jobList); |
|
762 | - } |
|
763 | - }); |
|
764 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
765 | - return new TrustedDomainHelper($this->getConfig()); |
|
766 | - }); |
|
767 | - $this->registerService('Throttler', function (Server $c) { |
|
768 | - return new Throttler( |
|
769 | - $c->getDatabaseConnection(), |
|
770 | - new TimeFactory(), |
|
771 | - $c->getLogger(), |
|
772 | - $c->getConfig() |
|
773 | - ); |
|
774 | - }); |
|
775 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
776 | - // IConfig and IAppManager requires a working database. This code |
|
777 | - // might however be called when ownCloud is not yet setup. |
|
778 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
779 | - $config = $c->getConfig(); |
|
780 | - $appManager = $c->getAppManager(); |
|
781 | - } else { |
|
782 | - $config = null; |
|
783 | - $appManager = null; |
|
784 | - } |
|
785 | - |
|
786 | - return new Checker( |
|
787 | - new EnvironmentHelper(), |
|
788 | - new FileAccessHelper(), |
|
789 | - new AppLocator(), |
|
790 | - $config, |
|
791 | - $c->getMemCacheFactory(), |
|
792 | - $appManager, |
|
793 | - $c->getTempManager() |
|
794 | - ); |
|
795 | - }); |
|
796 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
797 | - if (isset($this['urlParams'])) { |
|
798 | - $urlParams = $this['urlParams']; |
|
799 | - } else { |
|
800 | - $urlParams = []; |
|
801 | - } |
|
802 | - |
|
803 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
804 | - && in_array('fakeinput', stream_get_wrappers()) |
|
805 | - ) { |
|
806 | - $stream = 'fakeinput://data'; |
|
807 | - } else { |
|
808 | - $stream = 'php://input'; |
|
809 | - } |
|
810 | - |
|
811 | - return new Request( |
|
812 | - [ |
|
813 | - 'get' => $_GET, |
|
814 | - 'post' => $_POST, |
|
815 | - 'files' => $_FILES, |
|
816 | - 'server' => $_SERVER, |
|
817 | - 'env' => $_ENV, |
|
818 | - 'cookies' => $_COOKIE, |
|
819 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
820 | - ? $_SERVER['REQUEST_METHOD'] |
|
821 | - : '', |
|
822 | - 'urlParams' => $urlParams, |
|
823 | - ], |
|
824 | - $this->getSecureRandom(), |
|
825 | - $this->getConfig(), |
|
826 | - $this->getCsrfTokenManager(), |
|
827 | - $stream |
|
828 | - ); |
|
829 | - }); |
|
830 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
831 | - |
|
832 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
833 | - return new Mailer( |
|
834 | - $c->getConfig(), |
|
835 | - $c->getLogger(), |
|
836 | - $c->query(Defaults::class), |
|
837 | - $c->getURLGenerator(), |
|
838 | - $c->getL10N('lib') |
|
839 | - ); |
|
840 | - }); |
|
841 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
842 | - |
|
843 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
844 | - $config = $c->getConfig(); |
|
845 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
846 | - if (is_null($factoryClass)) { |
|
847 | - throw new \Exception('ldapProviderFactory not set'); |
|
848 | - } |
|
849 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
850 | - $factory = new $factoryClass($this); |
|
851 | - return $factory->getLDAPProvider(); |
|
852 | - }); |
|
853 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
854 | - $ini = $c->getIniWrapper(); |
|
855 | - $config = $c->getConfig(); |
|
856 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
857 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
858 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
859 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
860 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
861 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
862 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
863 | - } |
|
864 | - return new DBLockingProvider( |
|
865 | - $c->getDatabaseConnection(), |
|
866 | - $c->getLogger(), |
|
867 | - new TimeFactory(), |
|
868 | - $ttl, |
|
869 | - !\OC::$CLI |
|
870 | - ); |
|
871 | - } |
|
872 | - return new NoopLockingProvider(); |
|
873 | - }); |
|
874 | - $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
875 | - |
|
876 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
877 | - return new \OC\Files\Mount\Manager(); |
|
878 | - }); |
|
879 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
880 | - |
|
881 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
882 | - return new \OC\Files\Type\Detection( |
|
883 | - $c->getURLGenerator(), |
|
884 | - \OC::$configDir, |
|
885 | - \OC::$SERVERROOT . '/resources/config/' |
|
886 | - ); |
|
887 | - }); |
|
888 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
889 | - |
|
890 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
891 | - return new \OC\Files\Type\Loader( |
|
892 | - $c->getDatabaseConnection() |
|
893 | - ); |
|
894 | - }); |
|
895 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
896 | - $this->registerService(BundleFetcher::class, function () { |
|
897 | - return new BundleFetcher($this->getL10N('lib')); |
|
898 | - }); |
|
899 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
900 | - return new Manager( |
|
901 | - $c->query(IValidator::class) |
|
902 | - ); |
|
903 | - }); |
|
904 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
905 | - |
|
906 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
907 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
908 | - $manager->registerCapability(function () use ($c) { |
|
909 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
910 | - }); |
|
911 | - $manager->registerCapability(function () use ($c) { |
|
912 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
913 | - }); |
|
914 | - return $manager; |
|
915 | - }); |
|
916 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
917 | - |
|
918 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
919 | - $config = $c->getConfig(); |
|
920 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
921 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
922 | - $factory = new $factoryClass($this); |
|
923 | - $manager = $factory->getManager(); |
|
924 | - |
|
925 | - $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
926 | - $manager = $c->getUserManager(); |
|
927 | - $user = $manager->get($id); |
|
928 | - if(is_null($user)) { |
|
929 | - $l = $c->getL10N('core'); |
|
930 | - $displayName = $l->t('Unknown user'); |
|
931 | - } else { |
|
932 | - $displayName = $user->getDisplayName(); |
|
933 | - } |
|
934 | - return $displayName; |
|
935 | - }); |
|
936 | - |
|
937 | - return $manager; |
|
938 | - }); |
|
939 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
940 | - |
|
941 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
942 | - /* |
|
161 | + /** @var string */ |
|
162 | + private $webRoot; |
|
163 | + |
|
164 | + /** |
|
165 | + * @param string $webRoot |
|
166 | + * @param \OC\Config $config |
|
167 | + */ |
|
168 | + public function __construct($webRoot, \OC\Config $config) { |
|
169 | + parent::__construct(); |
|
170 | + $this->webRoot = $webRoot; |
|
171 | + |
|
172 | + // To find out if we are running from CLI or not |
|
173 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
174 | + |
|
175 | + $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
176 | + return $c; |
|
177 | + }); |
|
178 | + |
|
179 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
180 | + $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
181 | + |
|
182 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
183 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
184 | + |
|
185 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
186 | + |
|
187 | + |
|
188 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
189 | + return new PreviewManager( |
|
190 | + $c->getConfig(), |
|
191 | + $c->getRootFolder(), |
|
192 | + $c->getAppDataDir('preview'), |
|
193 | + $c->getEventDispatcher(), |
|
194 | + $c->getSession()->get('user_id') |
|
195 | + ); |
|
196 | + }); |
|
197 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
198 | + |
|
199 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
200 | + return new \OC\Preview\Watcher( |
|
201 | + $c->getAppDataDir('preview') |
|
202 | + ); |
|
203 | + }); |
|
204 | + |
|
205 | + $this->registerService('EncryptionManager', function (Server $c) { |
|
206 | + $view = new View(); |
|
207 | + $util = new Encryption\Util( |
|
208 | + $view, |
|
209 | + $c->getUserManager(), |
|
210 | + $c->getGroupManager(), |
|
211 | + $c->getConfig() |
|
212 | + ); |
|
213 | + return new Encryption\Manager( |
|
214 | + $c->getConfig(), |
|
215 | + $c->getLogger(), |
|
216 | + $c->getL10N('core'), |
|
217 | + new View(), |
|
218 | + $util, |
|
219 | + new ArrayCache() |
|
220 | + ); |
|
221 | + }); |
|
222 | + |
|
223 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
224 | + $util = new Encryption\Util( |
|
225 | + new View(), |
|
226 | + $c->getUserManager(), |
|
227 | + $c->getGroupManager(), |
|
228 | + $c->getConfig() |
|
229 | + ); |
|
230 | + return new Encryption\File( |
|
231 | + $util, |
|
232 | + $c->getRootFolder(), |
|
233 | + $c->getShareManager() |
|
234 | + ); |
|
235 | + }); |
|
236 | + |
|
237 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
238 | + $view = new View(); |
|
239 | + $util = new Encryption\Util( |
|
240 | + $view, |
|
241 | + $c->getUserManager(), |
|
242 | + $c->getGroupManager(), |
|
243 | + $c->getConfig() |
|
244 | + ); |
|
245 | + |
|
246 | + return new Encryption\Keys\Storage($view, $util); |
|
247 | + }); |
|
248 | + $this->registerService('TagMapper', function (Server $c) { |
|
249 | + return new TagMapper($c->getDatabaseConnection()); |
|
250 | + }); |
|
251 | + |
|
252 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
253 | + $tagMapper = $c->query('TagMapper'); |
|
254 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
255 | + }); |
|
256 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
257 | + |
|
258 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
259 | + $config = $c->getConfig(); |
|
260 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
261 | + return new $factoryClass($this); |
|
262 | + }); |
|
263 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
264 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
265 | + }); |
|
266 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
267 | + |
|
268 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
269 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
270 | + }); |
|
271 | + $this->registerService('RootFolder', function (Server $c) { |
|
272 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
273 | + $view = new View(); |
|
274 | + $root = new Root( |
|
275 | + $manager, |
|
276 | + $view, |
|
277 | + null, |
|
278 | + $c->getUserMountCache(), |
|
279 | + $this->getLogger(), |
|
280 | + $this->getUserManager() |
|
281 | + ); |
|
282 | + $connector = new HookConnector($root, $view); |
|
283 | + $connector->viewToNode(); |
|
284 | + |
|
285 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
286 | + $previewConnector->connectWatcher(); |
|
287 | + |
|
288 | + return $root; |
|
289 | + }); |
|
290 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
291 | + |
|
292 | + $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
293 | + return new LazyRoot(function () use ($c) { |
|
294 | + return $c->query('RootFolder'); |
|
295 | + }); |
|
296 | + }); |
|
297 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
298 | + |
|
299 | + $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
300 | + $config = $c->getConfig(); |
|
301 | + return new \OC\User\Manager($config); |
|
302 | + }); |
|
303 | + $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
304 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
305 | + |
|
306 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
307 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
308 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
309 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
310 | + }); |
|
311 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
312 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
313 | + }); |
|
314 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
315 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
316 | + }); |
|
317 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
318 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
319 | + }); |
|
320 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
321 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
322 | + }); |
|
323 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
324 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
325 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
326 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
327 | + }); |
|
328 | + return $groupManager; |
|
329 | + }); |
|
330 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
331 | + |
|
332 | + $this->registerService(Store::class, function (Server $c) { |
|
333 | + $session = $c->getSession(); |
|
334 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
335 | + $tokenProvider = $c->query(IProvider::class); |
|
336 | + } else { |
|
337 | + $tokenProvider = null; |
|
338 | + } |
|
339 | + $logger = $c->getLogger(); |
|
340 | + return new Store($session, $logger, $tokenProvider); |
|
341 | + }); |
|
342 | + $this->registerAlias(IStore::class, Store::class); |
|
343 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
344 | + $dbConnection = $c->getDatabaseConnection(); |
|
345 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
346 | + }); |
|
347 | + $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
|
348 | + $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
|
349 | + $crypto = $c->getCrypto(); |
|
350 | + $config = $c->getConfig(); |
|
351 | + $logger = $c->getLogger(); |
|
352 | + $timeFactory = new TimeFactory(); |
|
353 | + return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
354 | + }); |
|
355 | + $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
|
356 | + |
|
357 | + $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
358 | + $manager = $c->getUserManager(); |
|
359 | + $session = new \OC\Session\Memory(''); |
|
360 | + $timeFactory = new TimeFactory(); |
|
361 | + // Token providers might require a working database. This code |
|
362 | + // might however be called when ownCloud is not yet setup. |
|
363 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
364 | + $defaultTokenProvider = $c->query(IProvider::class); |
|
365 | + } else { |
|
366 | + $defaultTokenProvider = null; |
|
367 | + } |
|
368 | + |
|
369 | + $dispatcher = $c->getEventDispatcher(); |
|
370 | + |
|
371 | + $userSession = new \OC\User\Session( |
|
372 | + $manager, |
|
373 | + $session, |
|
374 | + $timeFactory, |
|
375 | + $defaultTokenProvider, |
|
376 | + $c->getConfig(), |
|
377 | + $c->getSecureRandom(), |
|
378 | + $c->getLockdownManager(), |
|
379 | + $c->getLogger() |
|
380 | + ); |
|
381 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
382 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
383 | + }); |
|
384 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
385 | + /** @var $user \OC\User\User */ |
|
386 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
387 | + }); |
|
388 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
389 | + /** @var $user \OC\User\User */ |
|
390 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
391 | + $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
392 | + }); |
|
393 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
394 | + /** @var $user \OC\User\User */ |
|
395 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
396 | + }); |
|
397 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
398 | + /** @var $user \OC\User\User */ |
|
399 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
400 | + }); |
|
401 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
402 | + /** @var $user \OC\User\User */ |
|
403 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
404 | + }); |
|
405 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
406 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
407 | + }); |
|
408 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
409 | + /** @var $user \OC\User\User */ |
|
410 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
411 | + }); |
|
412 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
413 | + /** @var $user \OC\User\User */ |
|
414 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
415 | + }); |
|
416 | + $userSession->listen('\OC\User', 'logout', function () { |
|
417 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
418 | + }); |
|
419 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
420 | + /** @var $user \OC\User\User */ |
|
421 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
422 | + $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
423 | + }); |
|
424 | + return $userSession; |
|
425 | + }); |
|
426 | + $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
427 | + |
|
428 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
429 | + return new \OC\Authentication\TwoFactorAuth\Manager( |
|
430 | + $c->getAppManager(), |
|
431 | + $c->getSession(), |
|
432 | + $c->getConfig(), |
|
433 | + $c->getActivityManager(), |
|
434 | + $c->getLogger(), |
|
435 | + $c->query(IProvider::class), |
|
436 | + $c->query(ITimeFactory::class), |
|
437 | + $c->query(EventDispatcherInterface::class) |
|
438 | + ); |
|
439 | + }); |
|
440 | + |
|
441 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
442 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
443 | + |
|
444 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
445 | + return new \OC\AllConfig( |
|
446 | + $c->getSystemConfig() |
|
447 | + ); |
|
448 | + }); |
|
449 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
450 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
451 | + |
|
452 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
453 | + return new \OC\SystemConfig($config); |
|
454 | + }); |
|
455 | + |
|
456 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
457 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
458 | + }); |
|
459 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
460 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
461 | + |
|
462 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
463 | + return new \OC\L10N\Factory( |
|
464 | + $c->getConfig(), |
|
465 | + $c->getRequest(), |
|
466 | + $c->getUserSession(), |
|
467 | + \OC::$SERVERROOT |
|
468 | + ); |
|
469 | + }); |
|
470 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
471 | + |
|
472 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
473 | + $config = $c->getConfig(); |
|
474 | + $cacheFactory = $c->getMemCacheFactory(); |
|
475 | + $request = $c->getRequest(); |
|
476 | + return new \OC\URLGenerator( |
|
477 | + $config, |
|
478 | + $cacheFactory, |
|
479 | + $request |
|
480 | + ); |
|
481 | + }); |
|
482 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
483 | + |
|
484 | + $this->registerAlias('AppFetcher', AppFetcher::class); |
|
485 | + $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
486 | + |
|
487 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
488 | + return new Cache\File(); |
|
489 | + }); |
|
490 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
491 | + |
|
492 | + $this->registerService(Factory::class, function (Server $c) { |
|
493 | + |
|
494 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
495 | + ArrayCache::class, |
|
496 | + ArrayCache::class, |
|
497 | + ArrayCache::class |
|
498 | + ); |
|
499 | + $config = $c->getConfig(); |
|
500 | + $request = $c->getRequest(); |
|
501 | + $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
502 | + |
|
503 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
504 | + $v = \OC_App::getAppVersions(); |
|
505 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
506 | + $version = implode(',', $v); |
|
507 | + $instanceId = \OC_Util::getInstanceId(); |
|
508 | + $path = \OC::$SERVERROOT; |
|
509 | + $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
510 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
511 | + $config->getSystemValue('memcache.local', null), |
|
512 | + $config->getSystemValue('memcache.distributed', null), |
|
513 | + $config->getSystemValue('memcache.locking', null) |
|
514 | + ); |
|
515 | + } |
|
516 | + return $arrayCacheFactory; |
|
517 | + |
|
518 | + }); |
|
519 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
520 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
521 | + |
|
522 | + $this->registerService('RedisFactory', function (Server $c) { |
|
523 | + $systemConfig = $c->getSystemConfig(); |
|
524 | + return new RedisFactory($systemConfig); |
|
525 | + }); |
|
526 | + |
|
527 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
528 | + return new \OC\Activity\Manager( |
|
529 | + $c->getRequest(), |
|
530 | + $c->getUserSession(), |
|
531 | + $c->getConfig(), |
|
532 | + $c->query(IValidator::class) |
|
533 | + ); |
|
534 | + }); |
|
535 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
536 | + |
|
537 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
538 | + return new \OC\Activity\EventMerger( |
|
539 | + $c->getL10N('lib') |
|
540 | + ); |
|
541 | + }); |
|
542 | + $this->registerAlias(IValidator::class, Validator::class); |
|
543 | + |
|
544 | + $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
545 | + return new AvatarManager( |
|
546 | + $c->query(\OC\User\Manager::class), |
|
547 | + $c->getAppDataDir('avatar'), |
|
548 | + $c->getL10N('lib'), |
|
549 | + $c->getLogger(), |
|
550 | + $c->getConfig() |
|
551 | + ); |
|
552 | + }); |
|
553 | + $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
554 | + |
|
555 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
556 | + |
|
557 | + $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
558 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
559 | + $factory = new LogFactory($c, $this->getSystemConfig()); |
|
560 | + $logger = $factory->get($logType); |
|
561 | + $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
562 | + |
|
563 | + return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
564 | + }); |
|
565 | + $this->registerAlias('Logger', \OCP\ILogger::class); |
|
566 | + |
|
567 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
568 | + return new LogFactory($c, $this->getSystemConfig()); |
|
569 | + }); |
|
570 | + |
|
571 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
572 | + $config = $c->getConfig(); |
|
573 | + return new \OC\BackgroundJob\JobList( |
|
574 | + $c->getDatabaseConnection(), |
|
575 | + $config, |
|
576 | + new TimeFactory() |
|
577 | + ); |
|
578 | + }); |
|
579 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
580 | + |
|
581 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
582 | + $cacheFactory = $c->getMemCacheFactory(); |
|
583 | + $logger = $c->getLogger(); |
|
584 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
585 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
586 | + } else { |
|
587 | + $router = new \OC\Route\Router($logger); |
|
588 | + } |
|
589 | + return $router; |
|
590 | + }); |
|
591 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
592 | + |
|
593 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
594 | + return new Search(); |
|
595 | + }); |
|
596 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
597 | + |
|
598 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
599 | + return new \OC\Security\RateLimiting\Limiter( |
|
600 | + $this->getUserSession(), |
|
601 | + $this->getRequest(), |
|
602 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
603 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
604 | + ); |
|
605 | + }); |
|
606 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
607 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
608 | + $this->getMemCacheFactory(), |
|
609 | + new \OC\AppFramework\Utility\TimeFactory() |
|
610 | + ); |
|
611 | + }); |
|
612 | + |
|
613 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
614 | + return new SecureRandom(); |
|
615 | + }); |
|
616 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
617 | + |
|
618 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
619 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
620 | + }); |
|
621 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
622 | + |
|
623 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
624 | + return new Hasher($c->getConfig()); |
|
625 | + }); |
|
626 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
627 | + |
|
628 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
629 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
630 | + }); |
|
631 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
632 | + |
|
633 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
634 | + $systemConfig = $c->getSystemConfig(); |
|
635 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
636 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
637 | + if (!$factory->isValidType($type)) { |
|
638 | + throw new \OC\DatabaseException('Invalid database type'); |
|
639 | + } |
|
640 | + $connectionParams = $factory->createConnectionParams(); |
|
641 | + $connection = $factory->getConnection($type, $connectionParams); |
|
642 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
643 | + return $connection; |
|
644 | + }); |
|
645 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
646 | + |
|
647 | + |
|
648 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
649 | + $user = \OC_User::getUser(); |
|
650 | + $uid = $user ? $user : null; |
|
651 | + return new ClientService( |
|
652 | + $c->getConfig(), |
|
653 | + new \OC\Security\CertificateManager( |
|
654 | + $uid, |
|
655 | + new View(), |
|
656 | + $c->getConfig(), |
|
657 | + $c->getLogger(), |
|
658 | + $c->getSecureRandom() |
|
659 | + ) |
|
660 | + ); |
|
661 | + }); |
|
662 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
663 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
664 | + $eventLogger = new EventLogger(); |
|
665 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
666 | + // In debug mode, module is being activated by default |
|
667 | + $eventLogger->activate(); |
|
668 | + } |
|
669 | + return $eventLogger; |
|
670 | + }); |
|
671 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
672 | + |
|
673 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
674 | + $queryLogger = new QueryLogger(); |
|
675 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
676 | + // In debug mode, module is being activated by default |
|
677 | + $queryLogger->activate(); |
|
678 | + } |
|
679 | + return $queryLogger; |
|
680 | + }); |
|
681 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
682 | + |
|
683 | + $this->registerService(TempManager::class, function (Server $c) { |
|
684 | + return new TempManager( |
|
685 | + $c->getLogger(), |
|
686 | + $c->getConfig() |
|
687 | + ); |
|
688 | + }); |
|
689 | + $this->registerAlias('TempManager', TempManager::class); |
|
690 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
691 | + |
|
692 | + $this->registerService(AppManager::class, function (Server $c) { |
|
693 | + return new \OC\App\AppManager( |
|
694 | + $c->getUserSession(), |
|
695 | + $c->query(\OC\AppConfig::class), |
|
696 | + $c->getGroupManager(), |
|
697 | + $c->getMemCacheFactory(), |
|
698 | + $c->getEventDispatcher() |
|
699 | + ); |
|
700 | + }); |
|
701 | + $this->registerAlias('AppManager', AppManager::class); |
|
702 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
703 | + |
|
704 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
705 | + return new DateTimeZone( |
|
706 | + $c->getConfig(), |
|
707 | + $c->getSession() |
|
708 | + ); |
|
709 | + }); |
|
710 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
711 | + |
|
712 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
713 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
714 | + |
|
715 | + return new DateTimeFormatter( |
|
716 | + $c->getDateTimeZone()->getTimeZone(), |
|
717 | + $c->getL10N('lib', $language) |
|
718 | + ); |
|
719 | + }); |
|
720 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
721 | + |
|
722 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
723 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
724 | + $listener = new UserMountCacheListener($mountCache); |
|
725 | + $listener->listen($c->getUserManager()); |
|
726 | + return $mountCache; |
|
727 | + }); |
|
728 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
729 | + |
|
730 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
731 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
732 | + $mountCache = $c->query('UserMountCache'); |
|
733 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
734 | + |
|
735 | + // builtin providers |
|
736 | + |
|
737 | + $config = $c->getConfig(); |
|
738 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
739 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
740 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
741 | + |
|
742 | + return $manager; |
|
743 | + }); |
|
744 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
745 | + |
|
746 | + $this->registerService('IniWrapper', function ($c) { |
|
747 | + return new IniGetWrapper(); |
|
748 | + }); |
|
749 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
750 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
751 | + if ($busClass) { |
|
752 | + list($app, $class) = explode('::', $busClass, 2); |
|
753 | + if ($c->getAppManager()->isInstalled($app)) { |
|
754 | + \OC_App::loadApp($app); |
|
755 | + return $c->query($class); |
|
756 | + } else { |
|
757 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
758 | + } |
|
759 | + } else { |
|
760 | + $jobList = $c->getJobList(); |
|
761 | + return new CronBus($jobList); |
|
762 | + } |
|
763 | + }); |
|
764 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
765 | + return new TrustedDomainHelper($this->getConfig()); |
|
766 | + }); |
|
767 | + $this->registerService('Throttler', function (Server $c) { |
|
768 | + return new Throttler( |
|
769 | + $c->getDatabaseConnection(), |
|
770 | + new TimeFactory(), |
|
771 | + $c->getLogger(), |
|
772 | + $c->getConfig() |
|
773 | + ); |
|
774 | + }); |
|
775 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
776 | + // IConfig and IAppManager requires a working database. This code |
|
777 | + // might however be called when ownCloud is not yet setup. |
|
778 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
779 | + $config = $c->getConfig(); |
|
780 | + $appManager = $c->getAppManager(); |
|
781 | + } else { |
|
782 | + $config = null; |
|
783 | + $appManager = null; |
|
784 | + } |
|
785 | + |
|
786 | + return new Checker( |
|
787 | + new EnvironmentHelper(), |
|
788 | + new FileAccessHelper(), |
|
789 | + new AppLocator(), |
|
790 | + $config, |
|
791 | + $c->getMemCacheFactory(), |
|
792 | + $appManager, |
|
793 | + $c->getTempManager() |
|
794 | + ); |
|
795 | + }); |
|
796 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
797 | + if (isset($this['urlParams'])) { |
|
798 | + $urlParams = $this['urlParams']; |
|
799 | + } else { |
|
800 | + $urlParams = []; |
|
801 | + } |
|
802 | + |
|
803 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
804 | + && in_array('fakeinput', stream_get_wrappers()) |
|
805 | + ) { |
|
806 | + $stream = 'fakeinput://data'; |
|
807 | + } else { |
|
808 | + $stream = 'php://input'; |
|
809 | + } |
|
810 | + |
|
811 | + return new Request( |
|
812 | + [ |
|
813 | + 'get' => $_GET, |
|
814 | + 'post' => $_POST, |
|
815 | + 'files' => $_FILES, |
|
816 | + 'server' => $_SERVER, |
|
817 | + 'env' => $_ENV, |
|
818 | + 'cookies' => $_COOKIE, |
|
819 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
820 | + ? $_SERVER['REQUEST_METHOD'] |
|
821 | + : '', |
|
822 | + 'urlParams' => $urlParams, |
|
823 | + ], |
|
824 | + $this->getSecureRandom(), |
|
825 | + $this->getConfig(), |
|
826 | + $this->getCsrfTokenManager(), |
|
827 | + $stream |
|
828 | + ); |
|
829 | + }); |
|
830 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
831 | + |
|
832 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
833 | + return new Mailer( |
|
834 | + $c->getConfig(), |
|
835 | + $c->getLogger(), |
|
836 | + $c->query(Defaults::class), |
|
837 | + $c->getURLGenerator(), |
|
838 | + $c->getL10N('lib') |
|
839 | + ); |
|
840 | + }); |
|
841 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
842 | + |
|
843 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
844 | + $config = $c->getConfig(); |
|
845 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
846 | + if (is_null($factoryClass)) { |
|
847 | + throw new \Exception('ldapProviderFactory not set'); |
|
848 | + } |
|
849 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
850 | + $factory = new $factoryClass($this); |
|
851 | + return $factory->getLDAPProvider(); |
|
852 | + }); |
|
853 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
854 | + $ini = $c->getIniWrapper(); |
|
855 | + $config = $c->getConfig(); |
|
856 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
857 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
858 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
859 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
860 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
861 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
862 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
863 | + } |
|
864 | + return new DBLockingProvider( |
|
865 | + $c->getDatabaseConnection(), |
|
866 | + $c->getLogger(), |
|
867 | + new TimeFactory(), |
|
868 | + $ttl, |
|
869 | + !\OC::$CLI |
|
870 | + ); |
|
871 | + } |
|
872 | + return new NoopLockingProvider(); |
|
873 | + }); |
|
874 | + $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
875 | + |
|
876 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
877 | + return new \OC\Files\Mount\Manager(); |
|
878 | + }); |
|
879 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
880 | + |
|
881 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
882 | + return new \OC\Files\Type\Detection( |
|
883 | + $c->getURLGenerator(), |
|
884 | + \OC::$configDir, |
|
885 | + \OC::$SERVERROOT . '/resources/config/' |
|
886 | + ); |
|
887 | + }); |
|
888 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
889 | + |
|
890 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
891 | + return new \OC\Files\Type\Loader( |
|
892 | + $c->getDatabaseConnection() |
|
893 | + ); |
|
894 | + }); |
|
895 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
896 | + $this->registerService(BundleFetcher::class, function () { |
|
897 | + return new BundleFetcher($this->getL10N('lib')); |
|
898 | + }); |
|
899 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
900 | + return new Manager( |
|
901 | + $c->query(IValidator::class) |
|
902 | + ); |
|
903 | + }); |
|
904 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
905 | + |
|
906 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
907 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
908 | + $manager->registerCapability(function () use ($c) { |
|
909 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
910 | + }); |
|
911 | + $manager->registerCapability(function () use ($c) { |
|
912 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
913 | + }); |
|
914 | + return $manager; |
|
915 | + }); |
|
916 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
917 | + |
|
918 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
919 | + $config = $c->getConfig(); |
|
920 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
921 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
922 | + $factory = new $factoryClass($this); |
|
923 | + $manager = $factory->getManager(); |
|
924 | + |
|
925 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
926 | + $manager = $c->getUserManager(); |
|
927 | + $user = $manager->get($id); |
|
928 | + if(is_null($user)) { |
|
929 | + $l = $c->getL10N('core'); |
|
930 | + $displayName = $l->t('Unknown user'); |
|
931 | + } else { |
|
932 | + $displayName = $user->getDisplayName(); |
|
933 | + } |
|
934 | + return $displayName; |
|
935 | + }); |
|
936 | + |
|
937 | + return $manager; |
|
938 | + }); |
|
939 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
940 | + |
|
941 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
942 | + /* |
|
943 | 943 | * Dark magic for autoloader. |
944 | 944 | * If we do a class_exists it will try to load the class which will |
945 | 945 | * make composer cache the result. Resulting in errors when enabling |
946 | 946 | * the theming app. |
947 | 947 | */ |
948 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
949 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
950 | - $classExists = true; |
|
951 | - } else { |
|
952 | - $classExists = false; |
|
953 | - } |
|
954 | - |
|
955 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
956 | - return new ThemingDefaults( |
|
957 | - $c->getConfig(), |
|
958 | - $c->getL10N('theming'), |
|
959 | - $c->getURLGenerator(), |
|
960 | - $c->getMemCacheFactory(), |
|
961 | - new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
962 | - new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator()), |
|
963 | - $c->getAppManager() |
|
964 | - ); |
|
965 | - } |
|
966 | - return new \OC_Defaults(); |
|
967 | - }); |
|
968 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
969 | - /** @var Factory $cacheFactory */ |
|
970 | - $cacheFactory = $c->query(Factory::class); |
|
971 | - return new SCSSCacher( |
|
972 | - $c->getLogger(), |
|
973 | - $c->query(\OC\Files\AppData\Factory::class), |
|
974 | - $c->getURLGenerator(), |
|
975 | - $c->getConfig(), |
|
976 | - $c->getThemingDefaults(), |
|
977 | - \OC::$SERVERROOT, |
|
978 | - $this->getMemCacheFactory() |
|
979 | - ); |
|
980 | - }); |
|
981 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
982 | - /** @var Factory $cacheFactory */ |
|
983 | - $cacheFactory = $c->query(Factory::class); |
|
984 | - return new JSCombiner( |
|
985 | - $c->getAppDataDir('js'), |
|
986 | - $c->getURLGenerator(), |
|
987 | - $this->getMemCacheFactory(), |
|
988 | - $c->getSystemConfig(), |
|
989 | - $c->getLogger() |
|
990 | - ); |
|
991 | - }); |
|
992 | - $this->registerService(EventDispatcher::class, function () { |
|
993 | - return new EventDispatcher(); |
|
994 | - }); |
|
995 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
996 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
997 | - |
|
998 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
999 | - // FIXME: Instantiiated here due to cyclic dependency |
|
1000 | - $request = new Request( |
|
1001 | - [ |
|
1002 | - 'get' => $_GET, |
|
1003 | - 'post' => $_POST, |
|
1004 | - 'files' => $_FILES, |
|
1005 | - 'server' => $_SERVER, |
|
1006 | - 'env' => $_ENV, |
|
1007 | - 'cookies' => $_COOKIE, |
|
1008 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1009 | - ? $_SERVER['REQUEST_METHOD'] |
|
1010 | - : null, |
|
1011 | - ], |
|
1012 | - $c->getSecureRandom(), |
|
1013 | - $c->getConfig() |
|
1014 | - ); |
|
1015 | - |
|
1016 | - return new CryptoWrapper( |
|
1017 | - $c->getConfig(), |
|
1018 | - $c->getCrypto(), |
|
1019 | - $c->getSecureRandom(), |
|
1020 | - $request |
|
1021 | - ); |
|
1022 | - }); |
|
1023 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1024 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1025 | - |
|
1026 | - return new CsrfTokenManager( |
|
1027 | - $tokenGenerator, |
|
1028 | - $c->query(SessionStorage::class) |
|
1029 | - ); |
|
1030 | - }); |
|
1031 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1032 | - return new SessionStorage($c->getSession()); |
|
1033 | - }); |
|
1034 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1035 | - return new ContentSecurityPolicyManager(); |
|
1036 | - }); |
|
1037 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
1038 | - |
|
1039 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1040 | - return new ContentSecurityPolicyNonceManager( |
|
1041 | - $c->getCsrfTokenManager(), |
|
1042 | - $c->getRequest() |
|
1043 | - ); |
|
1044 | - }); |
|
1045 | - |
|
1046 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1047 | - $config = $c->getConfig(); |
|
1048 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1049 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
1050 | - $factory = new $factoryClass($this); |
|
1051 | - |
|
1052 | - $manager = new \OC\Share20\Manager( |
|
1053 | - $c->getLogger(), |
|
1054 | - $c->getConfig(), |
|
1055 | - $c->getSecureRandom(), |
|
1056 | - $c->getHasher(), |
|
1057 | - $c->getMountManager(), |
|
1058 | - $c->getGroupManager(), |
|
1059 | - $c->getL10N('lib'), |
|
1060 | - $c->getL10NFactory(), |
|
1061 | - $factory, |
|
1062 | - $c->getUserManager(), |
|
1063 | - $c->getLazyRootFolder(), |
|
1064 | - $c->getEventDispatcher(), |
|
1065 | - $c->getMailer(), |
|
1066 | - $c->getURLGenerator(), |
|
1067 | - $c->getThemingDefaults() |
|
1068 | - ); |
|
1069 | - |
|
1070 | - return $manager; |
|
1071 | - }); |
|
1072 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1073 | - |
|
1074 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1075 | - $instance = new Collaboration\Collaborators\Search($c); |
|
1076 | - |
|
1077 | - // register default plugins |
|
1078 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1079 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1080 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1081 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1082 | - |
|
1083 | - return $instance; |
|
1084 | - }); |
|
1085 | - $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1086 | - |
|
1087 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1088 | - |
|
1089 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1090 | - $manager = new \OC\Settings\Manager( |
|
1091 | - $c->getLogger(), |
|
1092 | - $c->getDatabaseConnection(), |
|
1093 | - $c->getL10N('lib'), |
|
1094 | - $c->getConfig(), |
|
1095 | - $c->getEncryptionManager(), |
|
1096 | - $c->getUserManager(), |
|
1097 | - $c->getLockingProvider(), |
|
1098 | - $c->getRequest(), |
|
1099 | - $c->getURLGenerator(), |
|
1100 | - $c->query(AccountManager::class), |
|
1101 | - $c->getGroupManager(), |
|
1102 | - $c->getL10NFactory(), |
|
1103 | - $c->getAppManager() |
|
1104 | - ); |
|
1105 | - return $manager; |
|
1106 | - }); |
|
1107 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1108 | - return new \OC\Files\AppData\Factory( |
|
1109 | - $c->getRootFolder(), |
|
1110 | - $c->getSystemConfig() |
|
1111 | - ); |
|
1112 | - }); |
|
1113 | - |
|
1114 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1115 | - return new LockdownManager(function () use ($c) { |
|
1116 | - return $c->getSession(); |
|
1117 | - }); |
|
1118 | - }); |
|
1119 | - |
|
1120 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1121 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1122 | - }); |
|
1123 | - |
|
1124 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1125 | - return new CloudIdManager(); |
|
1126 | - }); |
|
1127 | - |
|
1128 | - $this->registerService(IConfig::class, function (Server $c) { |
|
1129 | - return new GlobalScale\Config($c->getConfig()); |
|
1130 | - }); |
|
1131 | - |
|
1132 | - $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
1133 | - return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
1134 | - }); |
|
1135 | - |
|
1136 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1137 | - return new CloudFederationFactory(); |
|
1138 | - }); |
|
1139 | - |
|
1140 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1141 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1142 | - |
|
1143 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1144 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1145 | - |
|
1146 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1147 | - return new Defaults( |
|
1148 | - $c->getThemingDefaults() |
|
1149 | - ); |
|
1150 | - }); |
|
1151 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1152 | - |
|
1153 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1154 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1155 | - }); |
|
1156 | - |
|
1157 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1158 | - return new ShareHelper( |
|
1159 | - $c->query(\OCP\Share\IManager::class) |
|
1160 | - ); |
|
1161 | - }); |
|
1162 | - |
|
1163 | - $this->registerService(Installer::class, function(Server $c) { |
|
1164 | - return new Installer( |
|
1165 | - $c->getAppFetcher(), |
|
1166 | - $c->getHTTPClientService(), |
|
1167 | - $c->getTempManager(), |
|
1168 | - $c->getLogger(), |
|
1169 | - $c->getConfig() |
|
1170 | - ); |
|
1171 | - }); |
|
1172 | - |
|
1173 | - $this->registerService(IApiFactory::class, function(Server $c) { |
|
1174 | - return new ApiFactory($c->getHTTPClientService()); |
|
1175 | - }); |
|
1176 | - |
|
1177 | - $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1178 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
1179 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1180 | - }); |
|
1181 | - |
|
1182 | - $this->registerService(IContactsStore::class, function(Server $c) { |
|
1183 | - return new ContactsStore( |
|
1184 | - $c->getContactsManager(), |
|
1185 | - $c->getConfig(), |
|
1186 | - $c->getUserManager(), |
|
1187 | - $c->getGroupManager() |
|
1188 | - ); |
|
1189 | - }); |
|
1190 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1191 | - |
|
1192 | - $this->connectDispatcher(); |
|
1193 | - } |
|
1194 | - |
|
1195 | - /** |
|
1196 | - * @return \OCP\Calendar\IManager |
|
1197 | - */ |
|
1198 | - public function getCalendarManager() { |
|
1199 | - return $this->query('CalendarManager'); |
|
1200 | - } |
|
1201 | - |
|
1202 | - private function connectDispatcher() { |
|
1203 | - $dispatcher = $this->getEventDispatcher(); |
|
1204 | - |
|
1205 | - // Delete avatar on user deletion |
|
1206 | - $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1207 | - $logger = $this->getLogger(); |
|
1208 | - $manager = $this->getAvatarManager(); |
|
1209 | - /** @var IUser $user */ |
|
1210 | - $user = $e->getSubject(); |
|
1211 | - |
|
1212 | - try { |
|
1213 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1214 | - $avatar->remove(); |
|
1215 | - } catch (NotFoundException $e) { |
|
1216 | - // no avatar to remove |
|
1217 | - } catch (\Exception $e) { |
|
1218 | - // Ignore exceptions |
|
1219 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1220 | - } |
|
1221 | - }); |
|
1222 | - |
|
1223 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1224 | - $manager = $this->getAvatarManager(); |
|
1225 | - /** @var IUser $user */ |
|
1226 | - $user = $e->getSubject(); |
|
1227 | - $feature = $e->getArgument('feature'); |
|
1228 | - $oldValue = $e->getArgument('oldValue'); |
|
1229 | - $value = $e->getArgument('value'); |
|
1230 | - |
|
1231 | - try { |
|
1232 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1233 | - $avatar->userChanged($feature, $oldValue, $value); |
|
1234 | - } catch (NotFoundException $e) { |
|
1235 | - // no avatar to remove |
|
1236 | - } |
|
1237 | - }); |
|
1238 | - } |
|
1239 | - |
|
1240 | - /** |
|
1241 | - * @return \OCP\Contacts\IManager |
|
1242 | - */ |
|
1243 | - public function getContactsManager() { |
|
1244 | - return $this->query('ContactsManager'); |
|
1245 | - } |
|
1246 | - |
|
1247 | - /** |
|
1248 | - * @return \OC\Encryption\Manager |
|
1249 | - */ |
|
1250 | - public function getEncryptionManager() { |
|
1251 | - return $this->query('EncryptionManager'); |
|
1252 | - } |
|
1253 | - |
|
1254 | - /** |
|
1255 | - * @return \OC\Encryption\File |
|
1256 | - */ |
|
1257 | - public function getEncryptionFilesHelper() { |
|
1258 | - return $this->query('EncryptionFileHelper'); |
|
1259 | - } |
|
1260 | - |
|
1261 | - /** |
|
1262 | - * @return \OCP\Encryption\Keys\IStorage |
|
1263 | - */ |
|
1264 | - public function getEncryptionKeyStorage() { |
|
1265 | - return $this->query('EncryptionKeyStorage'); |
|
1266 | - } |
|
1267 | - |
|
1268 | - /** |
|
1269 | - * The current request object holding all information about the request |
|
1270 | - * currently being processed is returned from this method. |
|
1271 | - * In case the current execution was not initiated by a web request null is returned |
|
1272 | - * |
|
1273 | - * @return \OCP\IRequest |
|
1274 | - */ |
|
1275 | - public function getRequest() { |
|
1276 | - return $this->query('Request'); |
|
1277 | - } |
|
1278 | - |
|
1279 | - /** |
|
1280 | - * Returns the preview manager which can create preview images for a given file |
|
1281 | - * |
|
1282 | - * @return \OCP\IPreview |
|
1283 | - */ |
|
1284 | - public function getPreviewManager() { |
|
1285 | - return $this->query('PreviewManager'); |
|
1286 | - } |
|
1287 | - |
|
1288 | - /** |
|
1289 | - * Returns the tag manager which can get and set tags for different object types |
|
1290 | - * |
|
1291 | - * @see \OCP\ITagManager::load() |
|
1292 | - * @return \OCP\ITagManager |
|
1293 | - */ |
|
1294 | - public function getTagManager() { |
|
1295 | - return $this->query('TagManager'); |
|
1296 | - } |
|
1297 | - |
|
1298 | - /** |
|
1299 | - * Returns the system-tag manager |
|
1300 | - * |
|
1301 | - * @return \OCP\SystemTag\ISystemTagManager |
|
1302 | - * |
|
1303 | - * @since 9.0.0 |
|
1304 | - */ |
|
1305 | - public function getSystemTagManager() { |
|
1306 | - return $this->query('SystemTagManager'); |
|
1307 | - } |
|
1308 | - |
|
1309 | - /** |
|
1310 | - * Returns the system-tag object mapper |
|
1311 | - * |
|
1312 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1313 | - * |
|
1314 | - * @since 9.0.0 |
|
1315 | - */ |
|
1316 | - public function getSystemTagObjectMapper() { |
|
1317 | - return $this->query('SystemTagObjectMapper'); |
|
1318 | - } |
|
1319 | - |
|
1320 | - /** |
|
1321 | - * Returns the avatar manager, used for avatar functionality |
|
1322 | - * |
|
1323 | - * @return \OCP\IAvatarManager |
|
1324 | - */ |
|
1325 | - public function getAvatarManager() { |
|
1326 | - return $this->query('AvatarManager'); |
|
1327 | - } |
|
1328 | - |
|
1329 | - /** |
|
1330 | - * Returns the root folder of ownCloud's data directory |
|
1331 | - * |
|
1332 | - * @return \OCP\Files\IRootFolder |
|
1333 | - */ |
|
1334 | - public function getRootFolder() { |
|
1335 | - return $this->query('LazyRootFolder'); |
|
1336 | - } |
|
1337 | - |
|
1338 | - /** |
|
1339 | - * Returns the root folder of ownCloud's data directory |
|
1340 | - * This is the lazy variant so this gets only initialized once it |
|
1341 | - * is actually used. |
|
1342 | - * |
|
1343 | - * @return \OCP\Files\IRootFolder |
|
1344 | - */ |
|
1345 | - public function getLazyRootFolder() { |
|
1346 | - return $this->query('LazyRootFolder'); |
|
1347 | - } |
|
1348 | - |
|
1349 | - /** |
|
1350 | - * Returns a view to ownCloud's files folder |
|
1351 | - * |
|
1352 | - * @param string $userId user ID |
|
1353 | - * @return \OCP\Files\Folder|null |
|
1354 | - */ |
|
1355 | - public function getUserFolder($userId = null) { |
|
1356 | - if ($userId === null) { |
|
1357 | - $user = $this->getUserSession()->getUser(); |
|
1358 | - if (!$user) { |
|
1359 | - return null; |
|
1360 | - } |
|
1361 | - $userId = $user->getUID(); |
|
1362 | - } |
|
1363 | - $root = $this->getRootFolder(); |
|
1364 | - return $root->getUserFolder($userId); |
|
1365 | - } |
|
1366 | - |
|
1367 | - /** |
|
1368 | - * Returns an app-specific view in ownClouds data directory |
|
1369 | - * |
|
1370 | - * @return \OCP\Files\Folder |
|
1371 | - * @deprecated since 9.2.0 use IAppData |
|
1372 | - */ |
|
1373 | - public function getAppFolder() { |
|
1374 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1375 | - $root = $this->getRootFolder(); |
|
1376 | - if (!$root->nodeExists($dir)) { |
|
1377 | - $folder = $root->newFolder($dir); |
|
1378 | - } else { |
|
1379 | - $folder = $root->get($dir); |
|
1380 | - } |
|
1381 | - return $folder; |
|
1382 | - } |
|
1383 | - |
|
1384 | - /** |
|
1385 | - * @return \OC\User\Manager |
|
1386 | - */ |
|
1387 | - public function getUserManager() { |
|
1388 | - return $this->query('UserManager'); |
|
1389 | - } |
|
1390 | - |
|
1391 | - /** |
|
1392 | - * @return \OC\Group\Manager |
|
1393 | - */ |
|
1394 | - public function getGroupManager() { |
|
1395 | - return $this->query('GroupManager'); |
|
1396 | - } |
|
1397 | - |
|
1398 | - /** |
|
1399 | - * @return \OC\User\Session |
|
1400 | - */ |
|
1401 | - public function getUserSession() { |
|
1402 | - return $this->query('UserSession'); |
|
1403 | - } |
|
1404 | - |
|
1405 | - /** |
|
1406 | - * @return \OCP\ISession |
|
1407 | - */ |
|
1408 | - public function getSession() { |
|
1409 | - return $this->query('UserSession')->getSession(); |
|
1410 | - } |
|
1411 | - |
|
1412 | - /** |
|
1413 | - * @param \OCP\ISession $session |
|
1414 | - */ |
|
1415 | - public function setSession(\OCP\ISession $session) { |
|
1416 | - $this->query(SessionStorage::class)->setSession($session); |
|
1417 | - $this->query('UserSession')->setSession($session); |
|
1418 | - $this->query(Store::class)->setSession($session); |
|
1419 | - } |
|
1420 | - |
|
1421 | - /** |
|
1422 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1423 | - */ |
|
1424 | - public function getTwoFactorAuthManager() { |
|
1425 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1426 | - } |
|
1427 | - |
|
1428 | - /** |
|
1429 | - * @return \OC\NavigationManager |
|
1430 | - */ |
|
1431 | - public function getNavigationManager() { |
|
1432 | - return $this->query('NavigationManager'); |
|
1433 | - } |
|
1434 | - |
|
1435 | - /** |
|
1436 | - * @return \OCP\IConfig |
|
1437 | - */ |
|
1438 | - public function getConfig() { |
|
1439 | - return $this->query('AllConfig'); |
|
1440 | - } |
|
1441 | - |
|
1442 | - /** |
|
1443 | - * @return \OC\SystemConfig |
|
1444 | - */ |
|
1445 | - public function getSystemConfig() { |
|
1446 | - return $this->query('SystemConfig'); |
|
1447 | - } |
|
1448 | - |
|
1449 | - /** |
|
1450 | - * Returns the app config manager |
|
1451 | - * |
|
1452 | - * @return \OCP\IAppConfig |
|
1453 | - */ |
|
1454 | - public function getAppConfig() { |
|
1455 | - return $this->query('AppConfig'); |
|
1456 | - } |
|
1457 | - |
|
1458 | - /** |
|
1459 | - * @return \OCP\L10N\IFactory |
|
1460 | - */ |
|
1461 | - public function getL10NFactory() { |
|
1462 | - return $this->query('L10NFactory'); |
|
1463 | - } |
|
1464 | - |
|
1465 | - /** |
|
1466 | - * get an L10N instance |
|
1467 | - * |
|
1468 | - * @param string $app appid |
|
1469 | - * @param string $lang |
|
1470 | - * @return IL10N |
|
1471 | - */ |
|
1472 | - public function getL10N($app, $lang = null) { |
|
1473 | - return $this->getL10NFactory()->get($app, $lang); |
|
1474 | - } |
|
1475 | - |
|
1476 | - /** |
|
1477 | - * @return \OCP\IURLGenerator |
|
1478 | - */ |
|
1479 | - public function getURLGenerator() { |
|
1480 | - return $this->query('URLGenerator'); |
|
1481 | - } |
|
1482 | - |
|
1483 | - /** |
|
1484 | - * @return AppFetcher |
|
1485 | - */ |
|
1486 | - public function getAppFetcher() { |
|
1487 | - return $this->query(AppFetcher::class); |
|
1488 | - } |
|
1489 | - |
|
1490 | - /** |
|
1491 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1492 | - * getMemCacheFactory() instead. |
|
1493 | - * |
|
1494 | - * @return \OCP\ICache |
|
1495 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1496 | - */ |
|
1497 | - public function getCache() { |
|
1498 | - return $this->query('UserCache'); |
|
1499 | - } |
|
1500 | - |
|
1501 | - /** |
|
1502 | - * Returns an \OCP\CacheFactory instance |
|
1503 | - * |
|
1504 | - * @return \OCP\ICacheFactory |
|
1505 | - */ |
|
1506 | - public function getMemCacheFactory() { |
|
1507 | - return $this->query('MemCacheFactory'); |
|
1508 | - } |
|
1509 | - |
|
1510 | - /** |
|
1511 | - * Returns an \OC\RedisFactory instance |
|
1512 | - * |
|
1513 | - * @return \OC\RedisFactory |
|
1514 | - */ |
|
1515 | - public function getGetRedisFactory() { |
|
1516 | - return $this->query('RedisFactory'); |
|
1517 | - } |
|
1518 | - |
|
1519 | - |
|
1520 | - /** |
|
1521 | - * Returns the current session |
|
1522 | - * |
|
1523 | - * @return \OCP\IDBConnection |
|
1524 | - */ |
|
1525 | - public function getDatabaseConnection() { |
|
1526 | - return $this->query('DatabaseConnection'); |
|
1527 | - } |
|
1528 | - |
|
1529 | - /** |
|
1530 | - * Returns the activity manager |
|
1531 | - * |
|
1532 | - * @return \OCP\Activity\IManager |
|
1533 | - */ |
|
1534 | - public function getActivityManager() { |
|
1535 | - return $this->query('ActivityManager'); |
|
1536 | - } |
|
1537 | - |
|
1538 | - /** |
|
1539 | - * Returns an job list for controlling background jobs |
|
1540 | - * |
|
1541 | - * @return \OCP\BackgroundJob\IJobList |
|
1542 | - */ |
|
1543 | - public function getJobList() { |
|
1544 | - return $this->query('JobList'); |
|
1545 | - } |
|
1546 | - |
|
1547 | - /** |
|
1548 | - * Returns a logger instance |
|
1549 | - * |
|
1550 | - * @return \OCP\ILogger |
|
1551 | - */ |
|
1552 | - public function getLogger() { |
|
1553 | - return $this->query('Logger'); |
|
1554 | - } |
|
1555 | - |
|
1556 | - /** |
|
1557 | - * @return ILogFactory |
|
1558 | - * @throws \OCP\AppFramework\QueryException |
|
1559 | - */ |
|
1560 | - public function getLogFactory() { |
|
1561 | - return $this->query(ILogFactory::class); |
|
1562 | - } |
|
1563 | - |
|
1564 | - /** |
|
1565 | - * Returns a router for generating and matching urls |
|
1566 | - * |
|
1567 | - * @return \OCP\Route\IRouter |
|
1568 | - */ |
|
1569 | - public function getRouter() { |
|
1570 | - return $this->query('Router'); |
|
1571 | - } |
|
1572 | - |
|
1573 | - /** |
|
1574 | - * Returns a search instance |
|
1575 | - * |
|
1576 | - * @return \OCP\ISearch |
|
1577 | - */ |
|
1578 | - public function getSearch() { |
|
1579 | - return $this->query('Search'); |
|
1580 | - } |
|
1581 | - |
|
1582 | - /** |
|
1583 | - * Returns a SecureRandom instance |
|
1584 | - * |
|
1585 | - * @return \OCP\Security\ISecureRandom |
|
1586 | - */ |
|
1587 | - public function getSecureRandom() { |
|
1588 | - return $this->query('SecureRandom'); |
|
1589 | - } |
|
1590 | - |
|
1591 | - /** |
|
1592 | - * Returns a Crypto instance |
|
1593 | - * |
|
1594 | - * @return \OCP\Security\ICrypto |
|
1595 | - */ |
|
1596 | - public function getCrypto() { |
|
1597 | - return $this->query('Crypto'); |
|
1598 | - } |
|
1599 | - |
|
1600 | - /** |
|
1601 | - * Returns a Hasher instance |
|
1602 | - * |
|
1603 | - * @return \OCP\Security\IHasher |
|
1604 | - */ |
|
1605 | - public function getHasher() { |
|
1606 | - return $this->query('Hasher'); |
|
1607 | - } |
|
1608 | - |
|
1609 | - /** |
|
1610 | - * Returns a CredentialsManager instance |
|
1611 | - * |
|
1612 | - * @return \OCP\Security\ICredentialsManager |
|
1613 | - */ |
|
1614 | - public function getCredentialsManager() { |
|
1615 | - return $this->query('CredentialsManager'); |
|
1616 | - } |
|
1617 | - |
|
1618 | - /** |
|
1619 | - * Get the certificate manager for the user |
|
1620 | - * |
|
1621 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1622 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1623 | - */ |
|
1624 | - public function getCertificateManager($userId = '') { |
|
1625 | - if ($userId === '') { |
|
1626 | - $userSession = $this->getUserSession(); |
|
1627 | - $user = $userSession->getUser(); |
|
1628 | - if (is_null($user)) { |
|
1629 | - return null; |
|
1630 | - } |
|
1631 | - $userId = $user->getUID(); |
|
1632 | - } |
|
1633 | - return new CertificateManager( |
|
1634 | - $userId, |
|
1635 | - new View(), |
|
1636 | - $this->getConfig(), |
|
1637 | - $this->getLogger(), |
|
1638 | - $this->getSecureRandom() |
|
1639 | - ); |
|
1640 | - } |
|
1641 | - |
|
1642 | - /** |
|
1643 | - * Returns an instance of the HTTP client service |
|
1644 | - * |
|
1645 | - * @return \OCP\Http\Client\IClientService |
|
1646 | - */ |
|
1647 | - public function getHTTPClientService() { |
|
1648 | - return $this->query('HttpClientService'); |
|
1649 | - } |
|
1650 | - |
|
1651 | - /** |
|
1652 | - * Create a new event source |
|
1653 | - * |
|
1654 | - * @return \OCP\IEventSource |
|
1655 | - */ |
|
1656 | - public function createEventSource() { |
|
1657 | - return new \OC_EventSource(); |
|
1658 | - } |
|
1659 | - |
|
1660 | - /** |
|
1661 | - * Get the active event logger |
|
1662 | - * |
|
1663 | - * The returned logger only logs data when debug mode is enabled |
|
1664 | - * |
|
1665 | - * @return \OCP\Diagnostics\IEventLogger |
|
1666 | - */ |
|
1667 | - public function getEventLogger() { |
|
1668 | - return $this->query('EventLogger'); |
|
1669 | - } |
|
1670 | - |
|
1671 | - /** |
|
1672 | - * Get the active query logger |
|
1673 | - * |
|
1674 | - * The returned logger only logs data when debug mode is enabled |
|
1675 | - * |
|
1676 | - * @return \OCP\Diagnostics\IQueryLogger |
|
1677 | - */ |
|
1678 | - public function getQueryLogger() { |
|
1679 | - return $this->query('QueryLogger'); |
|
1680 | - } |
|
1681 | - |
|
1682 | - /** |
|
1683 | - * Get the manager for temporary files and folders |
|
1684 | - * |
|
1685 | - * @return \OCP\ITempManager |
|
1686 | - */ |
|
1687 | - public function getTempManager() { |
|
1688 | - return $this->query('TempManager'); |
|
1689 | - } |
|
1690 | - |
|
1691 | - /** |
|
1692 | - * Get the app manager |
|
1693 | - * |
|
1694 | - * @return \OCP\App\IAppManager |
|
1695 | - */ |
|
1696 | - public function getAppManager() { |
|
1697 | - return $this->query('AppManager'); |
|
1698 | - } |
|
1699 | - |
|
1700 | - /** |
|
1701 | - * Creates a new mailer |
|
1702 | - * |
|
1703 | - * @return \OCP\Mail\IMailer |
|
1704 | - */ |
|
1705 | - public function getMailer() { |
|
1706 | - return $this->query('Mailer'); |
|
1707 | - } |
|
1708 | - |
|
1709 | - /** |
|
1710 | - * Get the webroot |
|
1711 | - * |
|
1712 | - * @return string |
|
1713 | - */ |
|
1714 | - public function getWebRoot() { |
|
1715 | - return $this->webRoot; |
|
1716 | - } |
|
1717 | - |
|
1718 | - /** |
|
1719 | - * @return \OC\OCSClient |
|
1720 | - */ |
|
1721 | - public function getOcsClient() { |
|
1722 | - return $this->query('OcsClient'); |
|
1723 | - } |
|
1724 | - |
|
1725 | - /** |
|
1726 | - * @return \OCP\IDateTimeZone |
|
1727 | - */ |
|
1728 | - public function getDateTimeZone() { |
|
1729 | - return $this->query('DateTimeZone'); |
|
1730 | - } |
|
1731 | - |
|
1732 | - /** |
|
1733 | - * @return \OCP\IDateTimeFormatter |
|
1734 | - */ |
|
1735 | - public function getDateTimeFormatter() { |
|
1736 | - return $this->query('DateTimeFormatter'); |
|
1737 | - } |
|
1738 | - |
|
1739 | - /** |
|
1740 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
1741 | - */ |
|
1742 | - public function getMountProviderCollection() { |
|
1743 | - return $this->query('MountConfigManager'); |
|
1744 | - } |
|
1745 | - |
|
1746 | - /** |
|
1747 | - * Get the IniWrapper |
|
1748 | - * |
|
1749 | - * @return IniGetWrapper |
|
1750 | - */ |
|
1751 | - public function getIniWrapper() { |
|
1752 | - return $this->query('IniWrapper'); |
|
1753 | - } |
|
1754 | - |
|
1755 | - /** |
|
1756 | - * @return \OCP\Command\IBus |
|
1757 | - */ |
|
1758 | - public function getCommandBus() { |
|
1759 | - return $this->query('AsyncCommandBus'); |
|
1760 | - } |
|
1761 | - |
|
1762 | - /** |
|
1763 | - * Get the trusted domain helper |
|
1764 | - * |
|
1765 | - * @return TrustedDomainHelper |
|
1766 | - */ |
|
1767 | - public function getTrustedDomainHelper() { |
|
1768 | - return $this->query('TrustedDomainHelper'); |
|
1769 | - } |
|
1770 | - |
|
1771 | - /** |
|
1772 | - * Get the locking provider |
|
1773 | - * |
|
1774 | - * @return \OCP\Lock\ILockingProvider |
|
1775 | - * @since 8.1.0 |
|
1776 | - */ |
|
1777 | - public function getLockingProvider() { |
|
1778 | - return $this->query('LockingProvider'); |
|
1779 | - } |
|
1780 | - |
|
1781 | - /** |
|
1782 | - * @return \OCP\Files\Mount\IMountManager |
|
1783 | - **/ |
|
1784 | - function getMountManager() { |
|
1785 | - return $this->query('MountManager'); |
|
1786 | - } |
|
1787 | - |
|
1788 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
1789 | - function getUserMountCache() { |
|
1790 | - return $this->query('UserMountCache'); |
|
1791 | - } |
|
1792 | - |
|
1793 | - /** |
|
1794 | - * Get the MimeTypeDetector |
|
1795 | - * |
|
1796 | - * @return \OCP\Files\IMimeTypeDetector |
|
1797 | - */ |
|
1798 | - public function getMimeTypeDetector() { |
|
1799 | - return $this->query('MimeTypeDetector'); |
|
1800 | - } |
|
1801 | - |
|
1802 | - /** |
|
1803 | - * Get the MimeTypeLoader |
|
1804 | - * |
|
1805 | - * @return \OCP\Files\IMimeTypeLoader |
|
1806 | - */ |
|
1807 | - public function getMimeTypeLoader() { |
|
1808 | - return $this->query('MimeTypeLoader'); |
|
1809 | - } |
|
1810 | - |
|
1811 | - /** |
|
1812 | - * Get the manager of all the capabilities |
|
1813 | - * |
|
1814 | - * @return \OC\CapabilitiesManager |
|
1815 | - */ |
|
1816 | - public function getCapabilitiesManager() { |
|
1817 | - return $this->query('CapabilitiesManager'); |
|
1818 | - } |
|
1819 | - |
|
1820 | - /** |
|
1821 | - * Get the EventDispatcher |
|
1822 | - * |
|
1823 | - * @return EventDispatcherInterface |
|
1824 | - * @since 8.2.0 |
|
1825 | - */ |
|
1826 | - public function getEventDispatcher() { |
|
1827 | - return $this->query('EventDispatcher'); |
|
1828 | - } |
|
1829 | - |
|
1830 | - /** |
|
1831 | - * Get the Notification Manager |
|
1832 | - * |
|
1833 | - * @return \OCP\Notification\IManager |
|
1834 | - * @since 8.2.0 |
|
1835 | - */ |
|
1836 | - public function getNotificationManager() { |
|
1837 | - return $this->query('NotificationManager'); |
|
1838 | - } |
|
1839 | - |
|
1840 | - /** |
|
1841 | - * @return \OCP\Comments\ICommentsManager |
|
1842 | - */ |
|
1843 | - public function getCommentsManager() { |
|
1844 | - return $this->query('CommentsManager'); |
|
1845 | - } |
|
1846 | - |
|
1847 | - /** |
|
1848 | - * @return \OCA\Theming\ThemingDefaults |
|
1849 | - */ |
|
1850 | - public function getThemingDefaults() { |
|
1851 | - return $this->query('ThemingDefaults'); |
|
1852 | - } |
|
1853 | - |
|
1854 | - /** |
|
1855 | - * @return \OC\IntegrityCheck\Checker |
|
1856 | - */ |
|
1857 | - public function getIntegrityCodeChecker() { |
|
1858 | - return $this->query('IntegrityCodeChecker'); |
|
1859 | - } |
|
1860 | - |
|
1861 | - /** |
|
1862 | - * @return \OC\Session\CryptoWrapper |
|
1863 | - */ |
|
1864 | - public function getSessionCryptoWrapper() { |
|
1865 | - return $this->query('CryptoWrapper'); |
|
1866 | - } |
|
1867 | - |
|
1868 | - /** |
|
1869 | - * @return CsrfTokenManager |
|
1870 | - */ |
|
1871 | - public function getCsrfTokenManager() { |
|
1872 | - return $this->query('CsrfTokenManager'); |
|
1873 | - } |
|
1874 | - |
|
1875 | - /** |
|
1876 | - * @return Throttler |
|
1877 | - */ |
|
1878 | - public function getBruteForceThrottler() { |
|
1879 | - return $this->query('Throttler'); |
|
1880 | - } |
|
1881 | - |
|
1882 | - /** |
|
1883 | - * @return IContentSecurityPolicyManager |
|
1884 | - */ |
|
1885 | - public function getContentSecurityPolicyManager() { |
|
1886 | - return $this->query('ContentSecurityPolicyManager'); |
|
1887 | - } |
|
1888 | - |
|
1889 | - /** |
|
1890 | - * @return ContentSecurityPolicyNonceManager |
|
1891 | - */ |
|
1892 | - public function getContentSecurityPolicyNonceManager() { |
|
1893 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
1894 | - } |
|
1895 | - |
|
1896 | - /** |
|
1897 | - * Not a public API as of 8.2, wait for 9.0 |
|
1898 | - * |
|
1899 | - * @return \OCA\Files_External\Service\BackendService |
|
1900 | - */ |
|
1901 | - public function getStoragesBackendService() { |
|
1902 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1903 | - } |
|
1904 | - |
|
1905 | - /** |
|
1906 | - * Not a public API as of 8.2, wait for 9.0 |
|
1907 | - * |
|
1908 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1909 | - */ |
|
1910 | - public function getGlobalStoragesService() { |
|
1911 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1912 | - } |
|
1913 | - |
|
1914 | - /** |
|
1915 | - * Not a public API as of 8.2, wait for 9.0 |
|
1916 | - * |
|
1917 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1918 | - */ |
|
1919 | - public function getUserGlobalStoragesService() { |
|
1920 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1921 | - } |
|
1922 | - |
|
1923 | - /** |
|
1924 | - * Not a public API as of 8.2, wait for 9.0 |
|
1925 | - * |
|
1926 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
1927 | - */ |
|
1928 | - public function getUserStoragesService() { |
|
1929 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1930 | - } |
|
1931 | - |
|
1932 | - /** |
|
1933 | - * @return \OCP\Share\IManager |
|
1934 | - */ |
|
1935 | - public function getShareManager() { |
|
1936 | - return $this->query('ShareManager'); |
|
1937 | - } |
|
1938 | - |
|
1939 | - /** |
|
1940 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
1941 | - */ |
|
1942 | - public function getCollaboratorSearch() { |
|
1943 | - return $this->query('CollaboratorSearch'); |
|
1944 | - } |
|
1945 | - |
|
1946 | - /** |
|
1947 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
1948 | - */ |
|
1949 | - public function getAutoCompleteManager(){ |
|
1950 | - return $this->query(IManager::class); |
|
1951 | - } |
|
1952 | - |
|
1953 | - /** |
|
1954 | - * Returns the LDAP Provider |
|
1955 | - * |
|
1956 | - * @return \OCP\LDAP\ILDAPProvider |
|
1957 | - */ |
|
1958 | - public function getLDAPProvider() { |
|
1959 | - return $this->query('LDAPProvider'); |
|
1960 | - } |
|
1961 | - |
|
1962 | - /** |
|
1963 | - * @return \OCP\Settings\IManager |
|
1964 | - */ |
|
1965 | - public function getSettingsManager() { |
|
1966 | - return $this->query('SettingsManager'); |
|
1967 | - } |
|
1968 | - |
|
1969 | - /** |
|
1970 | - * @return \OCP\Files\IAppData |
|
1971 | - */ |
|
1972 | - public function getAppDataDir($app) { |
|
1973 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
1974 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1975 | - return $factory->get($app); |
|
1976 | - } |
|
1977 | - |
|
1978 | - /** |
|
1979 | - * @return \OCP\Lockdown\ILockdownManager |
|
1980 | - */ |
|
1981 | - public function getLockdownManager() { |
|
1982 | - return $this->query('LockdownManager'); |
|
1983 | - } |
|
1984 | - |
|
1985 | - /** |
|
1986 | - * @return \OCP\Federation\ICloudIdManager |
|
1987 | - */ |
|
1988 | - public function getCloudIdManager() { |
|
1989 | - return $this->query(ICloudIdManager::class); |
|
1990 | - } |
|
1991 | - |
|
1992 | - /** |
|
1993 | - * @return \OCP\GlobalScale\IConfig |
|
1994 | - */ |
|
1995 | - public function getGlobalScaleConfig() { |
|
1996 | - return $this->query(IConfig::class); |
|
1997 | - } |
|
1998 | - |
|
1999 | - /** |
|
2000 | - * @return \OCP\Federation\ICloudFederationProviderManager |
|
2001 | - */ |
|
2002 | - public function getCloudFederationProviderManager() { |
|
2003 | - return $this->query(ICloudFederationProviderManager::class); |
|
2004 | - } |
|
2005 | - |
|
2006 | - /** |
|
2007 | - * @return \OCP\Remote\Api\IApiFactory |
|
2008 | - */ |
|
2009 | - public function getRemoteApiFactory() { |
|
2010 | - return $this->query(IApiFactory::class); |
|
2011 | - } |
|
2012 | - |
|
2013 | - /** |
|
2014 | - * @return \OCP\Federation\ICloudFederationFactory |
|
2015 | - */ |
|
2016 | - public function getCloudFederationFactory() { |
|
2017 | - return $this->query(ICloudFederationFactory::class); |
|
2018 | - } |
|
2019 | - |
|
2020 | - /** |
|
2021 | - * @return \OCP\Remote\IInstanceFactory |
|
2022 | - */ |
|
2023 | - public function getRemoteInstanceFactory() { |
|
2024 | - return $this->query(IInstanceFactory::class); |
|
2025 | - } |
|
948 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
949 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
950 | + $classExists = true; |
|
951 | + } else { |
|
952 | + $classExists = false; |
|
953 | + } |
|
954 | + |
|
955 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
956 | + return new ThemingDefaults( |
|
957 | + $c->getConfig(), |
|
958 | + $c->getL10N('theming'), |
|
959 | + $c->getURLGenerator(), |
|
960 | + $c->getMemCacheFactory(), |
|
961 | + new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
962 | + new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator()), |
|
963 | + $c->getAppManager() |
|
964 | + ); |
|
965 | + } |
|
966 | + return new \OC_Defaults(); |
|
967 | + }); |
|
968 | + $this->registerService(SCSSCacher::class, function (Server $c) { |
|
969 | + /** @var Factory $cacheFactory */ |
|
970 | + $cacheFactory = $c->query(Factory::class); |
|
971 | + return new SCSSCacher( |
|
972 | + $c->getLogger(), |
|
973 | + $c->query(\OC\Files\AppData\Factory::class), |
|
974 | + $c->getURLGenerator(), |
|
975 | + $c->getConfig(), |
|
976 | + $c->getThemingDefaults(), |
|
977 | + \OC::$SERVERROOT, |
|
978 | + $this->getMemCacheFactory() |
|
979 | + ); |
|
980 | + }); |
|
981 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
982 | + /** @var Factory $cacheFactory */ |
|
983 | + $cacheFactory = $c->query(Factory::class); |
|
984 | + return new JSCombiner( |
|
985 | + $c->getAppDataDir('js'), |
|
986 | + $c->getURLGenerator(), |
|
987 | + $this->getMemCacheFactory(), |
|
988 | + $c->getSystemConfig(), |
|
989 | + $c->getLogger() |
|
990 | + ); |
|
991 | + }); |
|
992 | + $this->registerService(EventDispatcher::class, function () { |
|
993 | + return new EventDispatcher(); |
|
994 | + }); |
|
995 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
996 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
997 | + |
|
998 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
999 | + // FIXME: Instantiiated here due to cyclic dependency |
|
1000 | + $request = new Request( |
|
1001 | + [ |
|
1002 | + 'get' => $_GET, |
|
1003 | + 'post' => $_POST, |
|
1004 | + 'files' => $_FILES, |
|
1005 | + 'server' => $_SERVER, |
|
1006 | + 'env' => $_ENV, |
|
1007 | + 'cookies' => $_COOKIE, |
|
1008 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1009 | + ? $_SERVER['REQUEST_METHOD'] |
|
1010 | + : null, |
|
1011 | + ], |
|
1012 | + $c->getSecureRandom(), |
|
1013 | + $c->getConfig() |
|
1014 | + ); |
|
1015 | + |
|
1016 | + return new CryptoWrapper( |
|
1017 | + $c->getConfig(), |
|
1018 | + $c->getCrypto(), |
|
1019 | + $c->getSecureRandom(), |
|
1020 | + $request |
|
1021 | + ); |
|
1022 | + }); |
|
1023 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1024 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1025 | + |
|
1026 | + return new CsrfTokenManager( |
|
1027 | + $tokenGenerator, |
|
1028 | + $c->query(SessionStorage::class) |
|
1029 | + ); |
|
1030 | + }); |
|
1031 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
1032 | + return new SessionStorage($c->getSession()); |
|
1033 | + }); |
|
1034 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1035 | + return new ContentSecurityPolicyManager(); |
|
1036 | + }); |
|
1037 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
1038 | + |
|
1039 | + $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1040 | + return new ContentSecurityPolicyNonceManager( |
|
1041 | + $c->getCsrfTokenManager(), |
|
1042 | + $c->getRequest() |
|
1043 | + ); |
|
1044 | + }); |
|
1045 | + |
|
1046 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1047 | + $config = $c->getConfig(); |
|
1048 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1049 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
1050 | + $factory = new $factoryClass($this); |
|
1051 | + |
|
1052 | + $manager = new \OC\Share20\Manager( |
|
1053 | + $c->getLogger(), |
|
1054 | + $c->getConfig(), |
|
1055 | + $c->getSecureRandom(), |
|
1056 | + $c->getHasher(), |
|
1057 | + $c->getMountManager(), |
|
1058 | + $c->getGroupManager(), |
|
1059 | + $c->getL10N('lib'), |
|
1060 | + $c->getL10NFactory(), |
|
1061 | + $factory, |
|
1062 | + $c->getUserManager(), |
|
1063 | + $c->getLazyRootFolder(), |
|
1064 | + $c->getEventDispatcher(), |
|
1065 | + $c->getMailer(), |
|
1066 | + $c->getURLGenerator(), |
|
1067 | + $c->getThemingDefaults() |
|
1068 | + ); |
|
1069 | + |
|
1070 | + return $manager; |
|
1071 | + }); |
|
1072 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1073 | + |
|
1074 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1075 | + $instance = new Collaboration\Collaborators\Search($c); |
|
1076 | + |
|
1077 | + // register default plugins |
|
1078 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1079 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1080 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1081 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1082 | + |
|
1083 | + return $instance; |
|
1084 | + }); |
|
1085 | + $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1086 | + |
|
1087 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1088 | + |
|
1089 | + $this->registerService('SettingsManager', function (Server $c) { |
|
1090 | + $manager = new \OC\Settings\Manager( |
|
1091 | + $c->getLogger(), |
|
1092 | + $c->getDatabaseConnection(), |
|
1093 | + $c->getL10N('lib'), |
|
1094 | + $c->getConfig(), |
|
1095 | + $c->getEncryptionManager(), |
|
1096 | + $c->getUserManager(), |
|
1097 | + $c->getLockingProvider(), |
|
1098 | + $c->getRequest(), |
|
1099 | + $c->getURLGenerator(), |
|
1100 | + $c->query(AccountManager::class), |
|
1101 | + $c->getGroupManager(), |
|
1102 | + $c->getL10NFactory(), |
|
1103 | + $c->getAppManager() |
|
1104 | + ); |
|
1105 | + return $manager; |
|
1106 | + }); |
|
1107 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1108 | + return new \OC\Files\AppData\Factory( |
|
1109 | + $c->getRootFolder(), |
|
1110 | + $c->getSystemConfig() |
|
1111 | + ); |
|
1112 | + }); |
|
1113 | + |
|
1114 | + $this->registerService('LockdownManager', function (Server $c) { |
|
1115 | + return new LockdownManager(function () use ($c) { |
|
1116 | + return $c->getSession(); |
|
1117 | + }); |
|
1118 | + }); |
|
1119 | + |
|
1120 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1121 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1122 | + }); |
|
1123 | + |
|
1124 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1125 | + return new CloudIdManager(); |
|
1126 | + }); |
|
1127 | + |
|
1128 | + $this->registerService(IConfig::class, function (Server $c) { |
|
1129 | + return new GlobalScale\Config($c->getConfig()); |
|
1130 | + }); |
|
1131 | + |
|
1132 | + $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
1133 | + return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
1134 | + }); |
|
1135 | + |
|
1136 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1137 | + return new CloudFederationFactory(); |
|
1138 | + }); |
|
1139 | + |
|
1140 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1141 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1142 | + |
|
1143 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1144 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1145 | + |
|
1146 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1147 | + return new Defaults( |
|
1148 | + $c->getThemingDefaults() |
|
1149 | + ); |
|
1150 | + }); |
|
1151 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1152 | + |
|
1153 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1154 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1155 | + }); |
|
1156 | + |
|
1157 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
1158 | + return new ShareHelper( |
|
1159 | + $c->query(\OCP\Share\IManager::class) |
|
1160 | + ); |
|
1161 | + }); |
|
1162 | + |
|
1163 | + $this->registerService(Installer::class, function(Server $c) { |
|
1164 | + return new Installer( |
|
1165 | + $c->getAppFetcher(), |
|
1166 | + $c->getHTTPClientService(), |
|
1167 | + $c->getTempManager(), |
|
1168 | + $c->getLogger(), |
|
1169 | + $c->getConfig() |
|
1170 | + ); |
|
1171 | + }); |
|
1172 | + |
|
1173 | + $this->registerService(IApiFactory::class, function(Server $c) { |
|
1174 | + return new ApiFactory($c->getHTTPClientService()); |
|
1175 | + }); |
|
1176 | + |
|
1177 | + $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1178 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
1179 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1180 | + }); |
|
1181 | + |
|
1182 | + $this->registerService(IContactsStore::class, function(Server $c) { |
|
1183 | + return new ContactsStore( |
|
1184 | + $c->getContactsManager(), |
|
1185 | + $c->getConfig(), |
|
1186 | + $c->getUserManager(), |
|
1187 | + $c->getGroupManager() |
|
1188 | + ); |
|
1189 | + }); |
|
1190 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1191 | + |
|
1192 | + $this->connectDispatcher(); |
|
1193 | + } |
|
1194 | + |
|
1195 | + /** |
|
1196 | + * @return \OCP\Calendar\IManager |
|
1197 | + */ |
|
1198 | + public function getCalendarManager() { |
|
1199 | + return $this->query('CalendarManager'); |
|
1200 | + } |
|
1201 | + |
|
1202 | + private function connectDispatcher() { |
|
1203 | + $dispatcher = $this->getEventDispatcher(); |
|
1204 | + |
|
1205 | + // Delete avatar on user deletion |
|
1206 | + $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1207 | + $logger = $this->getLogger(); |
|
1208 | + $manager = $this->getAvatarManager(); |
|
1209 | + /** @var IUser $user */ |
|
1210 | + $user = $e->getSubject(); |
|
1211 | + |
|
1212 | + try { |
|
1213 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1214 | + $avatar->remove(); |
|
1215 | + } catch (NotFoundException $e) { |
|
1216 | + // no avatar to remove |
|
1217 | + } catch (\Exception $e) { |
|
1218 | + // Ignore exceptions |
|
1219 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1220 | + } |
|
1221 | + }); |
|
1222 | + |
|
1223 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1224 | + $manager = $this->getAvatarManager(); |
|
1225 | + /** @var IUser $user */ |
|
1226 | + $user = $e->getSubject(); |
|
1227 | + $feature = $e->getArgument('feature'); |
|
1228 | + $oldValue = $e->getArgument('oldValue'); |
|
1229 | + $value = $e->getArgument('value'); |
|
1230 | + |
|
1231 | + try { |
|
1232 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1233 | + $avatar->userChanged($feature, $oldValue, $value); |
|
1234 | + } catch (NotFoundException $e) { |
|
1235 | + // no avatar to remove |
|
1236 | + } |
|
1237 | + }); |
|
1238 | + } |
|
1239 | + |
|
1240 | + /** |
|
1241 | + * @return \OCP\Contacts\IManager |
|
1242 | + */ |
|
1243 | + public function getContactsManager() { |
|
1244 | + return $this->query('ContactsManager'); |
|
1245 | + } |
|
1246 | + |
|
1247 | + /** |
|
1248 | + * @return \OC\Encryption\Manager |
|
1249 | + */ |
|
1250 | + public function getEncryptionManager() { |
|
1251 | + return $this->query('EncryptionManager'); |
|
1252 | + } |
|
1253 | + |
|
1254 | + /** |
|
1255 | + * @return \OC\Encryption\File |
|
1256 | + */ |
|
1257 | + public function getEncryptionFilesHelper() { |
|
1258 | + return $this->query('EncryptionFileHelper'); |
|
1259 | + } |
|
1260 | + |
|
1261 | + /** |
|
1262 | + * @return \OCP\Encryption\Keys\IStorage |
|
1263 | + */ |
|
1264 | + public function getEncryptionKeyStorage() { |
|
1265 | + return $this->query('EncryptionKeyStorage'); |
|
1266 | + } |
|
1267 | + |
|
1268 | + /** |
|
1269 | + * The current request object holding all information about the request |
|
1270 | + * currently being processed is returned from this method. |
|
1271 | + * In case the current execution was not initiated by a web request null is returned |
|
1272 | + * |
|
1273 | + * @return \OCP\IRequest |
|
1274 | + */ |
|
1275 | + public function getRequest() { |
|
1276 | + return $this->query('Request'); |
|
1277 | + } |
|
1278 | + |
|
1279 | + /** |
|
1280 | + * Returns the preview manager which can create preview images for a given file |
|
1281 | + * |
|
1282 | + * @return \OCP\IPreview |
|
1283 | + */ |
|
1284 | + public function getPreviewManager() { |
|
1285 | + return $this->query('PreviewManager'); |
|
1286 | + } |
|
1287 | + |
|
1288 | + /** |
|
1289 | + * Returns the tag manager which can get and set tags for different object types |
|
1290 | + * |
|
1291 | + * @see \OCP\ITagManager::load() |
|
1292 | + * @return \OCP\ITagManager |
|
1293 | + */ |
|
1294 | + public function getTagManager() { |
|
1295 | + return $this->query('TagManager'); |
|
1296 | + } |
|
1297 | + |
|
1298 | + /** |
|
1299 | + * Returns the system-tag manager |
|
1300 | + * |
|
1301 | + * @return \OCP\SystemTag\ISystemTagManager |
|
1302 | + * |
|
1303 | + * @since 9.0.0 |
|
1304 | + */ |
|
1305 | + public function getSystemTagManager() { |
|
1306 | + return $this->query('SystemTagManager'); |
|
1307 | + } |
|
1308 | + |
|
1309 | + /** |
|
1310 | + * Returns the system-tag object mapper |
|
1311 | + * |
|
1312 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1313 | + * |
|
1314 | + * @since 9.0.0 |
|
1315 | + */ |
|
1316 | + public function getSystemTagObjectMapper() { |
|
1317 | + return $this->query('SystemTagObjectMapper'); |
|
1318 | + } |
|
1319 | + |
|
1320 | + /** |
|
1321 | + * Returns the avatar manager, used for avatar functionality |
|
1322 | + * |
|
1323 | + * @return \OCP\IAvatarManager |
|
1324 | + */ |
|
1325 | + public function getAvatarManager() { |
|
1326 | + return $this->query('AvatarManager'); |
|
1327 | + } |
|
1328 | + |
|
1329 | + /** |
|
1330 | + * Returns the root folder of ownCloud's data directory |
|
1331 | + * |
|
1332 | + * @return \OCP\Files\IRootFolder |
|
1333 | + */ |
|
1334 | + public function getRootFolder() { |
|
1335 | + return $this->query('LazyRootFolder'); |
|
1336 | + } |
|
1337 | + |
|
1338 | + /** |
|
1339 | + * Returns the root folder of ownCloud's data directory |
|
1340 | + * This is the lazy variant so this gets only initialized once it |
|
1341 | + * is actually used. |
|
1342 | + * |
|
1343 | + * @return \OCP\Files\IRootFolder |
|
1344 | + */ |
|
1345 | + public function getLazyRootFolder() { |
|
1346 | + return $this->query('LazyRootFolder'); |
|
1347 | + } |
|
1348 | + |
|
1349 | + /** |
|
1350 | + * Returns a view to ownCloud's files folder |
|
1351 | + * |
|
1352 | + * @param string $userId user ID |
|
1353 | + * @return \OCP\Files\Folder|null |
|
1354 | + */ |
|
1355 | + public function getUserFolder($userId = null) { |
|
1356 | + if ($userId === null) { |
|
1357 | + $user = $this->getUserSession()->getUser(); |
|
1358 | + if (!$user) { |
|
1359 | + return null; |
|
1360 | + } |
|
1361 | + $userId = $user->getUID(); |
|
1362 | + } |
|
1363 | + $root = $this->getRootFolder(); |
|
1364 | + return $root->getUserFolder($userId); |
|
1365 | + } |
|
1366 | + |
|
1367 | + /** |
|
1368 | + * Returns an app-specific view in ownClouds data directory |
|
1369 | + * |
|
1370 | + * @return \OCP\Files\Folder |
|
1371 | + * @deprecated since 9.2.0 use IAppData |
|
1372 | + */ |
|
1373 | + public function getAppFolder() { |
|
1374 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
1375 | + $root = $this->getRootFolder(); |
|
1376 | + if (!$root->nodeExists($dir)) { |
|
1377 | + $folder = $root->newFolder($dir); |
|
1378 | + } else { |
|
1379 | + $folder = $root->get($dir); |
|
1380 | + } |
|
1381 | + return $folder; |
|
1382 | + } |
|
1383 | + |
|
1384 | + /** |
|
1385 | + * @return \OC\User\Manager |
|
1386 | + */ |
|
1387 | + public function getUserManager() { |
|
1388 | + return $this->query('UserManager'); |
|
1389 | + } |
|
1390 | + |
|
1391 | + /** |
|
1392 | + * @return \OC\Group\Manager |
|
1393 | + */ |
|
1394 | + public function getGroupManager() { |
|
1395 | + return $this->query('GroupManager'); |
|
1396 | + } |
|
1397 | + |
|
1398 | + /** |
|
1399 | + * @return \OC\User\Session |
|
1400 | + */ |
|
1401 | + public function getUserSession() { |
|
1402 | + return $this->query('UserSession'); |
|
1403 | + } |
|
1404 | + |
|
1405 | + /** |
|
1406 | + * @return \OCP\ISession |
|
1407 | + */ |
|
1408 | + public function getSession() { |
|
1409 | + return $this->query('UserSession')->getSession(); |
|
1410 | + } |
|
1411 | + |
|
1412 | + /** |
|
1413 | + * @param \OCP\ISession $session |
|
1414 | + */ |
|
1415 | + public function setSession(\OCP\ISession $session) { |
|
1416 | + $this->query(SessionStorage::class)->setSession($session); |
|
1417 | + $this->query('UserSession')->setSession($session); |
|
1418 | + $this->query(Store::class)->setSession($session); |
|
1419 | + } |
|
1420 | + |
|
1421 | + /** |
|
1422 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1423 | + */ |
|
1424 | + public function getTwoFactorAuthManager() { |
|
1425 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1426 | + } |
|
1427 | + |
|
1428 | + /** |
|
1429 | + * @return \OC\NavigationManager |
|
1430 | + */ |
|
1431 | + public function getNavigationManager() { |
|
1432 | + return $this->query('NavigationManager'); |
|
1433 | + } |
|
1434 | + |
|
1435 | + /** |
|
1436 | + * @return \OCP\IConfig |
|
1437 | + */ |
|
1438 | + public function getConfig() { |
|
1439 | + return $this->query('AllConfig'); |
|
1440 | + } |
|
1441 | + |
|
1442 | + /** |
|
1443 | + * @return \OC\SystemConfig |
|
1444 | + */ |
|
1445 | + public function getSystemConfig() { |
|
1446 | + return $this->query('SystemConfig'); |
|
1447 | + } |
|
1448 | + |
|
1449 | + /** |
|
1450 | + * Returns the app config manager |
|
1451 | + * |
|
1452 | + * @return \OCP\IAppConfig |
|
1453 | + */ |
|
1454 | + public function getAppConfig() { |
|
1455 | + return $this->query('AppConfig'); |
|
1456 | + } |
|
1457 | + |
|
1458 | + /** |
|
1459 | + * @return \OCP\L10N\IFactory |
|
1460 | + */ |
|
1461 | + public function getL10NFactory() { |
|
1462 | + return $this->query('L10NFactory'); |
|
1463 | + } |
|
1464 | + |
|
1465 | + /** |
|
1466 | + * get an L10N instance |
|
1467 | + * |
|
1468 | + * @param string $app appid |
|
1469 | + * @param string $lang |
|
1470 | + * @return IL10N |
|
1471 | + */ |
|
1472 | + public function getL10N($app, $lang = null) { |
|
1473 | + return $this->getL10NFactory()->get($app, $lang); |
|
1474 | + } |
|
1475 | + |
|
1476 | + /** |
|
1477 | + * @return \OCP\IURLGenerator |
|
1478 | + */ |
|
1479 | + public function getURLGenerator() { |
|
1480 | + return $this->query('URLGenerator'); |
|
1481 | + } |
|
1482 | + |
|
1483 | + /** |
|
1484 | + * @return AppFetcher |
|
1485 | + */ |
|
1486 | + public function getAppFetcher() { |
|
1487 | + return $this->query(AppFetcher::class); |
|
1488 | + } |
|
1489 | + |
|
1490 | + /** |
|
1491 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1492 | + * getMemCacheFactory() instead. |
|
1493 | + * |
|
1494 | + * @return \OCP\ICache |
|
1495 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1496 | + */ |
|
1497 | + public function getCache() { |
|
1498 | + return $this->query('UserCache'); |
|
1499 | + } |
|
1500 | + |
|
1501 | + /** |
|
1502 | + * Returns an \OCP\CacheFactory instance |
|
1503 | + * |
|
1504 | + * @return \OCP\ICacheFactory |
|
1505 | + */ |
|
1506 | + public function getMemCacheFactory() { |
|
1507 | + return $this->query('MemCacheFactory'); |
|
1508 | + } |
|
1509 | + |
|
1510 | + /** |
|
1511 | + * Returns an \OC\RedisFactory instance |
|
1512 | + * |
|
1513 | + * @return \OC\RedisFactory |
|
1514 | + */ |
|
1515 | + public function getGetRedisFactory() { |
|
1516 | + return $this->query('RedisFactory'); |
|
1517 | + } |
|
1518 | + |
|
1519 | + |
|
1520 | + /** |
|
1521 | + * Returns the current session |
|
1522 | + * |
|
1523 | + * @return \OCP\IDBConnection |
|
1524 | + */ |
|
1525 | + public function getDatabaseConnection() { |
|
1526 | + return $this->query('DatabaseConnection'); |
|
1527 | + } |
|
1528 | + |
|
1529 | + /** |
|
1530 | + * Returns the activity manager |
|
1531 | + * |
|
1532 | + * @return \OCP\Activity\IManager |
|
1533 | + */ |
|
1534 | + public function getActivityManager() { |
|
1535 | + return $this->query('ActivityManager'); |
|
1536 | + } |
|
1537 | + |
|
1538 | + /** |
|
1539 | + * Returns an job list for controlling background jobs |
|
1540 | + * |
|
1541 | + * @return \OCP\BackgroundJob\IJobList |
|
1542 | + */ |
|
1543 | + public function getJobList() { |
|
1544 | + return $this->query('JobList'); |
|
1545 | + } |
|
1546 | + |
|
1547 | + /** |
|
1548 | + * Returns a logger instance |
|
1549 | + * |
|
1550 | + * @return \OCP\ILogger |
|
1551 | + */ |
|
1552 | + public function getLogger() { |
|
1553 | + return $this->query('Logger'); |
|
1554 | + } |
|
1555 | + |
|
1556 | + /** |
|
1557 | + * @return ILogFactory |
|
1558 | + * @throws \OCP\AppFramework\QueryException |
|
1559 | + */ |
|
1560 | + public function getLogFactory() { |
|
1561 | + return $this->query(ILogFactory::class); |
|
1562 | + } |
|
1563 | + |
|
1564 | + /** |
|
1565 | + * Returns a router for generating and matching urls |
|
1566 | + * |
|
1567 | + * @return \OCP\Route\IRouter |
|
1568 | + */ |
|
1569 | + public function getRouter() { |
|
1570 | + return $this->query('Router'); |
|
1571 | + } |
|
1572 | + |
|
1573 | + /** |
|
1574 | + * Returns a search instance |
|
1575 | + * |
|
1576 | + * @return \OCP\ISearch |
|
1577 | + */ |
|
1578 | + public function getSearch() { |
|
1579 | + return $this->query('Search'); |
|
1580 | + } |
|
1581 | + |
|
1582 | + /** |
|
1583 | + * Returns a SecureRandom instance |
|
1584 | + * |
|
1585 | + * @return \OCP\Security\ISecureRandom |
|
1586 | + */ |
|
1587 | + public function getSecureRandom() { |
|
1588 | + return $this->query('SecureRandom'); |
|
1589 | + } |
|
1590 | + |
|
1591 | + /** |
|
1592 | + * Returns a Crypto instance |
|
1593 | + * |
|
1594 | + * @return \OCP\Security\ICrypto |
|
1595 | + */ |
|
1596 | + public function getCrypto() { |
|
1597 | + return $this->query('Crypto'); |
|
1598 | + } |
|
1599 | + |
|
1600 | + /** |
|
1601 | + * Returns a Hasher instance |
|
1602 | + * |
|
1603 | + * @return \OCP\Security\IHasher |
|
1604 | + */ |
|
1605 | + public function getHasher() { |
|
1606 | + return $this->query('Hasher'); |
|
1607 | + } |
|
1608 | + |
|
1609 | + /** |
|
1610 | + * Returns a CredentialsManager instance |
|
1611 | + * |
|
1612 | + * @return \OCP\Security\ICredentialsManager |
|
1613 | + */ |
|
1614 | + public function getCredentialsManager() { |
|
1615 | + return $this->query('CredentialsManager'); |
|
1616 | + } |
|
1617 | + |
|
1618 | + /** |
|
1619 | + * Get the certificate manager for the user |
|
1620 | + * |
|
1621 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1622 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1623 | + */ |
|
1624 | + public function getCertificateManager($userId = '') { |
|
1625 | + if ($userId === '') { |
|
1626 | + $userSession = $this->getUserSession(); |
|
1627 | + $user = $userSession->getUser(); |
|
1628 | + if (is_null($user)) { |
|
1629 | + return null; |
|
1630 | + } |
|
1631 | + $userId = $user->getUID(); |
|
1632 | + } |
|
1633 | + return new CertificateManager( |
|
1634 | + $userId, |
|
1635 | + new View(), |
|
1636 | + $this->getConfig(), |
|
1637 | + $this->getLogger(), |
|
1638 | + $this->getSecureRandom() |
|
1639 | + ); |
|
1640 | + } |
|
1641 | + |
|
1642 | + /** |
|
1643 | + * Returns an instance of the HTTP client service |
|
1644 | + * |
|
1645 | + * @return \OCP\Http\Client\IClientService |
|
1646 | + */ |
|
1647 | + public function getHTTPClientService() { |
|
1648 | + return $this->query('HttpClientService'); |
|
1649 | + } |
|
1650 | + |
|
1651 | + /** |
|
1652 | + * Create a new event source |
|
1653 | + * |
|
1654 | + * @return \OCP\IEventSource |
|
1655 | + */ |
|
1656 | + public function createEventSource() { |
|
1657 | + return new \OC_EventSource(); |
|
1658 | + } |
|
1659 | + |
|
1660 | + /** |
|
1661 | + * Get the active event logger |
|
1662 | + * |
|
1663 | + * The returned logger only logs data when debug mode is enabled |
|
1664 | + * |
|
1665 | + * @return \OCP\Diagnostics\IEventLogger |
|
1666 | + */ |
|
1667 | + public function getEventLogger() { |
|
1668 | + return $this->query('EventLogger'); |
|
1669 | + } |
|
1670 | + |
|
1671 | + /** |
|
1672 | + * Get the active query logger |
|
1673 | + * |
|
1674 | + * The returned logger only logs data when debug mode is enabled |
|
1675 | + * |
|
1676 | + * @return \OCP\Diagnostics\IQueryLogger |
|
1677 | + */ |
|
1678 | + public function getQueryLogger() { |
|
1679 | + return $this->query('QueryLogger'); |
|
1680 | + } |
|
1681 | + |
|
1682 | + /** |
|
1683 | + * Get the manager for temporary files and folders |
|
1684 | + * |
|
1685 | + * @return \OCP\ITempManager |
|
1686 | + */ |
|
1687 | + public function getTempManager() { |
|
1688 | + return $this->query('TempManager'); |
|
1689 | + } |
|
1690 | + |
|
1691 | + /** |
|
1692 | + * Get the app manager |
|
1693 | + * |
|
1694 | + * @return \OCP\App\IAppManager |
|
1695 | + */ |
|
1696 | + public function getAppManager() { |
|
1697 | + return $this->query('AppManager'); |
|
1698 | + } |
|
1699 | + |
|
1700 | + /** |
|
1701 | + * Creates a new mailer |
|
1702 | + * |
|
1703 | + * @return \OCP\Mail\IMailer |
|
1704 | + */ |
|
1705 | + public function getMailer() { |
|
1706 | + return $this->query('Mailer'); |
|
1707 | + } |
|
1708 | + |
|
1709 | + /** |
|
1710 | + * Get the webroot |
|
1711 | + * |
|
1712 | + * @return string |
|
1713 | + */ |
|
1714 | + public function getWebRoot() { |
|
1715 | + return $this->webRoot; |
|
1716 | + } |
|
1717 | + |
|
1718 | + /** |
|
1719 | + * @return \OC\OCSClient |
|
1720 | + */ |
|
1721 | + public function getOcsClient() { |
|
1722 | + return $this->query('OcsClient'); |
|
1723 | + } |
|
1724 | + |
|
1725 | + /** |
|
1726 | + * @return \OCP\IDateTimeZone |
|
1727 | + */ |
|
1728 | + public function getDateTimeZone() { |
|
1729 | + return $this->query('DateTimeZone'); |
|
1730 | + } |
|
1731 | + |
|
1732 | + /** |
|
1733 | + * @return \OCP\IDateTimeFormatter |
|
1734 | + */ |
|
1735 | + public function getDateTimeFormatter() { |
|
1736 | + return $this->query('DateTimeFormatter'); |
|
1737 | + } |
|
1738 | + |
|
1739 | + /** |
|
1740 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
1741 | + */ |
|
1742 | + public function getMountProviderCollection() { |
|
1743 | + return $this->query('MountConfigManager'); |
|
1744 | + } |
|
1745 | + |
|
1746 | + /** |
|
1747 | + * Get the IniWrapper |
|
1748 | + * |
|
1749 | + * @return IniGetWrapper |
|
1750 | + */ |
|
1751 | + public function getIniWrapper() { |
|
1752 | + return $this->query('IniWrapper'); |
|
1753 | + } |
|
1754 | + |
|
1755 | + /** |
|
1756 | + * @return \OCP\Command\IBus |
|
1757 | + */ |
|
1758 | + public function getCommandBus() { |
|
1759 | + return $this->query('AsyncCommandBus'); |
|
1760 | + } |
|
1761 | + |
|
1762 | + /** |
|
1763 | + * Get the trusted domain helper |
|
1764 | + * |
|
1765 | + * @return TrustedDomainHelper |
|
1766 | + */ |
|
1767 | + public function getTrustedDomainHelper() { |
|
1768 | + return $this->query('TrustedDomainHelper'); |
|
1769 | + } |
|
1770 | + |
|
1771 | + /** |
|
1772 | + * Get the locking provider |
|
1773 | + * |
|
1774 | + * @return \OCP\Lock\ILockingProvider |
|
1775 | + * @since 8.1.0 |
|
1776 | + */ |
|
1777 | + public function getLockingProvider() { |
|
1778 | + return $this->query('LockingProvider'); |
|
1779 | + } |
|
1780 | + |
|
1781 | + /** |
|
1782 | + * @return \OCP\Files\Mount\IMountManager |
|
1783 | + **/ |
|
1784 | + function getMountManager() { |
|
1785 | + return $this->query('MountManager'); |
|
1786 | + } |
|
1787 | + |
|
1788 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
1789 | + function getUserMountCache() { |
|
1790 | + return $this->query('UserMountCache'); |
|
1791 | + } |
|
1792 | + |
|
1793 | + /** |
|
1794 | + * Get the MimeTypeDetector |
|
1795 | + * |
|
1796 | + * @return \OCP\Files\IMimeTypeDetector |
|
1797 | + */ |
|
1798 | + public function getMimeTypeDetector() { |
|
1799 | + return $this->query('MimeTypeDetector'); |
|
1800 | + } |
|
1801 | + |
|
1802 | + /** |
|
1803 | + * Get the MimeTypeLoader |
|
1804 | + * |
|
1805 | + * @return \OCP\Files\IMimeTypeLoader |
|
1806 | + */ |
|
1807 | + public function getMimeTypeLoader() { |
|
1808 | + return $this->query('MimeTypeLoader'); |
|
1809 | + } |
|
1810 | + |
|
1811 | + /** |
|
1812 | + * Get the manager of all the capabilities |
|
1813 | + * |
|
1814 | + * @return \OC\CapabilitiesManager |
|
1815 | + */ |
|
1816 | + public function getCapabilitiesManager() { |
|
1817 | + return $this->query('CapabilitiesManager'); |
|
1818 | + } |
|
1819 | + |
|
1820 | + /** |
|
1821 | + * Get the EventDispatcher |
|
1822 | + * |
|
1823 | + * @return EventDispatcherInterface |
|
1824 | + * @since 8.2.0 |
|
1825 | + */ |
|
1826 | + public function getEventDispatcher() { |
|
1827 | + return $this->query('EventDispatcher'); |
|
1828 | + } |
|
1829 | + |
|
1830 | + /** |
|
1831 | + * Get the Notification Manager |
|
1832 | + * |
|
1833 | + * @return \OCP\Notification\IManager |
|
1834 | + * @since 8.2.0 |
|
1835 | + */ |
|
1836 | + public function getNotificationManager() { |
|
1837 | + return $this->query('NotificationManager'); |
|
1838 | + } |
|
1839 | + |
|
1840 | + /** |
|
1841 | + * @return \OCP\Comments\ICommentsManager |
|
1842 | + */ |
|
1843 | + public function getCommentsManager() { |
|
1844 | + return $this->query('CommentsManager'); |
|
1845 | + } |
|
1846 | + |
|
1847 | + /** |
|
1848 | + * @return \OCA\Theming\ThemingDefaults |
|
1849 | + */ |
|
1850 | + public function getThemingDefaults() { |
|
1851 | + return $this->query('ThemingDefaults'); |
|
1852 | + } |
|
1853 | + |
|
1854 | + /** |
|
1855 | + * @return \OC\IntegrityCheck\Checker |
|
1856 | + */ |
|
1857 | + public function getIntegrityCodeChecker() { |
|
1858 | + return $this->query('IntegrityCodeChecker'); |
|
1859 | + } |
|
1860 | + |
|
1861 | + /** |
|
1862 | + * @return \OC\Session\CryptoWrapper |
|
1863 | + */ |
|
1864 | + public function getSessionCryptoWrapper() { |
|
1865 | + return $this->query('CryptoWrapper'); |
|
1866 | + } |
|
1867 | + |
|
1868 | + /** |
|
1869 | + * @return CsrfTokenManager |
|
1870 | + */ |
|
1871 | + public function getCsrfTokenManager() { |
|
1872 | + return $this->query('CsrfTokenManager'); |
|
1873 | + } |
|
1874 | + |
|
1875 | + /** |
|
1876 | + * @return Throttler |
|
1877 | + */ |
|
1878 | + public function getBruteForceThrottler() { |
|
1879 | + return $this->query('Throttler'); |
|
1880 | + } |
|
1881 | + |
|
1882 | + /** |
|
1883 | + * @return IContentSecurityPolicyManager |
|
1884 | + */ |
|
1885 | + public function getContentSecurityPolicyManager() { |
|
1886 | + return $this->query('ContentSecurityPolicyManager'); |
|
1887 | + } |
|
1888 | + |
|
1889 | + /** |
|
1890 | + * @return ContentSecurityPolicyNonceManager |
|
1891 | + */ |
|
1892 | + public function getContentSecurityPolicyNonceManager() { |
|
1893 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
1894 | + } |
|
1895 | + |
|
1896 | + /** |
|
1897 | + * Not a public API as of 8.2, wait for 9.0 |
|
1898 | + * |
|
1899 | + * @return \OCA\Files_External\Service\BackendService |
|
1900 | + */ |
|
1901 | + public function getStoragesBackendService() { |
|
1902 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1903 | + } |
|
1904 | + |
|
1905 | + /** |
|
1906 | + * Not a public API as of 8.2, wait for 9.0 |
|
1907 | + * |
|
1908 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1909 | + */ |
|
1910 | + public function getGlobalStoragesService() { |
|
1911 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1912 | + } |
|
1913 | + |
|
1914 | + /** |
|
1915 | + * Not a public API as of 8.2, wait for 9.0 |
|
1916 | + * |
|
1917 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1918 | + */ |
|
1919 | + public function getUserGlobalStoragesService() { |
|
1920 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1921 | + } |
|
1922 | + |
|
1923 | + /** |
|
1924 | + * Not a public API as of 8.2, wait for 9.0 |
|
1925 | + * |
|
1926 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
1927 | + */ |
|
1928 | + public function getUserStoragesService() { |
|
1929 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1930 | + } |
|
1931 | + |
|
1932 | + /** |
|
1933 | + * @return \OCP\Share\IManager |
|
1934 | + */ |
|
1935 | + public function getShareManager() { |
|
1936 | + return $this->query('ShareManager'); |
|
1937 | + } |
|
1938 | + |
|
1939 | + /** |
|
1940 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
1941 | + */ |
|
1942 | + public function getCollaboratorSearch() { |
|
1943 | + return $this->query('CollaboratorSearch'); |
|
1944 | + } |
|
1945 | + |
|
1946 | + /** |
|
1947 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
1948 | + */ |
|
1949 | + public function getAutoCompleteManager(){ |
|
1950 | + return $this->query(IManager::class); |
|
1951 | + } |
|
1952 | + |
|
1953 | + /** |
|
1954 | + * Returns the LDAP Provider |
|
1955 | + * |
|
1956 | + * @return \OCP\LDAP\ILDAPProvider |
|
1957 | + */ |
|
1958 | + public function getLDAPProvider() { |
|
1959 | + return $this->query('LDAPProvider'); |
|
1960 | + } |
|
1961 | + |
|
1962 | + /** |
|
1963 | + * @return \OCP\Settings\IManager |
|
1964 | + */ |
|
1965 | + public function getSettingsManager() { |
|
1966 | + return $this->query('SettingsManager'); |
|
1967 | + } |
|
1968 | + |
|
1969 | + /** |
|
1970 | + * @return \OCP\Files\IAppData |
|
1971 | + */ |
|
1972 | + public function getAppDataDir($app) { |
|
1973 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
1974 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1975 | + return $factory->get($app); |
|
1976 | + } |
|
1977 | + |
|
1978 | + /** |
|
1979 | + * @return \OCP\Lockdown\ILockdownManager |
|
1980 | + */ |
|
1981 | + public function getLockdownManager() { |
|
1982 | + return $this->query('LockdownManager'); |
|
1983 | + } |
|
1984 | + |
|
1985 | + /** |
|
1986 | + * @return \OCP\Federation\ICloudIdManager |
|
1987 | + */ |
|
1988 | + public function getCloudIdManager() { |
|
1989 | + return $this->query(ICloudIdManager::class); |
|
1990 | + } |
|
1991 | + |
|
1992 | + /** |
|
1993 | + * @return \OCP\GlobalScale\IConfig |
|
1994 | + */ |
|
1995 | + public function getGlobalScaleConfig() { |
|
1996 | + return $this->query(IConfig::class); |
|
1997 | + } |
|
1998 | + |
|
1999 | + /** |
|
2000 | + * @return \OCP\Federation\ICloudFederationProviderManager |
|
2001 | + */ |
|
2002 | + public function getCloudFederationProviderManager() { |
|
2003 | + return $this->query(ICloudFederationProviderManager::class); |
|
2004 | + } |
|
2005 | + |
|
2006 | + /** |
|
2007 | + * @return \OCP\Remote\Api\IApiFactory |
|
2008 | + */ |
|
2009 | + public function getRemoteApiFactory() { |
|
2010 | + return $this->query(IApiFactory::class); |
|
2011 | + } |
|
2012 | + |
|
2013 | + /** |
|
2014 | + * @return \OCP\Federation\ICloudFederationFactory |
|
2015 | + */ |
|
2016 | + public function getCloudFederationFactory() { |
|
2017 | + return $this->query(ICloudFederationFactory::class); |
|
2018 | + } |
|
2019 | + |
|
2020 | + /** |
|
2021 | + * @return \OCP\Remote\IInstanceFactory |
|
2022 | + */ |
|
2023 | + public function getRemoteInstanceFactory() { |
|
2024 | + return $this->query(IInstanceFactory::class); |
|
2025 | + } |
|
2026 | 2026 | } |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | // To find out if we are running from CLI or not |
173 | 173 | $this->registerParameter('isCLI', \OC::$CLI); |
174 | 174 | |
175 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
175 | + $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
176 | 176 | return $c; |
177 | 177 | }); |
178 | 178 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
186 | 186 | |
187 | 187 | |
188 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
188 | + $this->registerService(\OCP\IPreview::class, function(Server $c) { |
|
189 | 189 | return new PreviewManager( |
190 | 190 | $c->getConfig(), |
191 | 191 | $c->getRootFolder(), |
@@ -196,13 +196,13 @@ discard block |
||
196 | 196 | }); |
197 | 197 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
198 | 198 | |
199 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
199 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
200 | 200 | return new \OC\Preview\Watcher( |
201 | 201 | $c->getAppDataDir('preview') |
202 | 202 | ); |
203 | 203 | }); |
204 | 204 | |
205 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
205 | + $this->registerService('EncryptionManager', function(Server $c) { |
|
206 | 206 | $view = new View(); |
207 | 207 | $util = new Encryption\Util( |
208 | 208 | $view, |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | ); |
221 | 221 | }); |
222 | 222 | |
223 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
223 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
224 | 224 | $util = new Encryption\Util( |
225 | 225 | new View(), |
226 | 226 | $c->getUserManager(), |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | ); |
235 | 235 | }); |
236 | 236 | |
237 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
237 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
238 | 238 | $view = new View(); |
239 | 239 | $util = new Encryption\Util( |
240 | 240 | $view, |
@@ -245,30 +245,30 @@ discard block |
||
245 | 245 | |
246 | 246 | return new Encryption\Keys\Storage($view, $util); |
247 | 247 | }); |
248 | - $this->registerService('TagMapper', function (Server $c) { |
|
248 | + $this->registerService('TagMapper', function(Server $c) { |
|
249 | 249 | return new TagMapper($c->getDatabaseConnection()); |
250 | 250 | }); |
251 | 251 | |
252 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
252 | + $this->registerService(\OCP\ITagManager::class, function(Server $c) { |
|
253 | 253 | $tagMapper = $c->query('TagMapper'); |
254 | 254 | return new TagManager($tagMapper, $c->getUserSession()); |
255 | 255 | }); |
256 | 256 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
257 | 257 | |
258 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
258 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
259 | 259 | $config = $c->getConfig(); |
260 | 260 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
261 | 261 | return new $factoryClass($this); |
262 | 262 | }); |
263 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
263 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) { |
|
264 | 264 | return $c->query('SystemTagManagerFactory')->getManager(); |
265 | 265 | }); |
266 | 266 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
267 | 267 | |
268 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
268 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) { |
|
269 | 269 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
270 | 270 | }); |
271 | - $this->registerService('RootFolder', function (Server $c) { |
|
271 | + $this->registerService('RootFolder', function(Server $c) { |
|
272 | 272 | $manager = \OC\Files\Filesystem::getMountManager(null); |
273 | 273 | $view = new View(); |
274 | 274 | $root = new Root( |
@@ -289,38 +289,38 @@ discard block |
||
289 | 289 | }); |
290 | 290 | $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
291 | 291 | |
292 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
293 | - return new LazyRoot(function () use ($c) { |
|
292 | + $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
293 | + return new LazyRoot(function() use ($c) { |
|
294 | 294 | return $c->query('RootFolder'); |
295 | 295 | }); |
296 | 296 | }); |
297 | 297 | $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
298 | 298 | |
299 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
299 | + $this->registerService(\OC\User\Manager::class, function(Server $c) { |
|
300 | 300 | $config = $c->getConfig(); |
301 | 301 | return new \OC\User\Manager($config); |
302 | 302 | }); |
303 | 303 | $this->registerAlias('UserManager', \OC\User\Manager::class); |
304 | 304 | $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
305 | 305 | |
306 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
306 | + $this->registerService(\OCP\IGroupManager::class, function(Server $c) { |
|
307 | 307 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
308 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
308 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
309 | 309 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
310 | 310 | }); |
311 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
311 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) { |
|
312 | 312 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
313 | 313 | }); |
314 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
314 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
315 | 315 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
316 | 316 | }); |
317 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
317 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
318 | 318 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
319 | 319 | }); |
320 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
320 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
321 | 321 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
322 | 322 | }); |
323 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
323 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
324 | 324 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
325 | 325 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
326 | 326 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | }); |
330 | 330 | $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
331 | 331 | |
332 | - $this->registerService(Store::class, function (Server $c) { |
|
332 | + $this->registerService(Store::class, function(Server $c) { |
|
333 | 333 | $session = $c->getSession(); |
334 | 334 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
335 | 335 | $tokenProvider = $c->query(IProvider::class); |
@@ -340,11 +340,11 @@ discard block |
||
340 | 340 | return new Store($session, $logger, $tokenProvider); |
341 | 341 | }); |
342 | 342 | $this->registerAlias(IStore::class, Store::class); |
343 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
343 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function(Server $c) { |
|
344 | 344 | $dbConnection = $c->getDatabaseConnection(); |
345 | 345 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
346 | 346 | }); |
347 | - $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
|
347 | + $this->registerService(Authentication\Token\DefaultTokenProvider::class, function(Server $c) { |
|
348 | 348 | $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
349 | 349 | $crypto = $c->getCrypto(); |
350 | 350 | $config = $c->getConfig(); |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | }); |
355 | 355 | $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
356 | 356 | |
357 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
357 | + $this->registerService(\OCP\IUserSession::class, function(Server $c) { |
|
358 | 358 | $manager = $c->getUserManager(); |
359 | 359 | $session = new \OC\Session\Memory(''); |
360 | 360 | $timeFactory = new TimeFactory(); |
@@ -378,45 +378,45 @@ discard block |
||
378 | 378 | $c->getLockdownManager(), |
379 | 379 | $c->getLogger() |
380 | 380 | ); |
381 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
381 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
382 | 382 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
383 | 383 | }); |
384 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
384 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
385 | 385 | /** @var $user \OC\User\User */ |
386 | 386 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
387 | 387 | }); |
388 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
388 | + $userSession->listen('\OC\User', 'preDelete', function($user) use ($dispatcher) { |
|
389 | 389 | /** @var $user \OC\User\User */ |
390 | 390 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
391 | 391 | $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
392 | 392 | }); |
393 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
393 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
394 | 394 | /** @var $user \OC\User\User */ |
395 | 395 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
396 | 396 | }); |
397 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
397 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
398 | 398 | /** @var $user \OC\User\User */ |
399 | 399 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
400 | 400 | }); |
401 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
401 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
402 | 402 | /** @var $user \OC\User\User */ |
403 | 403 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
404 | 404 | }); |
405 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
405 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
406 | 406 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
407 | 407 | }); |
408 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
408 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password) { |
|
409 | 409 | /** @var $user \OC\User\User */ |
410 | 410 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
411 | 411 | }); |
412 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
412 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
413 | 413 | /** @var $user \OC\User\User */ |
414 | 414 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
415 | 415 | }); |
416 | - $userSession->listen('\OC\User', 'logout', function () { |
|
416 | + $userSession->listen('\OC\User', 'logout', function() { |
|
417 | 417 | \OC_Hook::emit('OC_User', 'logout', array()); |
418 | 418 | }); |
419 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
419 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
420 | 420 | /** @var $user \OC\User\User */ |
421 | 421 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
422 | 422 | $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | }); |
426 | 426 | $this->registerAlias('UserSession', \OCP\IUserSession::class); |
427 | 427 | |
428 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
428 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) { |
|
429 | 429 | return new \OC\Authentication\TwoFactorAuth\Manager( |
430 | 430 | $c->getAppManager(), |
431 | 431 | $c->getSession(), |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
442 | 442 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
443 | 443 | |
444 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
444 | + $this->registerService(\OC\AllConfig::class, function(Server $c) { |
|
445 | 445 | return new \OC\AllConfig( |
446 | 446 | $c->getSystemConfig() |
447 | 447 | ); |
@@ -449,17 +449,17 @@ discard block |
||
449 | 449 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
450 | 450 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
451 | 451 | |
452 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
452 | + $this->registerService('SystemConfig', function($c) use ($config) { |
|
453 | 453 | return new \OC\SystemConfig($config); |
454 | 454 | }); |
455 | 455 | |
456 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
456 | + $this->registerService(\OC\AppConfig::class, function(Server $c) { |
|
457 | 457 | return new \OC\AppConfig($c->getDatabaseConnection()); |
458 | 458 | }); |
459 | 459 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
460 | 460 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
461 | 461 | |
462 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
462 | + $this->registerService(\OCP\L10N\IFactory::class, function(Server $c) { |
|
463 | 463 | return new \OC\L10N\Factory( |
464 | 464 | $c->getConfig(), |
465 | 465 | $c->getRequest(), |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | }); |
470 | 470 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
471 | 471 | |
472 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
472 | + $this->registerService(\OCP\IURLGenerator::class, function(Server $c) { |
|
473 | 473 | $config = $c->getConfig(); |
474 | 474 | $cacheFactory = $c->getMemCacheFactory(); |
475 | 475 | $request = $c->getRequest(); |
@@ -484,12 +484,12 @@ discard block |
||
484 | 484 | $this->registerAlias('AppFetcher', AppFetcher::class); |
485 | 485 | $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
486 | 486 | |
487 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
487 | + $this->registerService(\OCP\ICache::class, function($c) { |
|
488 | 488 | return new Cache\File(); |
489 | 489 | }); |
490 | 490 | $this->registerAlias('UserCache', \OCP\ICache::class); |
491 | 491 | |
492 | - $this->registerService(Factory::class, function (Server $c) { |
|
492 | + $this->registerService(Factory::class, function(Server $c) { |
|
493 | 493 | |
494 | 494 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
495 | 495 | ArrayCache::class, |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | $version = implode(',', $v); |
507 | 507 | $instanceId = \OC_Util::getInstanceId(); |
508 | 508 | $path = \OC::$SERVERROOT; |
509 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
509 | + $prefix = md5($instanceId.'-'.$version.'-'.$path); |
|
510 | 510 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
511 | 511 | $config->getSystemValue('memcache.local', null), |
512 | 512 | $config->getSystemValue('memcache.distributed', null), |
@@ -519,12 +519,12 @@ discard block |
||
519 | 519 | $this->registerAlias('MemCacheFactory', Factory::class); |
520 | 520 | $this->registerAlias(ICacheFactory::class, Factory::class); |
521 | 521 | |
522 | - $this->registerService('RedisFactory', function (Server $c) { |
|
522 | + $this->registerService('RedisFactory', function(Server $c) { |
|
523 | 523 | $systemConfig = $c->getSystemConfig(); |
524 | 524 | return new RedisFactory($systemConfig); |
525 | 525 | }); |
526 | 526 | |
527 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
527 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
528 | 528 | return new \OC\Activity\Manager( |
529 | 529 | $c->getRequest(), |
530 | 530 | $c->getUserSession(), |
@@ -534,14 +534,14 @@ discard block |
||
534 | 534 | }); |
535 | 535 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
536 | 536 | |
537 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
537 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
538 | 538 | return new \OC\Activity\EventMerger( |
539 | 539 | $c->getL10N('lib') |
540 | 540 | ); |
541 | 541 | }); |
542 | 542 | $this->registerAlias(IValidator::class, Validator::class); |
543 | 543 | |
544 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
544 | + $this->registerService(\OCP\IAvatarManager::class, function(Server $c) { |
|
545 | 545 | return new AvatarManager( |
546 | 546 | $c->query(\OC\User\Manager::class), |
547 | 547 | $c->getAppDataDir('avatar'), |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | |
555 | 555 | $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
556 | 556 | |
557 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
557 | + $this->registerService(\OCP\ILogger::class, function(Server $c) { |
|
558 | 558 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
559 | 559 | $factory = new LogFactory($c, $this->getSystemConfig()); |
560 | 560 | $logger = $factory->get($logType); |
@@ -564,11 +564,11 @@ discard block |
||
564 | 564 | }); |
565 | 565 | $this->registerAlias('Logger', \OCP\ILogger::class); |
566 | 566 | |
567 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
567 | + $this->registerService(ILogFactory::class, function(Server $c) { |
|
568 | 568 | return new LogFactory($c, $this->getSystemConfig()); |
569 | 569 | }); |
570 | 570 | |
571 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
571 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) { |
|
572 | 572 | $config = $c->getConfig(); |
573 | 573 | return new \OC\BackgroundJob\JobList( |
574 | 574 | $c->getDatabaseConnection(), |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | }); |
579 | 579 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
580 | 580 | |
581 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
581 | + $this->registerService(\OCP\Route\IRouter::class, function(Server $c) { |
|
582 | 582 | $cacheFactory = $c->getMemCacheFactory(); |
583 | 583 | $logger = $c->getLogger(); |
584 | 584 | if ($cacheFactory->isLocalCacheAvailable()) { |
@@ -590,12 +590,12 @@ discard block |
||
590 | 590 | }); |
591 | 591 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
592 | 592 | |
593 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
593 | + $this->registerService(\OCP\ISearch::class, function($c) { |
|
594 | 594 | return new Search(); |
595 | 595 | }); |
596 | 596 | $this->registerAlias('Search', \OCP\ISearch::class); |
597 | 597 | |
598 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
598 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function(Server $c) { |
|
599 | 599 | return new \OC\Security\RateLimiting\Limiter( |
600 | 600 | $this->getUserSession(), |
601 | 601 | $this->getRequest(), |
@@ -603,34 +603,34 @@ discard block |
||
603 | 603 | $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
604 | 604 | ); |
605 | 605 | }); |
606 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
606 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
607 | 607 | return new \OC\Security\RateLimiting\Backend\MemoryCache( |
608 | 608 | $this->getMemCacheFactory(), |
609 | 609 | new \OC\AppFramework\Utility\TimeFactory() |
610 | 610 | ); |
611 | 611 | }); |
612 | 612 | |
613 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
613 | + $this->registerService(\OCP\Security\ISecureRandom::class, function($c) { |
|
614 | 614 | return new SecureRandom(); |
615 | 615 | }); |
616 | 616 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
617 | 617 | |
618 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
618 | + $this->registerService(\OCP\Security\ICrypto::class, function(Server $c) { |
|
619 | 619 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
620 | 620 | }); |
621 | 621 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
622 | 622 | |
623 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
623 | + $this->registerService(\OCP\Security\IHasher::class, function(Server $c) { |
|
624 | 624 | return new Hasher($c->getConfig()); |
625 | 625 | }); |
626 | 626 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
627 | 627 | |
628 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
628 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) { |
|
629 | 629 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
630 | 630 | }); |
631 | 631 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
632 | 632 | |
633 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
633 | + $this->registerService(IDBConnection::class, function(Server $c) { |
|
634 | 634 | $systemConfig = $c->getSystemConfig(); |
635 | 635 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
636 | 636 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -645,7 +645,7 @@ discard block |
||
645 | 645 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
646 | 646 | |
647 | 647 | |
648 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
648 | + $this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) { |
|
649 | 649 | $user = \OC_User::getUser(); |
650 | 650 | $uid = $user ? $user : null; |
651 | 651 | return new ClientService( |
@@ -660,7 +660,7 @@ discard block |
||
660 | 660 | ); |
661 | 661 | }); |
662 | 662 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
663 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
663 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) { |
|
664 | 664 | $eventLogger = new EventLogger(); |
665 | 665 | if ($c->getSystemConfig()->getValue('debug', false)) { |
666 | 666 | // In debug mode, module is being activated by default |
@@ -670,7 +670,7 @@ discard block |
||
670 | 670 | }); |
671 | 671 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
672 | 672 | |
673 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
673 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) { |
|
674 | 674 | $queryLogger = new QueryLogger(); |
675 | 675 | if ($c->getSystemConfig()->getValue('debug', false)) { |
676 | 676 | // In debug mode, module is being activated by default |
@@ -680,7 +680,7 @@ discard block |
||
680 | 680 | }); |
681 | 681 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
682 | 682 | |
683 | - $this->registerService(TempManager::class, function (Server $c) { |
|
683 | + $this->registerService(TempManager::class, function(Server $c) { |
|
684 | 684 | return new TempManager( |
685 | 685 | $c->getLogger(), |
686 | 686 | $c->getConfig() |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | $this->registerAlias('TempManager', TempManager::class); |
690 | 690 | $this->registerAlias(ITempManager::class, TempManager::class); |
691 | 691 | |
692 | - $this->registerService(AppManager::class, function (Server $c) { |
|
692 | + $this->registerService(AppManager::class, function(Server $c) { |
|
693 | 693 | return new \OC\App\AppManager( |
694 | 694 | $c->getUserSession(), |
695 | 695 | $c->query(\OC\AppConfig::class), |
@@ -701,7 +701,7 @@ discard block |
||
701 | 701 | $this->registerAlias('AppManager', AppManager::class); |
702 | 702 | $this->registerAlias(IAppManager::class, AppManager::class); |
703 | 703 | |
704 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
704 | + $this->registerService(\OCP\IDateTimeZone::class, function(Server $c) { |
|
705 | 705 | return new DateTimeZone( |
706 | 706 | $c->getConfig(), |
707 | 707 | $c->getSession() |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | }); |
710 | 710 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
711 | 711 | |
712 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
712 | + $this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) { |
|
713 | 713 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
714 | 714 | |
715 | 715 | return new DateTimeFormatter( |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | }); |
720 | 720 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
721 | 721 | |
722 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
722 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) { |
|
723 | 723 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
724 | 724 | $listener = new UserMountCacheListener($mountCache); |
725 | 725 | $listener->listen($c->getUserManager()); |
@@ -727,7 +727,7 @@ discard block |
||
727 | 727 | }); |
728 | 728 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
729 | 729 | |
730 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
730 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) { |
|
731 | 731 | $loader = \OC\Files\Filesystem::getLoader(); |
732 | 732 | $mountCache = $c->query('UserMountCache'); |
733 | 733 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
@@ -743,10 +743,10 @@ discard block |
||
743 | 743 | }); |
744 | 744 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
745 | 745 | |
746 | - $this->registerService('IniWrapper', function ($c) { |
|
746 | + $this->registerService('IniWrapper', function($c) { |
|
747 | 747 | return new IniGetWrapper(); |
748 | 748 | }); |
749 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
749 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
750 | 750 | $busClass = $c->getConfig()->getSystemValue('commandbus'); |
751 | 751 | if ($busClass) { |
752 | 752 | list($app, $class) = explode('::', $busClass, 2); |
@@ -761,10 +761,10 @@ discard block |
||
761 | 761 | return new CronBus($jobList); |
762 | 762 | } |
763 | 763 | }); |
764 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
764 | + $this->registerService('TrustedDomainHelper', function($c) { |
|
765 | 765 | return new TrustedDomainHelper($this->getConfig()); |
766 | 766 | }); |
767 | - $this->registerService('Throttler', function (Server $c) { |
|
767 | + $this->registerService('Throttler', function(Server $c) { |
|
768 | 768 | return new Throttler( |
769 | 769 | $c->getDatabaseConnection(), |
770 | 770 | new TimeFactory(), |
@@ -772,7 +772,7 @@ discard block |
||
772 | 772 | $c->getConfig() |
773 | 773 | ); |
774 | 774 | }); |
775 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
775 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
776 | 776 | // IConfig and IAppManager requires a working database. This code |
777 | 777 | // might however be called when ownCloud is not yet setup. |
778 | 778 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
@@ -793,7 +793,7 @@ discard block |
||
793 | 793 | $c->getTempManager() |
794 | 794 | ); |
795 | 795 | }); |
796 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
796 | + $this->registerService(\OCP\IRequest::class, function($c) { |
|
797 | 797 | if (isset($this['urlParams'])) { |
798 | 798 | $urlParams = $this['urlParams']; |
799 | 799 | } else { |
@@ -829,7 +829,7 @@ discard block |
||
829 | 829 | }); |
830 | 830 | $this->registerAlias('Request', \OCP\IRequest::class); |
831 | 831 | |
832 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
832 | + $this->registerService(\OCP\Mail\IMailer::class, function(Server $c) { |
|
833 | 833 | return new Mailer( |
834 | 834 | $c->getConfig(), |
835 | 835 | $c->getLogger(), |
@@ -840,7 +840,7 @@ discard block |
||
840 | 840 | }); |
841 | 841 | $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
842 | 842 | |
843 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
843 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
844 | 844 | $config = $c->getConfig(); |
845 | 845 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
846 | 846 | if (is_null($factoryClass)) { |
@@ -850,7 +850,7 @@ discard block |
||
850 | 850 | $factory = new $factoryClass($this); |
851 | 851 | return $factory->getLDAPProvider(); |
852 | 852 | }); |
853 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
853 | + $this->registerService(ILockingProvider::class, function(Server $c) { |
|
854 | 854 | $ini = $c->getIniWrapper(); |
855 | 855 | $config = $c->getConfig(); |
856 | 856 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -873,49 +873,49 @@ discard block |
||
873 | 873 | }); |
874 | 874 | $this->registerAlias('LockingProvider', ILockingProvider::class); |
875 | 875 | |
876 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
876 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function() { |
|
877 | 877 | return new \OC\Files\Mount\Manager(); |
878 | 878 | }); |
879 | 879 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
880 | 880 | |
881 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
881 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) { |
|
882 | 882 | return new \OC\Files\Type\Detection( |
883 | 883 | $c->getURLGenerator(), |
884 | 884 | \OC::$configDir, |
885 | - \OC::$SERVERROOT . '/resources/config/' |
|
885 | + \OC::$SERVERROOT.'/resources/config/' |
|
886 | 886 | ); |
887 | 887 | }); |
888 | 888 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
889 | 889 | |
890 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
890 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) { |
|
891 | 891 | return new \OC\Files\Type\Loader( |
892 | 892 | $c->getDatabaseConnection() |
893 | 893 | ); |
894 | 894 | }); |
895 | 895 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
896 | - $this->registerService(BundleFetcher::class, function () { |
|
896 | + $this->registerService(BundleFetcher::class, function() { |
|
897 | 897 | return new BundleFetcher($this->getL10N('lib')); |
898 | 898 | }); |
899 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
899 | + $this->registerService(\OCP\Notification\IManager::class, function(Server $c) { |
|
900 | 900 | return new Manager( |
901 | 901 | $c->query(IValidator::class) |
902 | 902 | ); |
903 | 903 | }); |
904 | 904 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
905 | 905 | |
906 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
906 | + $this->registerService(\OC\CapabilitiesManager::class, function(Server $c) { |
|
907 | 907 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
908 | - $manager->registerCapability(function () use ($c) { |
|
908 | + $manager->registerCapability(function() use ($c) { |
|
909 | 909 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
910 | 910 | }); |
911 | - $manager->registerCapability(function () use ($c) { |
|
911 | + $manager->registerCapability(function() use ($c) { |
|
912 | 912 | return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
913 | 913 | }); |
914 | 914 | return $manager; |
915 | 915 | }); |
916 | 916 | $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
917 | 917 | |
918 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
918 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
919 | 919 | $config = $c->getConfig(); |
920 | 920 | $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
921 | 921 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
@@ -925,7 +925,7 @@ discard block |
||
925 | 925 | $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
926 | 926 | $manager = $c->getUserManager(); |
927 | 927 | $user = $manager->get($id); |
928 | - if(is_null($user)) { |
|
928 | + if (is_null($user)) { |
|
929 | 929 | $l = $c->getL10N('core'); |
930 | 930 | $displayName = $l->t('Unknown user'); |
931 | 931 | } else { |
@@ -938,7 +938,7 @@ discard block |
||
938 | 938 | }); |
939 | 939 | $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
940 | 940 | |
941 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
941 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
942 | 942 | /* |
943 | 943 | * Dark magic for autoloader. |
944 | 944 | * If we do a class_exists it will try to load the class which will |
@@ -965,7 +965,7 @@ discard block |
||
965 | 965 | } |
966 | 966 | return new \OC_Defaults(); |
967 | 967 | }); |
968 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
968 | + $this->registerService(SCSSCacher::class, function(Server $c) { |
|
969 | 969 | /** @var Factory $cacheFactory */ |
970 | 970 | $cacheFactory = $c->query(Factory::class); |
971 | 971 | return new SCSSCacher( |
@@ -978,7 +978,7 @@ discard block |
||
978 | 978 | $this->getMemCacheFactory() |
979 | 979 | ); |
980 | 980 | }); |
981 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
981 | + $this->registerService(JSCombiner::class, function(Server $c) { |
|
982 | 982 | /** @var Factory $cacheFactory */ |
983 | 983 | $cacheFactory = $c->query(Factory::class); |
984 | 984 | return new JSCombiner( |
@@ -989,13 +989,13 @@ discard block |
||
989 | 989 | $c->getLogger() |
990 | 990 | ); |
991 | 991 | }); |
992 | - $this->registerService(EventDispatcher::class, function () { |
|
992 | + $this->registerService(EventDispatcher::class, function() { |
|
993 | 993 | return new EventDispatcher(); |
994 | 994 | }); |
995 | 995 | $this->registerAlias('EventDispatcher', EventDispatcher::class); |
996 | 996 | $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
997 | 997 | |
998 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
998 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
999 | 999 | // FIXME: Instantiiated here due to cyclic dependency |
1000 | 1000 | $request = new Request( |
1001 | 1001 | [ |
@@ -1020,7 +1020,7 @@ discard block |
||
1020 | 1020 | $request |
1021 | 1021 | ); |
1022 | 1022 | }); |
1023 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1023 | + $this->registerService('CsrfTokenManager', function(Server $c) { |
|
1024 | 1024 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
1025 | 1025 | |
1026 | 1026 | return new CsrfTokenManager( |
@@ -1028,22 +1028,22 @@ discard block |
||
1028 | 1028 | $c->query(SessionStorage::class) |
1029 | 1029 | ); |
1030 | 1030 | }); |
1031 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1031 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
1032 | 1032 | return new SessionStorage($c->getSession()); |
1033 | 1033 | }); |
1034 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1034 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) { |
|
1035 | 1035 | return new ContentSecurityPolicyManager(); |
1036 | 1036 | }); |
1037 | 1037 | $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
1038 | 1038 | |
1039 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1039 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
1040 | 1040 | return new ContentSecurityPolicyNonceManager( |
1041 | 1041 | $c->getCsrfTokenManager(), |
1042 | 1042 | $c->getRequest() |
1043 | 1043 | ); |
1044 | 1044 | }); |
1045 | 1045 | |
1046 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1046 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
1047 | 1047 | $config = $c->getConfig(); |
1048 | 1048 | $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
1049 | 1049 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -1086,7 +1086,7 @@ discard block |
||
1086 | 1086 | |
1087 | 1087 | $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
1088 | 1088 | |
1089 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1089 | + $this->registerService('SettingsManager', function(Server $c) { |
|
1090 | 1090 | $manager = new \OC\Settings\Manager( |
1091 | 1091 | $c->getLogger(), |
1092 | 1092 | $c->getDatabaseConnection(), |
@@ -1104,36 +1104,36 @@ discard block |
||
1104 | 1104 | ); |
1105 | 1105 | return $manager; |
1106 | 1106 | }); |
1107 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1107 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
1108 | 1108 | return new \OC\Files\AppData\Factory( |
1109 | 1109 | $c->getRootFolder(), |
1110 | 1110 | $c->getSystemConfig() |
1111 | 1111 | ); |
1112 | 1112 | }); |
1113 | 1113 | |
1114 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1115 | - return new LockdownManager(function () use ($c) { |
|
1114 | + $this->registerService('LockdownManager', function(Server $c) { |
|
1115 | + return new LockdownManager(function() use ($c) { |
|
1116 | 1116 | return $c->getSession(); |
1117 | 1117 | }); |
1118 | 1118 | }); |
1119 | 1119 | |
1120 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1120 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) { |
|
1121 | 1121 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
1122 | 1122 | }); |
1123 | 1123 | |
1124 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1124 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
1125 | 1125 | return new CloudIdManager(); |
1126 | 1126 | }); |
1127 | 1127 | |
1128 | - $this->registerService(IConfig::class, function (Server $c) { |
|
1128 | + $this->registerService(IConfig::class, function(Server $c) { |
|
1129 | 1129 | return new GlobalScale\Config($c->getConfig()); |
1130 | 1130 | }); |
1131 | 1131 | |
1132 | - $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
1132 | + $this->registerService(ICloudFederationProviderManager::class, function(Server $c) { |
|
1133 | 1133 | return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
1134 | 1134 | }); |
1135 | 1135 | |
1136 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1136 | + $this->registerService(ICloudFederationFactory::class, function(Server $c) { |
|
1137 | 1137 | return new CloudFederationFactory(); |
1138 | 1138 | }); |
1139 | 1139 | |
@@ -1143,18 +1143,18 @@ discard block |
||
1143 | 1143 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
1144 | 1144 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
1145 | 1145 | |
1146 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1146 | + $this->registerService(Defaults::class, function(Server $c) { |
|
1147 | 1147 | return new Defaults( |
1148 | 1148 | $c->getThemingDefaults() |
1149 | 1149 | ); |
1150 | 1150 | }); |
1151 | 1151 | $this->registerAlias('Defaults', \OCP\Defaults::class); |
1152 | 1152 | |
1153 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1153 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
1154 | 1154 | return $c->query(\OCP\IUserSession::class)->getSession(); |
1155 | 1155 | }); |
1156 | 1156 | |
1157 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1157 | + $this->registerService(IShareHelper::class, function(Server $c) { |
|
1158 | 1158 | return new ShareHelper( |
1159 | 1159 | $c->query(\OCP\Share\IManager::class) |
1160 | 1160 | ); |
@@ -1216,11 +1216,11 @@ discard block |
||
1216 | 1216 | // no avatar to remove |
1217 | 1217 | } catch (\Exception $e) { |
1218 | 1218 | // Ignore exceptions |
1219 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1219 | + $logger->info('Could not cleanup avatar of '.$user->getUID()); |
|
1220 | 1220 | } |
1221 | 1221 | }); |
1222 | 1222 | |
1223 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1223 | + $dispatcher->addListener('OCP\IUser::changeUser', function(GenericEvent $e) { |
|
1224 | 1224 | $manager = $this->getAvatarManager(); |
1225 | 1225 | /** @var IUser $user */ |
1226 | 1226 | $user = $e->getSubject(); |
@@ -1371,7 +1371,7 @@ discard block |
||
1371 | 1371 | * @deprecated since 9.2.0 use IAppData |
1372 | 1372 | */ |
1373 | 1373 | public function getAppFolder() { |
1374 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1374 | + $dir = '/'.\OC_App::getCurrentApp(); |
|
1375 | 1375 | $root = $this->getRootFolder(); |
1376 | 1376 | if (!$root->nodeExists($dir)) { |
1377 | 1377 | $folder = $root->newFolder($dir); |
@@ -1946,7 +1946,7 @@ discard block |
||
1946 | 1946 | /** |
1947 | 1947 | * @return \OCP\Collaboration\AutoComplete\IManager |
1948 | 1948 | */ |
1949 | - public function getAutoCompleteManager(){ |
|
1949 | + public function getAutoCompleteManager() { |
|
1950 | 1950 | return $this->query(IManager::class); |
1951 | 1951 | } |
1952 | 1952 |
@@ -31,7 +31,7 @@ |
||
31 | 31 | */ |
32 | 32 | public function __construct($action) { |
33 | 33 | $l = \OC::$server->getL10N('federation'); |
34 | - $message = 'Action "' . $action . '" not supported or implemented.'; |
|
34 | + $message = 'Action "'.$action.'" not supported or implemented.'; |
|
35 | 35 | $hint = $l->t('Action "%s" not supported or implemented.', [$action]); |
36 | 36 | parent::__construct($message, $hint); |
37 | 37 | } |
@@ -32,17 +32,17 @@ |
||
32 | 32 | */ |
33 | 33 | class ActionNotSupportedException extends HintException { |
34 | 34 | |
35 | - /** |
|
36 | - * ActionNotSupportedException constructor. |
|
37 | - * |
|
38 | - * @since 14.0.0 |
|
39 | - * |
|
40 | - */ |
|
41 | - public function __construct($action) { |
|
42 | - $l = \OC::$server->getL10N('federation'); |
|
43 | - $message = 'Action "' . $action . '" not supported or implemented.'; |
|
44 | - $hint = $l->t('Action "%s" not supported or implemented.', [$action]); |
|
45 | - parent::__construct($message, $hint); |
|
46 | - } |
|
35 | + /** |
|
36 | + * ActionNotSupportedException constructor. |
|
37 | + * |
|
38 | + * @since 14.0.0 |
|
39 | + * |
|
40 | + */ |
|
41 | + public function __construct($action) { |
|
42 | + $l = \OC::$server->getL10N('federation'); |
|
43 | + $message = 'Action "' . $action . '" not supported or implemented.'; |
|
44 | + $hint = $l->t('Action "%s" not supported or implemented.', [$action]); |
|
45 | + parent::__construct($message, $hint); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | } |
@@ -25,328 +25,328 @@ |
||
25 | 25 | |
26 | 26 | class CloudFederationShare implements ICloudFederationShare { |
27 | 27 | |
28 | - private $share = [ |
|
29 | - 'shareWith' => '', |
|
30 | - 'shareType' => '', |
|
31 | - 'name' => '', |
|
32 | - 'resourceType' => '', |
|
33 | - 'description' => '', |
|
34 | - 'providerId' => '', |
|
35 | - 'owner' => '', |
|
36 | - 'ownerDisplayName' => '', |
|
37 | - 'sharedBy' => '', |
|
38 | - 'sharedByDisplayName' => '', |
|
39 | - 'protocol' => [] |
|
40 | - ]; |
|
28 | + private $share = [ |
|
29 | + 'shareWith' => '', |
|
30 | + 'shareType' => '', |
|
31 | + 'name' => '', |
|
32 | + 'resourceType' => '', |
|
33 | + 'description' => '', |
|
34 | + 'providerId' => '', |
|
35 | + 'owner' => '', |
|
36 | + 'ownerDisplayName' => '', |
|
37 | + 'sharedBy' => '', |
|
38 | + 'sharedByDisplayName' => '', |
|
39 | + 'protocol' => [] |
|
40 | + ]; |
|
41 | 41 | |
42 | - /** |
|
43 | - * get a CloudFederationShare Object to prepare a share you want to send |
|
44 | - * |
|
45 | - * @param string $shareWith |
|
46 | - * @param string $name resource name (e.g. document.odt) |
|
47 | - * @param string $description share description (optional) |
|
48 | - * @param string $providerId resource UID on the provider side |
|
49 | - * @param string $owner provider specific UID of the user who owns the resource |
|
50 | - * @param string $ownerDisplayName display name of the user who shared the item |
|
51 | - * @param string $sharedBy provider specific UID of the user who shared the resource |
|
52 | - * @param string $sharedByDisplayName display name of the user who shared the resource |
|
53 | - * @param string $shareType ('group' or 'user' share) |
|
54 | - * @param string $resourceType ('file', 'calendar',...) |
|
55 | - * @param string $sharedSecret |
|
56 | - */ |
|
57 | - public function __construct($shareWith = '', |
|
58 | - $name = '', |
|
59 | - $description = '', |
|
60 | - $providerId = '', |
|
61 | - $owner = '', |
|
62 | - $ownerDisplayName = '', |
|
63 | - $sharedBy = '', |
|
64 | - $sharedByDisplayName = '', |
|
65 | - $shareType = '', |
|
66 | - $resourceType = '', |
|
67 | - $sharedSecret = '' |
|
68 | - ) { |
|
69 | - $this->setShareWith($shareWith); |
|
70 | - $this->setResourceName($name); |
|
71 | - $this->setDescription($description); |
|
72 | - $this->setProviderId($providerId); |
|
73 | - $this->setOwner($owner); |
|
74 | - $this->setOwnerDisplayName($ownerDisplayName); |
|
75 | - $this->setSharedBy($sharedBy); |
|
76 | - $this->setSharedByDisplayName($sharedByDisplayName); |
|
77 | - $this->setProtocol([ |
|
78 | - 'name' => 'webdav', |
|
79 | - 'options' => [ |
|
80 | - 'sharedSecret' => $sharedSecret, |
|
81 | - 'permissions' => '{http://open-collaboration-services.org/ns}share-permissions' |
|
82 | - ] |
|
83 | - ]); |
|
84 | - $this->setShareType($shareType); |
|
85 | - $this->setResourceType($resourceType); |
|
42 | + /** |
|
43 | + * get a CloudFederationShare Object to prepare a share you want to send |
|
44 | + * |
|
45 | + * @param string $shareWith |
|
46 | + * @param string $name resource name (e.g. document.odt) |
|
47 | + * @param string $description share description (optional) |
|
48 | + * @param string $providerId resource UID on the provider side |
|
49 | + * @param string $owner provider specific UID of the user who owns the resource |
|
50 | + * @param string $ownerDisplayName display name of the user who shared the item |
|
51 | + * @param string $sharedBy provider specific UID of the user who shared the resource |
|
52 | + * @param string $sharedByDisplayName display name of the user who shared the resource |
|
53 | + * @param string $shareType ('group' or 'user' share) |
|
54 | + * @param string $resourceType ('file', 'calendar',...) |
|
55 | + * @param string $sharedSecret |
|
56 | + */ |
|
57 | + public function __construct($shareWith = '', |
|
58 | + $name = '', |
|
59 | + $description = '', |
|
60 | + $providerId = '', |
|
61 | + $owner = '', |
|
62 | + $ownerDisplayName = '', |
|
63 | + $sharedBy = '', |
|
64 | + $sharedByDisplayName = '', |
|
65 | + $shareType = '', |
|
66 | + $resourceType = '', |
|
67 | + $sharedSecret = '' |
|
68 | + ) { |
|
69 | + $this->setShareWith($shareWith); |
|
70 | + $this->setResourceName($name); |
|
71 | + $this->setDescription($description); |
|
72 | + $this->setProviderId($providerId); |
|
73 | + $this->setOwner($owner); |
|
74 | + $this->setOwnerDisplayName($ownerDisplayName); |
|
75 | + $this->setSharedBy($sharedBy); |
|
76 | + $this->setSharedByDisplayName($sharedByDisplayName); |
|
77 | + $this->setProtocol([ |
|
78 | + 'name' => 'webdav', |
|
79 | + 'options' => [ |
|
80 | + 'sharedSecret' => $sharedSecret, |
|
81 | + 'permissions' => '{http://open-collaboration-services.org/ns}share-permissions' |
|
82 | + ] |
|
83 | + ]); |
|
84 | + $this->setShareType($shareType); |
|
85 | + $this->setResourceType($resourceType); |
|
86 | 86 | |
87 | - } |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * set uid of the recipient |
|
91 | - * |
|
92 | - * @param string $user |
|
93 | - * |
|
94 | - * @since 14.0.0 |
|
95 | - */ |
|
96 | - public function setShareWith($user) { |
|
97 | - $this->share['shareWith'] = $user; |
|
98 | - } |
|
89 | + /** |
|
90 | + * set uid of the recipient |
|
91 | + * |
|
92 | + * @param string $user |
|
93 | + * |
|
94 | + * @since 14.0.0 |
|
95 | + */ |
|
96 | + public function setShareWith($user) { |
|
97 | + $this->share['shareWith'] = $user; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * set resource name (e.g. document.odt) |
|
102 | - * |
|
103 | - * @param string $name |
|
104 | - * |
|
105 | - * @since 14.0.0 |
|
106 | - */ |
|
107 | - public function setResourceName($name) { |
|
108 | - $this->share['name'] = $name; |
|
109 | - } |
|
100 | + /** |
|
101 | + * set resource name (e.g. document.odt) |
|
102 | + * |
|
103 | + * @param string $name |
|
104 | + * |
|
105 | + * @since 14.0.0 |
|
106 | + */ |
|
107 | + public function setResourceName($name) { |
|
108 | + $this->share['name'] = $name; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * set resource type (e.g. file, calendar, contact,...) |
|
113 | - * |
|
114 | - * @param string $resourceType |
|
115 | - * |
|
116 | - * @since 14.0.0 |
|
117 | - */ |
|
118 | - public function setResourceType($resourceType) { |
|
119 | - $this->share['resourceType'] = $resourceType; |
|
120 | - } |
|
111 | + /** |
|
112 | + * set resource type (e.g. file, calendar, contact,...) |
|
113 | + * |
|
114 | + * @param string $resourceType |
|
115 | + * |
|
116 | + * @since 14.0.0 |
|
117 | + */ |
|
118 | + public function setResourceType($resourceType) { |
|
119 | + $this->share['resourceType'] = $resourceType; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * set resource description (optional) |
|
124 | - * |
|
125 | - * @param string $description |
|
126 | - * |
|
127 | - * @since 14.0.0 |
|
128 | - */ |
|
129 | - public function setDescription($description) { |
|
130 | - $this->share['description'] = $description; |
|
131 | - } |
|
122 | + /** |
|
123 | + * set resource description (optional) |
|
124 | + * |
|
125 | + * @param string $description |
|
126 | + * |
|
127 | + * @since 14.0.0 |
|
128 | + */ |
|
129 | + public function setDescription($description) { |
|
130 | + $this->share['description'] = $description; |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * set provider ID (e.g. file ID) |
|
135 | - * |
|
136 | - * @param string $providerId |
|
137 | - * |
|
138 | - * @since 14.0.0 |
|
139 | - */ |
|
140 | - public function setProviderId($providerId) { |
|
141 | - $this->share['providerId'] = $providerId; |
|
142 | - } |
|
133 | + /** |
|
134 | + * set provider ID (e.g. file ID) |
|
135 | + * |
|
136 | + * @param string $providerId |
|
137 | + * |
|
138 | + * @since 14.0.0 |
|
139 | + */ |
|
140 | + public function setProviderId($providerId) { |
|
141 | + $this->share['providerId'] = $providerId; |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * set owner UID |
|
146 | - * |
|
147 | - * @param string $owner |
|
148 | - * |
|
149 | - * @since 14.0.0 |
|
150 | - */ |
|
151 | - public function setOwner($owner) { |
|
152 | - $this->share['owner'] = $owner; |
|
153 | - } |
|
144 | + /** |
|
145 | + * set owner UID |
|
146 | + * |
|
147 | + * @param string $owner |
|
148 | + * |
|
149 | + * @since 14.0.0 |
|
150 | + */ |
|
151 | + public function setOwner($owner) { |
|
152 | + $this->share['owner'] = $owner; |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * set owner display name |
|
157 | - * |
|
158 | - * @param string $ownerDisplayName |
|
159 | - * |
|
160 | - * @since 14.0.0 |
|
161 | - */ |
|
162 | - public function setOwnerDisplayName($ownerDisplayName) { |
|
163 | - $this->share['ownerDisplayName'] = $ownerDisplayName; |
|
164 | - } |
|
155 | + /** |
|
156 | + * set owner display name |
|
157 | + * |
|
158 | + * @param string $ownerDisplayName |
|
159 | + * |
|
160 | + * @since 14.0.0 |
|
161 | + */ |
|
162 | + public function setOwnerDisplayName($ownerDisplayName) { |
|
163 | + $this->share['ownerDisplayName'] = $ownerDisplayName; |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
167 | - * set UID of the user who sends the share |
|
168 | - * |
|
169 | - * @param string $sharedBy |
|
170 | - * |
|
171 | - * @since 14.0.0 |
|
172 | - */ |
|
173 | - public function setSharedBy($sharedBy) { |
|
174 | - $this->share['sharedBy'] = $sharedBy; |
|
175 | - } |
|
166 | + /** |
|
167 | + * set UID of the user who sends the share |
|
168 | + * |
|
169 | + * @param string $sharedBy |
|
170 | + * |
|
171 | + * @since 14.0.0 |
|
172 | + */ |
|
173 | + public function setSharedBy($sharedBy) { |
|
174 | + $this->share['sharedBy'] = $sharedBy; |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * set display name of the user who sends the share |
|
179 | - * |
|
180 | - * @param $sharedByDisplayName |
|
181 | - * |
|
182 | - * @since 14.0.0 |
|
183 | - */ |
|
184 | - public function setSharedByDisplayName($sharedByDisplayName) { |
|
185 | - $this->share['sharedByDisplayName'] = $sharedByDisplayName; |
|
186 | - } |
|
177 | + /** |
|
178 | + * set display name of the user who sends the share |
|
179 | + * |
|
180 | + * @param $sharedByDisplayName |
|
181 | + * |
|
182 | + * @since 14.0.0 |
|
183 | + */ |
|
184 | + public function setSharedByDisplayName($sharedByDisplayName) { |
|
185 | + $this->share['sharedByDisplayName'] = $sharedByDisplayName; |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * set protocol specification |
|
190 | - * |
|
191 | - * @param array $protocol |
|
192 | - * |
|
193 | - * @since 14.0.0 |
|
194 | - */ |
|
195 | - public function setProtocol(array $protocol) { |
|
196 | - $this->share['protocol'] = $protocol; |
|
197 | - } |
|
188 | + /** |
|
189 | + * set protocol specification |
|
190 | + * |
|
191 | + * @param array $protocol |
|
192 | + * |
|
193 | + * @since 14.0.0 |
|
194 | + */ |
|
195 | + public function setProtocol(array $protocol) { |
|
196 | + $this->share['protocol'] = $protocol; |
|
197 | + } |
|
198 | 198 | |
199 | - /** |
|
200 | - * share type (group or user) |
|
201 | - * |
|
202 | - * @param string $shareType |
|
203 | - * |
|
204 | - * @since 14.0.0 |
|
205 | - */ |
|
206 | - public function setShareType($shareType) { |
|
207 | - $this->share['shareType'] = $shareType; |
|
208 | - } |
|
199 | + /** |
|
200 | + * share type (group or user) |
|
201 | + * |
|
202 | + * @param string $shareType |
|
203 | + * |
|
204 | + * @since 14.0.0 |
|
205 | + */ |
|
206 | + public function setShareType($shareType) { |
|
207 | + $this->share['shareType'] = $shareType; |
|
208 | + } |
|
209 | 209 | |
210 | - /** |
|
211 | - * get the whole share, ready to send out |
|
212 | - * |
|
213 | - * @return array |
|
214 | - * |
|
215 | - * @since 14.0.0 |
|
216 | - */ |
|
217 | - public function getShare() { |
|
218 | - return $this->share; |
|
219 | - } |
|
210 | + /** |
|
211 | + * get the whole share, ready to send out |
|
212 | + * |
|
213 | + * @return array |
|
214 | + * |
|
215 | + * @since 14.0.0 |
|
216 | + */ |
|
217 | + public function getShare() { |
|
218 | + return $this->share; |
|
219 | + } |
|
220 | 220 | |
221 | - /** |
|
222 | - * get uid of the recipient |
|
223 | - * |
|
224 | - * @return string |
|
225 | - * |
|
226 | - * @since 14.0.0 |
|
227 | - */ |
|
228 | - public function getShareWith() { |
|
229 | - return $this->share['shareWith']; |
|
230 | - } |
|
221 | + /** |
|
222 | + * get uid of the recipient |
|
223 | + * |
|
224 | + * @return string |
|
225 | + * |
|
226 | + * @since 14.0.0 |
|
227 | + */ |
|
228 | + public function getShareWith() { |
|
229 | + return $this->share['shareWith']; |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
233 | - * get resource name (e.g. file, calendar, contact,...) |
|
234 | - * |
|
235 | - * @return string |
|
236 | - * |
|
237 | - * @since 14.0.0 |
|
238 | - */ |
|
239 | - public function getResourceName() { |
|
240 | - return $this->share['name']; |
|
241 | - } |
|
232 | + /** |
|
233 | + * get resource name (e.g. file, calendar, contact,...) |
|
234 | + * |
|
235 | + * @return string |
|
236 | + * |
|
237 | + * @since 14.0.0 |
|
238 | + */ |
|
239 | + public function getResourceName() { |
|
240 | + return $this->share['name']; |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * get resource type (e.g. file, calendar, contact,...) |
|
245 | - * |
|
246 | - * @return string |
|
247 | - * |
|
248 | - * @since 14.0.0 |
|
249 | - */ |
|
250 | - public function getResourceType() { |
|
251 | - return $this->share['resourceType']; |
|
252 | - } |
|
243 | + /** |
|
244 | + * get resource type (e.g. file, calendar, contact,...) |
|
245 | + * |
|
246 | + * @return string |
|
247 | + * |
|
248 | + * @since 14.0.0 |
|
249 | + */ |
|
250 | + public function getResourceType() { |
|
251 | + return $this->share['resourceType']; |
|
252 | + } |
|
253 | 253 | |
254 | - /** |
|
255 | - * get resource description (optional) |
|
256 | - * |
|
257 | - * @return string |
|
258 | - * |
|
259 | - * @since 14.0.0 |
|
260 | - */ |
|
261 | - public function getDescription() { |
|
262 | - return $this->share['description']; |
|
263 | - } |
|
254 | + /** |
|
255 | + * get resource description (optional) |
|
256 | + * |
|
257 | + * @return string |
|
258 | + * |
|
259 | + * @since 14.0.0 |
|
260 | + */ |
|
261 | + public function getDescription() { |
|
262 | + return $this->share['description']; |
|
263 | + } |
|
264 | 264 | |
265 | - /** |
|
266 | - * get provider ID (e.g. file ID) |
|
267 | - * |
|
268 | - * @return string |
|
269 | - * |
|
270 | - * @since 14.0.0 |
|
271 | - */ |
|
272 | - public function getProviderId() { |
|
273 | - return $this->share['providerId']; |
|
274 | - } |
|
265 | + /** |
|
266 | + * get provider ID (e.g. file ID) |
|
267 | + * |
|
268 | + * @return string |
|
269 | + * |
|
270 | + * @since 14.0.0 |
|
271 | + */ |
|
272 | + public function getProviderId() { |
|
273 | + return $this->share['providerId']; |
|
274 | + } |
|
275 | 275 | |
276 | - /** |
|
277 | - * get owner UID |
|
278 | - * |
|
279 | - * @return string |
|
280 | - * |
|
281 | - * @since 14.0.0 |
|
282 | - */ |
|
283 | - public function getOwner() { |
|
284 | - return $this->share['owner']; |
|
285 | - } |
|
276 | + /** |
|
277 | + * get owner UID |
|
278 | + * |
|
279 | + * @return string |
|
280 | + * |
|
281 | + * @since 14.0.0 |
|
282 | + */ |
|
283 | + public function getOwner() { |
|
284 | + return $this->share['owner']; |
|
285 | + } |
|
286 | 286 | |
287 | - /** |
|
288 | - * get owner display name |
|
289 | - * |
|
290 | - * @return string |
|
291 | - * |
|
292 | - * @since 14.0.0 |
|
293 | - */ |
|
294 | - public function getOwnerDisplayName() { |
|
295 | - return $this->share['ownerDisplayName']; |
|
296 | - } |
|
287 | + /** |
|
288 | + * get owner display name |
|
289 | + * |
|
290 | + * @return string |
|
291 | + * |
|
292 | + * @since 14.0.0 |
|
293 | + */ |
|
294 | + public function getOwnerDisplayName() { |
|
295 | + return $this->share['ownerDisplayName']; |
|
296 | + } |
|
297 | 297 | |
298 | - /** |
|
299 | - * get UID of the user who sends the share |
|
300 | - * |
|
301 | - * @return string |
|
302 | - * |
|
303 | - * @since 14.0.0 |
|
304 | - */ |
|
305 | - public function getSharedBy() { |
|
306 | - return $this->share['sharedBy']; |
|
307 | - } |
|
298 | + /** |
|
299 | + * get UID of the user who sends the share |
|
300 | + * |
|
301 | + * @return string |
|
302 | + * |
|
303 | + * @since 14.0.0 |
|
304 | + */ |
|
305 | + public function getSharedBy() { |
|
306 | + return $this->share['sharedBy']; |
|
307 | + } |
|
308 | 308 | |
309 | - /** |
|
310 | - * get display name of the user who sends the share |
|
311 | - * |
|
312 | - * @return string |
|
313 | - * |
|
314 | - * @since 14.0.0 |
|
315 | - */ |
|
316 | - public function getSharedByDisplayName() { |
|
317 | - return $this->share['sharedByDisplayName']; |
|
318 | - } |
|
309 | + /** |
|
310 | + * get display name of the user who sends the share |
|
311 | + * |
|
312 | + * @return string |
|
313 | + * |
|
314 | + * @since 14.0.0 |
|
315 | + */ |
|
316 | + public function getSharedByDisplayName() { |
|
317 | + return $this->share['sharedByDisplayName']; |
|
318 | + } |
|
319 | 319 | |
320 | - /** |
|
321 | - * get share type (group or user) |
|
322 | - * |
|
323 | - * @return string |
|
324 | - * |
|
325 | - * @since 14.0.0 |
|
326 | - */ |
|
327 | - public function getShareType() { |
|
328 | - return $this->share['shareType']; |
|
329 | - } |
|
320 | + /** |
|
321 | + * get share type (group or user) |
|
322 | + * |
|
323 | + * @return string |
|
324 | + * |
|
325 | + * @since 14.0.0 |
|
326 | + */ |
|
327 | + public function getShareType() { |
|
328 | + return $this->share['shareType']; |
|
329 | + } |
|
330 | 330 | |
331 | - /** |
|
332 | - * get share Secret |
|
333 | - * |
|
334 | - * @return string |
|
335 | - * |
|
336 | - * @since 14.0.0 |
|
337 | - */ |
|
338 | - public function getShareSecret() { |
|
339 | - return $this->share['protocol']['options']['sharedSecret']; |
|
340 | - } |
|
331 | + /** |
|
332 | + * get share Secret |
|
333 | + * |
|
334 | + * @return string |
|
335 | + * |
|
336 | + * @since 14.0.0 |
|
337 | + */ |
|
338 | + public function getShareSecret() { |
|
339 | + return $this->share['protocol']['options']['sharedSecret']; |
|
340 | + } |
|
341 | 341 | |
342 | - /** |
|
343 | - * get protocol specification |
|
344 | - * |
|
345 | - * @return array |
|
346 | - * |
|
347 | - * @since 14.0.0 |
|
348 | - */ |
|
349 | - public function getProtocol() { |
|
350 | - return $this->share['protocol']; |
|
351 | - } |
|
342 | + /** |
|
343 | + * get protocol specification |
|
344 | + * |
|
345 | + * @return array |
|
346 | + * |
|
347 | + * @since 14.0.0 |
|
348 | + */ |
|
349 | + public function getProtocol() { |
|
350 | + return $this->share['protocol']; |
|
351 | + } |
|
352 | 352 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | IClientService $httpClientService, |
72 | 72 | ICloudIdManager $cloudIdManager, |
73 | 73 | ILogger $logger) { |
74 | - $this->cloudFederationProvider= []; |
|
74 | + $this->cloudFederationProvider = []; |
|
75 | 75 | $this->appManager = $appManager; |
76 | 76 | $this->httpClientService = $httpClientService; |
77 | 77 | $this->cloudIdManager = $cloudIdManager; |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | $client = $this->httpClientService->newClient(); |
142 | 142 | try { |
143 | - $response = $client->post($ocmEndPoint . '/shares', [ |
|
143 | + $response = $client->post($ocmEndPoint.'/shares', [ |
|
144 | 144 | 'body' => $share->getShare(), |
145 | 145 | 'timeout' => 10, |
146 | 146 | 'connect_timeout' => 10, |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | |
178 | 178 | $client = $this->httpClientService->newClient(); |
179 | 179 | try { |
180 | - $response = $client->post($ocmEndPoint . '/notifications', [ |
|
180 | + $response = $client->post($ocmEndPoint.'/notifications', [ |
|
181 | 181 | 'body' => $notification->getMessage(), |
182 | 182 | 'timeout' => 10, |
183 | 183 | 'connect_timeout' => 10, |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | } |
188 | 188 | } catch (\Exception $e) { |
189 | 189 | // log the error and return false |
190 | - $this->logger->error('error while sending notification for federated share: ' . $e->getMessage()); |
|
190 | + $this->logger->error('error while sending notification for federated share: '.$e->getMessage()); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | return false; |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | protected function getOCMEndPoint($url) { |
211 | 211 | $client = $this->httpClientService->newClient(); |
212 | 212 | try { |
213 | - $response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
213 | + $response = $client->get($url.'/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
214 | 214 | } catch (\Exception $e) { |
215 | 215 | return ''; |
216 | 216 | } |
@@ -42,191 +42,191 @@ |
||
42 | 42 | */ |
43 | 43 | class CloudFederationProviderManager implements ICloudFederationProviderManager { |
44 | 44 | |
45 | - /** @var array list of available cloud federation providers */ |
|
46 | - private $cloudFederationProvider; |
|
47 | - |
|
48 | - /** @var IAppManager */ |
|
49 | - private $appManager; |
|
50 | - |
|
51 | - /** @var IClientService */ |
|
52 | - private $httpClientService; |
|
53 | - |
|
54 | - /** @var ICloudIdManager */ |
|
55 | - private $cloudIdManager; |
|
56 | - |
|
57 | - /** @var ILogger */ |
|
58 | - private $logger; |
|
59 | - |
|
60 | - private $supportedAPIVersion = '1.0-proposal1'; |
|
61 | - |
|
62 | - /** |
|
63 | - * CloudFederationProviderManager constructor. |
|
64 | - * |
|
65 | - * @param IAppManager $appManager |
|
66 | - * @param IClientService $httpClientService |
|
67 | - * @param ICloudIdManager $cloudIdManager |
|
68 | - * @param ILogger $logger |
|
69 | - */ |
|
70 | - public function __construct(IAppManager $appManager, |
|
71 | - IClientService $httpClientService, |
|
72 | - ICloudIdManager $cloudIdManager, |
|
73 | - ILogger $logger) { |
|
74 | - $this->cloudFederationProvider= []; |
|
75 | - $this->appManager = $appManager; |
|
76 | - $this->httpClientService = $httpClientService; |
|
77 | - $this->cloudIdManager = $cloudIdManager; |
|
78 | - $this->logger = $logger; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * Registers an callback function which must return an cloud federation provider |
|
84 | - * |
|
85 | - * @param string $shareType which share type does the provider handles |
|
86 | - * @param string $displayName user facing name of the federated share provider |
|
87 | - * @param callable $callback |
|
88 | - */ |
|
89 | - public function addCloudFederationProvider($shareType, $displayName, callable $callback) { |
|
90 | - \OC::$server->getRemoteApiFactory(); |
|
91 | - |
|
92 | - $this->cloudFederationProvider[$shareType] = [ |
|
93 | - 'shareType' => $shareType, |
|
94 | - 'displayName' => $displayName, |
|
95 | - 'callback' => $callback, |
|
96 | - ]; |
|
97 | - |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * remove cloud federation provider |
|
102 | - * |
|
103 | - * @param string $providerId |
|
104 | - */ |
|
105 | - public function removeCloudFederationProvider($providerId) { |
|
106 | - unset($this->cloudFederationProvider[$providerId]); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * get a list of all cloudFederationProviders |
|
111 | - * |
|
112 | - * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]] |
|
113 | - */ |
|
114 | - public function getAllCloudFederationProviders() { |
|
115 | - return $this->cloudFederationProvider; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * get a specific cloud federation provider |
|
120 | - * |
|
121 | - * @param string $shareType |
|
122 | - * @return ICloudFederationProvider |
|
123 | - * @throws ProviderDoesNotExistsException |
|
124 | - */ |
|
125 | - public function getCloudFederationProvider($shareType) { |
|
126 | - if (isset($this->cloudFederationProvider[$shareType])) { |
|
127 | - return call_user_func($this->cloudFederationProvider[$shareType]['callback']); |
|
128 | - } else { |
|
129 | - throw new ProviderDoesNotExistsException($shareType); |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - public function sendShare(ICloudFederationShare $share) { |
|
134 | - $cloudID = $this->cloudIdManager->resolveCloudId($share->getShareWith()); |
|
135 | - $ocmEndPoint = $this->getOCMEndPoint($cloudID->getRemote()); |
|
136 | - |
|
137 | - if (empty($ocmEndPoint)) { |
|
138 | - return false; |
|
139 | - } |
|
140 | - |
|
141 | - $client = $this->httpClientService->newClient(); |
|
142 | - try { |
|
143 | - $response = $client->post($ocmEndPoint . '/shares', [ |
|
144 | - 'body' => $share->getShare(), |
|
145 | - 'timeout' => 10, |
|
146 | - 'connect_timeout' => 10, |
|
147 | - ]); |
|
148 | - |
|
149 | - if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
150 | - return true; |
|
151 | - } |
|
152 | - |
|
153 | - } catch (\Exception $e) { |
|
154 | - // if flat re-sharing is not supported by the remote server |
|
155 | - // we re-throw the exception and fall back to the old behaviour. |
|
156 | - // (flat re-shares has been introduced in Nextcloud 9.1) |
|
157 | - if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
158 | - throw $e; |
|
159 | - } |
|
160 | - } |
|
161 | - |
|
162 | - return false; |
|
163 | - |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @param string $url |
|
168 | - * @param ICloudFederationNotification $notification |
|
169 | - * @return mixed |
|
170 | - */ |
|
171 | - public function sendNotification($url, ICloudFederationNotification $notification) { |
|
172 | - $ocmEndPoint = $this->getOCMEndPoint($url); |
|
173 | - |
|
174 | - if (empty($ocmEndPoint)) { |
|
175 | - return false; |
|
176 | - } |
|
177 | - |
|
178 | - $client = $this->httpClientService->newClient(); |
|
179 | - try { |
|
180 | - $response = $client->post($ocmEndPoint . '/notifications', [ |
|
181 | - 'body' => $notification->getMessage(), |
|
182 | - 'timeout' => 10, |
|
183 | - 'connect_timeout' => 10, |
|
184 | - ]); |
|
185 | - if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
186 | - $result = json_decode($response->getBody(), true); |
|
187 | - return (is_array($result)) ? $result : []; |
|
188 | - } |
|
189 | - } catch (\Exception $e) { |
|
190 | - // log the error and return false |
|
191 | - $this->logger->error('error while sending notification for federated share: ' . $e->getMessage()); |
|
192 | - } |
|
193 | - |
|
194 | - return false; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * check if the new cloud federation API is ready to be used |
|
199 | - * |
|
200 | - * @return bool |
|
201 | - */ |
|
202 | - public function isReady() { |
|
203 | - return $this->appManager->isEnabledForUser('cloud_federation_api'); |
|
204 | - } |
|
205 | - /** |
|
206 | - * check if server supports the new OCM api and ask for the correct end-point |
|
207 | - * |
|
208 | - * @param string $url full base URL of the cloud server |
|
209 | - * @return string |
|
210 | - */ |
|
211 | - protected function getOCMEndPoint($url) { |
|
212 | - $client = $this->httpClientService->newClient(); |
|
213 | - try { |
|
214 | - $response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
215 | - } catch (\Exception $e) { |
|
216 | - return ''; |
|
217 | - } |
|
218 | - |
|
219 | - $result = $response->getBody(); |
|
220 | - $result = json_decode($result, true); |
|
221 | - |
|
222 | - $supportedVersion = isset($result['apiVersion']) && $result['apiVersion'] === $this->supportedAPIVersion; |
|
223 | - |
|
224 | - if (isset($result['endPoint']) && $supportedVersion) { |
|
225 | - return $result['endPoint']; |
|
226 | - } |
|
227 | - |
|
228 | - return ''; |
|
229 | - } |
|
45 | + /** @var array list of available cloud federation providers */ |
|
46 | + private $cloudFederationProvider; |
|
47 | + |
|
48 | + /** @var IAppManager */ |
|
49 | + private $appManager; |
|
50 | + |
|
51 | + /** @var IClientService */ |
|
52 | + private $httpClientService; |
|
53 | + |
|
54 | + /** @var ICloudIdManager */ |
|
55 | + private $cloudIdManager; |
|
56 | + |
|
57 | + /** @var ILogger */ |
|
58 | + private $logger; |
|
59 | + |
|
60 | + private $supportedAPIVersion = '1.0-proposal1'; |
|
61 | + |
|
62 | + /** |
|
63 | + * CloudFederationProviderManager constructor. |
|
64 | + * |
|
65 | + * @param IAppManager $appManager |
|
66 | + * @param IClientService $httpClientService |
|
67 | + * @param ICloudIdManager $cloudIdManager |
|
68 | + * @param ILogger $logger |
|
69 | + */ |
|
70 | + public function __construct(IAppManager $appManager, |
|
71 | + IClientService $httpClientService, |
|
72 | + ICloudIdManager $cloudIdManager, |
|
73 | + ILogger $logger) { |
|
74 | + $this->cloudFederationProvider= []; |
|
75 | + $this->appManager = $appManager; |
|
76 | + $this->httpClientService = $httpClientService; |
|
77 | + $this->cloudIdManager = $cloudIdManager; |
|
78 | + $this->logger = $logger; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * Registers an callback function which must return an cloud federation provider |
|
84 | + * |
|
85 | + * @param string $shareType which share type does the provider handles |
|
86 | + * @param string $displayName user facing name of the federated share provider |
|
87 | + * @param callable $callback |
|
88 | + */ |
|
89 | + public function addCloudFederationProvider($shareType, $displayName, callable $callback) { |
|
90 | + \OC::$server->getRemoteApiFactory(); |
|
91 | + |
|
92 | + $this->cloudFederationProvider[$shareType] = [ |
|
93 | + 'shareType' => $shareType, |
|
94 | + 'displayName' => $displayName, |
|
95 | + 'callback' => $callback, |
|
96 | + ]; |
|
97 | + |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * remove cloud federation provider |
|
102 | + * |
|
103 | + * @param string $providerId |
|
104 | + */ |
|
105 | + public function removeCloudFederationProvider($providerId) { |
|
106 | + unset($this->cloudFederationProvider[$providerId]); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * get a list of all cloudFederationProviders |
|
111 | + * |
|
112 | + * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]] |
|
113 | + */ |
|
114 | + public function getAllCloudFederationProviders() { |
|
115 | + return $this->cloudFederationProvider; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * get a specific cloud federation provider |
|
120 | + * |
|
121 | + * @param string $shareType |
|
122 | + * @return ICloudFederationProvider |
|
123 | + * @throws ProviderDoesNotExistsException |
|
124 | + */ |
|
125 | + public function getCloudFederationProvider($shareType) { |
|
126 | + if (isset($this->cloudFederationProvider[$shareType])) { |
|
127 | + return call_user_func($this->cloudFederationProvider[$shareType]['callback']); |
|
128 | + } else { |
|
129 | + throw new ProviderDoesNotExistsException($shareType); |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + public function sendShare(ICloudFederationShare $share) { |
|
134 | + $cloudID = $this->cloudIdManager->resolveCloudId($share->getShareWith()); |
|
135 | + $ocmEndPoint = $this->getOCMEndPoint($cloudID->getRemote()); |
|
136 | + |
|
137 | + if (empty($ocmEndPoint)) { |
|
138 | + return false; |
|
139 | + } |
|
140 | + |
|
141 | + $client = $this->httpClientService->newClient(); |
|
142 | + try { |
|
143 | + $response = $client->post($ocmEndPoint . '/shares', [ |
|
144 | + 'body' => $share->getShare(), |
|
145 | + 'timeout' => 10, |
|
146 | + 'connect_timeout' => 10, |
|
147 | + ]); |
|
148 | + |
|
149 | + if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
150 | + return true; |
|
151 | + } |
|
152 | + |
|
153 | + } catch (\Exception $e) { |
|
154 | + // if flat re-sharing is not supported by the remote server |
|
155 | + // we re-throw the exception and fall back to the old behaviour. |
|
156 | + // (flat re-shares has been introduced in Nextcloud 9.1) |
|
157 | + if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
158 | + throw $e; |
|
159 | + } |
|
160 | + } |
|
161 | + |
|
162 | + return false; |
|
163 | + |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @param string $url |
|
168 | + * @param ICloudFederationNotification $notification |
|
169 | + * @return mixed |
|
170 | + */ |
|
171 | + public function sendNotification($url, ICloudFederationNotification $notification) { |
|
172 | + $ocmEndPoint = $this->getOCMEndPoint($url); |
|
173 | + |
|
174 | + if (empty($ocmEndPoint)) { |
|
175 | + return false; |
|
176 | + } |
|
177 | + |
|
178 | + $client = $this->httpClientService->newClient(); |
|
179 | + try { |
|
180 | + $response = $client->post($ocmEndPoint . '/notifications', [ |
|
181 | + 'body' => $notification->getMessage(), |
|
182 | + 'timeout' => 10, |
|
183 | + 'connect_timeout' => 10, |
|
184 | + ]); |
|
185 | + if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
186 | + $result = json_decode($response->getBody(), true); |
|
187 | + return (is_array($result)) ? $result : []; |
|
188 | + } |
|
189 | + } catch (\Exception $e) { |
|
190 | + // log the error and return false |
|
191 | + $this->logger->error('error while sending notification for federated share: ' . $e->getMessage()); |
|
192 | + } |
|
193 | + |
|
194 | + return false; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * check if the new cloud federation API is ready to be used |
|
199 | + * |
|
200 | + * @return bool |
|
201 | + */ |
|
202 | + public function isReady() { |
|
203 | + return $this->appManager->isEnabledForUser('cloud_federation_api'); |
|
204 | + } |
|
205 | + /** |
|
206 | + * check if server supports the new OCM api and ask for the correct end-point |
|
207 | + * |
|
208 | + * @param string $url full base URL of the cloud server |
|
209 | + * @return string |
|
210 | + */ |
|
211 | + protected function getOCMEndPoint($url) { |
|
212 | + $client = $this->httpClientService->newClient(); |
|
213 | + try { |
|
214 | + $response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
215 | + } catch (\Exception $e) { |
|
216 | + return ''; |
|
217 | + } |
|
218 | + |
|
219 | + $result = $response->getBody(); |
|
220 | + $result = json_decode($result, true); |
|
221 | + |
|
222 | + $supportedVersion = isset($result['apiVersion']) && $result['apiVersion'] === $this->supportedAPIVersion; |
|
223 | + |
|
224 | + if (isset($result['endPoint']) && $supportedVersion) { |
|
225 | + return $result['endPoint']; |
|
226 | + } |
|
227 | + |
|
228 | + return ''; |
|
229 | + } |
|
230 | 230 | |
231 | 231 | |
232 | 232 | } |
@@ -27,37 +27,37 @@ |
||
27 | 27 | |
28 | 28 | class CloudFederationFactory implements ICloudFederationFactory { |
29 | 29 | |
30 | - /** |
|
31 | - * get a CloudFederationShare Object to prepare a share you want to send |
|
32 | - * |
|
33 | - * @param string $shareWith |
|
34 | - * @param string $name resource name (e.g. document.odt) |
|
35 | - * @param string $description share description (optional) |
|
36 | - * @param string $providerId resource UID on the provider side |
|
37 | - * @param string $owner provider specific UID of the user who owns the resource |
|
38 | - * @param string $ownerDisplayName display name of the user who shared the item |
|
39 | - * @param string $sharedBy provider specific UID of the user who shared the resource |
|
40 | - * @param string $sharedByDisplayName display name of the user who shared the resource |
|
41 | - * @param string $sharedSecret used to authenticate requests across servers |
|
42 | - * @param string $shareType ('group' or 'user' share) |
|
43 | - * @param $resourceType ('file', 'calendar',...) |
|
44 | - * @return ICloudFederationShare |
|
45 | - * |
|
46 | - * @since 14.0.0 |
|
47 | - */ |
|
48 | - public function getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $sharedSecret, $shareType, $resourceType) { |
|
49 | - return new CloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $shareType, $resourceType, $sharedSecret); |
|
50 | - } |
|
30 | + /** |
|
31 | + * get a CloudFederationShare Object to prepare a share you want to send |
|
32 | + * |
|
33 | + * @param string $shareWith |
|
34 | + * @param string $name resource name (e.g. document.odt) |
|
35 | + * @param string $description share description (optional) |
|
36 | + * @param string $providerId resource UID on the provider side |
|
37 | + * @param string $owner provider specific UID of the user who owns the resource |
|
38 | + * @param string $ownerDisplayName display name of the user who shared the item |
|
39 | + * @param string $sharedBy provider specific UID of the user who shared the resource |
|
40 | + * @param string $sharedByDisplayName display name of the user who shared the resource |
|
41 | + * @param string $sharedSecret used to authenticate requests across servers |
|
42 | + * @param string $shareType ('group' or 'user' share) |
|
43 | + * @param $resourceType ('file', 'calendar',...) |
|
44 | + * @return ICloudFederationShare |
|
45 | + * |
|
46 | + * @since 14.0.0 |
|
47 | + */ |
|
48 | + public function getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $sharedSecret, $shareType, $resourceType) { |
|
49 | + return new CloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $shareType, $resourceType, $sharedSecret); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * get a Cloud FederationNotification object to prepare a notification you |
|
54 | - * want to send |
|
55 | - * |
|
56 | - * @return ICloudFederationNotification |
|
57 | - * |
|
58 | - * @since 14.0.0 |
|
59 | - */ |
|
60 | - public function getCloudFederationNotification() { |
|
61 | - return new CloudFederationNotification(); |
|
62 | - } |
|
52 | + /** |
|
53 | + * get a Cloud FederationNotification object to prepare a notification you |
|
54 | + * want to send |
|
55 | + * |
|
56 | + * @return ICloudFederationNotification |
|
57 | + * |
|
58 | + * @since 14.0.0 |
|
59 | + */ |
|
60 | + public function getCloudFederationNotification() { |
|
61 | + return new CloudFederationNotification(); |
|
62 | + } |
|
63 | 63 | } |