@@ -1143,7 +1143,7 @@ discard block |
||
1143 | 1143 | * Get the certificate manager for the user |
1144 | 1144 | * |
1145 | 1145 | * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
1146 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1146 | + * @return null|CertificateManager | null if $uid is null and no user is logged in |
|
1147 | 1147 | */ |
1148 | 1148 | public function getCertificateManager($userId = '') { |
1149 | 1149 | if ($userId === '') { |
@@ -1464,6 +1464,7 @@ discard block |
||
1464 | 1464 | } |
1465 | 1465 | |
1466 | 1466 | /** |
1467 | + * @param string $app |
|
1467 | 1468 | * @return \OCP\Files\IAppData |
1468 | 1469 | */ |
1469 | 1470 | public function getAppDataDir($app) { |
@@ -115,7 +115,6 @@ |
||
115 | 115 | use OC\Template\JSCombiner; |
116 | 116 | use OC\Template\SCSSCacher; |
117 | 117 | use OCA\Theming\ThemingDefaults; |
118 | - |
|
119 | 118 | use OCP\App\IAppManager; |
120 | 119 | use OCP\AppFramework\Utility\ITimeFactory; |
121 | 120 | use OCP\Collaboration\AutoComplete\IManager; |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | parent::__construct(); |
162 | 162 | $this->webRoot = $webRoot; |
163 | 163 | |
164 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
164 | + $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
165 | 165 | return $c; |
166 | 166 | }); |
167 | 167 | |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
175 | 175 | |
176 | 176 | |
177 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
177 | + $this->registerService(\OCP\IPreview::class, function(Server $c) { |
|
178 | 178 | return new PreviewManager( |
179 | 179 | $c->getConfig(), |
180 | 180 | $c->getRootFolder(), |
@@ -185,13 +185,13 @@ discard block |
||
185 | 185 | }); |
186 | 186 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
187 | 187 | |
188 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
188 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
189 | 189 | return new \OC\Preview\Watcher( |
190 | 190 | $c->getAppDataDir('preview') |
191 | 191 | ); |
192 | 192 | }); |
193 | 193 | |
194 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
194 | + $this->registerService('EncryptionManager', function(Server $c) { |
|
195 | 195 | $view = new View(); |
196 | 196 | $util = new Encryption\Util( |
197 | 197 | $view, |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | ); |
210 | 210 | }); |
211 | 211 | |
212 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
212 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
213 | 213 | $util = new Encryption\Util( |
214 | 214 | new View(), |
215 | 215 | $c->getUserManager(), |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | ); |
224 | 224 | }); |
225 | 225 | |
226 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
226 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
227 | 227 | $view = new View(); |
228 | 228 | $util = new Encryption\Util( |
229 | 229 | $view, |
@@ -234,30 +234,30 @@ discard block |
||
234 | 234 | |
235 | 235 | return new Encryption\Keys\Storage($view, $util); |
236 | 236 | }); |
237 | - $this->registerService('TagMapper', function (Server $c) { |
|
237 | + $this->registerService('TagMapper', function(Server $c) { |
|
238 | 238 | return new TagMapper($c->getDatabaseConnection()); |
239 | 239 | }); |
240 | 240 | |
241 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
241 | + $this->registerService(\OCP\ITagManager::class, function(Server $c) { |
|
242 | 242 | $tagMapper = $c->query('TagMapper'); |
243 | 243 | return new TagManager($tagMapper, $c->getUserSession()); |
244 | 244 | }); |
245 | 245 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
246 | 246 | |
247 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
247 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
248 | 248 | $config = $c->getConfig(); |
249 | 249 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
250 | 250 | return new $factoryClass($this); |
251 | 251 | }); |
252 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
252 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) { |
|
253 | 253 | return $c->query('SystemTagManagerFactory')->getManager(); |
254 | 254 | }); |
255 | 255 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
256 | 256 | |
257 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
257 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) { |
|
258 | 258 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
259 | 259 | }); |
260 | - $this->registerService('RootFolder', function (Server $c) { |
|
260 | + $this->registerService('RootFolder', function(Server $c) { |
|
261 | 261 | $manager = \OC\Files\Filesystem::getMountManager(null); |
262 | 262 | $view = new View(); |
263 | 263 | $root = new Root( |
@@ -278,38 +278,38 @@ discard block |
||
278 | 278 | }); |
279 | 279 | $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
280 | 280 | |
281 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
282 | - return new LazyRoot(function () use ($c) { |
|
281 | + $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
282 | + return new LazyRoot(function() use ($c) { |
|
283 | 283 | return $c->query('RootFolder'); |
284 | 284 | }); |
285 | 285 | }); |
286 | 286 | $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
287 | 287 | |
288 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
288 | + $this->registerService(\OC\User\Manager::class, function(Server $c) { |
|
289 | 289 | $config = $c->getConfig(); |
290 | 290 | return new \OC\User\Manager($config); |
291 | 291 | }); |
292 | 292 | $this->registerAlias('UserManager', \OC\User\Manager::class); |
293 | 293 | $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
294 | 294 | |
295 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
295 | + $this->registerService(\OCP\IGroupManager::class, function(Server $c) { |
|
296 | 296 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
297 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
297 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
298 | 298 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
299 | 299 | }); |
300 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
300 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) { |
|
301 | 301 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
302 | 302 | }); |
303 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
303 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
304 | 304 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
305 | 305 | }); |
306 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
306 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
307 | 307 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
308 | 308 | }); |
309 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
309 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
310 | 310 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
311 | 311 | }); |
312 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
312 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
313 | 313 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
314 | 314 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
315 | 315 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | }); |
319 | 319 | $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
320 | 320 | |
321 | - $this->registerService(Store::class, function (Server $c) { |
|
321 | + $this->registerService(Store::class, function(Server $c) { |
|
322 | 322 | $session = $c->getSession(); |
323 | 323 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
324 | 324 | $tokenProvider = $c->query(IProvider::class); |
@@ -329,11 +329,11 @@ discard block |
||
329 | 329 | return new Store($session, $logger, $tokenProvider); |
330 | 330 | }); |
331 | 331 | $this->registerAlias(IStore::class, Store::class); |
332 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
332 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function(Server $c) { |
|
333 | 333 | $dbConnection = $c->getDatabaseConnection(); |
334 | 334 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
335 | 335 | }); |
336 | - $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
|
336 | + $this->registerService(Authentication\Token\DefaultTokenProvider::class, function(Server $c) { |
|
337 | 337 | $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
338 | 338 | $crypto = $c->getCrypto(); |
339 | 339 | $config = $c->getConfig(); |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | }); |
344 | 344 | $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
345 | 345 | |
346 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
346 | + $this->registerService(\OCP\IUserSession::class, function(Server $c) { |
|
347 | 347 | $manager = $c->getUserManager(); |
348 | 348 | $session = new \OC\Session\Memory(''); |
349 | 349 | $timeFactory = new TimeFactory(); |
@@ -367,45 +367,45 @@ discard block |
||
367 | 367 | $c->getLockdownManager(), |
368 | 368 | $c->getLogger() |
369 | 369 | ); |
370 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
370 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
371 | 371 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
372 | 372 | }); |
373 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
373 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
374 | 374 | /** @var $user \OC\User\User */ |
375 | 375 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
376 | 376 | }); |
377 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
377 | + $userSession->listen('\OC\User', 'preDelete', function($user) use ($dispatcher) { |
|
378 | 378 | /** @var $user \OC\User\User */ |
379 | 379 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
380 | 380 | $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
381 | 381 | }); |
382 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
382 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
383 | 383 | /** @var $user \OC\User\User */ |
384 | 384 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
385 | 385 | }); |
386 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
386 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
387 | 387 | /** @var $user \OC\User\User */ |
388 | 388 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
389 | 389 | }); |
390 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
390 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
391 | 391 | /** @var $user \OC\User\User */ |
392 | 392 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
393 | 393 | }); |
394 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
394 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
395 | 395 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
396 | 396 | }); |
397 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
397 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password) { |
|
398 | 398 | /** @var $user \OC\User\User */ |
399 | 399 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
400 | 400 | }); |
401 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
401 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
402 | 402 | /** @var $user \OC\User\User */ |
403 | 403 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
404 | 404 | }); |
405 | - $userSession->listen('\OC\User', 'logout', function () { |
|
405 | + $userSession->listen('\OC\User', 'logout', function() { |
|
406 | 406 | \OC_Hook::emit('OC_User', 'logout', array()); |
407 | 407 | }); |
408 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
408 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
409 | 409 | /** @var $user \OC\User\User */ |
410 | 410 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
411 | 411 | $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | }); |
415 | 415 | $this->registerAlias('UserSession', \OCP\IUserSession::class); |
416 | 416 | |
417 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
417 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) { |
|
418 | 418 | return new \OC\Authentication\TwoFactorAuth\Manager( |
419 | 419 | $c->getAppManager(), |
420 | 420 | $c->getSession(), |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
431 | 431 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
432 | 432 | |
433 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
433 | + $this->registerService(\OC\AllConfig::class, function(Server $c) { |
|
434 | 434 | return new \OC\AllConfig( |
435 | 435 | $c->getSystemConfig() |
436 | 436 | ); |
@@ -438,17 +438,17 @@ discard block |
||
438 | 438 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
439 | 439 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
440 | 440 | |
441 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
441 | + $this->registerService('SystemConfig', function($c) use ($config) { |
|
442 | 442 | return new \OC\SystemConfig($config); |
443 | 443 | }); |
444 | 444 | |
445 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
445 | + $this->registerService(\OC\AppConfig::class, function(Server $c) { |
|
446 | 446 | return new \OC\AppConfig($c->getDatabaseConnection()); |
447 | 447 | }); |
448 | 448 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
449 | 449 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
450 | 450 | |
451 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
451 | + $this->registerService(\OCP\L10N\IFactory::class, function(Server $c) { |
|
452 | 452 | return new \OC\L10N\Factory( |
453 | 453 | $c->getConfig(), |
454 | 454 | $c->getRequest(), |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | }); |
459 | 459 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
460 | 460 | |
461 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
461 | + $this->registerService(\OCP\IURLGenerator::class, function(Server $c) { |
|
462 | 462 | $config = $c->getConfig(); |
463 | 463 | $cacheFactory = $c->getMemCacheFactory(); |
464 | 464 | $request = $c->getRequest(); |
@@ -470,18 +470,18 @@ discard block |
||
470 | 470 | }); |
471 | 471 | $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
472 | 472 | |
473 | - $this->registerService('AppHelper', function ($c) { |
|
473 | + $this->registerService('AppHelper', function($c) { |
|
474 | 474 | return new \OC\AppHelper(); |
475 | 475 | }); |
476 | 476 | $this->registerAlias('AppFetcher', AppFetcher::class); |
477 | 477 | $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
478 | 478 | |
479 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
479 | + $this->registerService(\OCP\ICache::class, function($c) { |
|
480 | 480 | return new Cache\File(); |
481 | 481 | }); |
482 | 482 | $this->registerAlias('UserCache', \OCP\ICache::class); |
483 | 483 | |
484 | - $this->registerService(Factory::class, function (Server $c) { |
|
484 | + $this->registerService(Factory::class, function(Server $c) { |
|
485 | 485 | |
486 | 486 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
487 | 487 | ArrayCache::class, |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | $version = implode(',', $v); |
499 | 499 | $instanceId = \OC_Util::getInstanceId(); |
500 | 500 | $path = \OC::$SERVERROOT; |
501 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
501 | + $prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.$urlGenerator->getBaseUrl()); |
|
502 | 502 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
503 | 503 | $config->getSystemValue('memcache.local', null), |
504 | 504 | $config->getSystemValue('memcache.distributed', null), |
@@ -511,12 +511,12 @@ discard block |
||
511 | 511 | $this->registerAlias('MemCacheFactory', Factory::class); |
512 | 512 | $this->registerAlias(ICacheFactory::class, Factory::class); |
513 | 513 | |
514 | - $this->registerService('RedisFactory', function (Server $c) { |
|
514 | + $this->registerService('RedisFactory', function(Server $c) { |
|
515 | 515 | $systemConfig = $c->getSystemConfig(); |
516 | 516 | return new RedisFactory($systemConfig); |
517 | 517 | }); |
518 | 518 | |
519 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
519 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
520 | 520 | return new \OC\Activity\Manager( |
521 | 521 | $c->getRequest(), |
522 | 522 | $c->getUserSession(), |
@@ -526,14 +526,14 @@ discard block |
||
526 | 526 | }); |
527 | 527 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
528 | 528 | |
529 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
529 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
530 | 530 | return new \OC\Activity\EventMerger( |
531 | 531 | $c->getL10N('lib') |
532 | 532 | ); |
533 | 533 | }); |
534 | 534 | $this->registerAlias(IValidator::class, Validator::class); |
535 | 535 | |
536 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
536 | + $this->registerService(\OCP\IAvatarManager::class, function(Server $c) { |
|
537 | 537 | return new AvatarManager( |
538 | 538 | $c->query(\OC\User\Manager::class), |
539 | 539 | $c->getAppDataDir('avatar'), |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | |
547 | 547 | $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
548 | 548 | |
549 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
549 | + $this->registerService(\OCP\ILogger::class, function(Server $c) { |
|
550 | 550 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
551 | 551 | $logger = Log::getLogClass($logType); |
552 | 552 | call_user_func(array($logger, 'init')); |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | }); |
558 | 558 | $this->registerAlias('Logger', \OCP\ILogger::class); |
559 | 559 | |
560 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
560 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) { |
|
561 | 561 | $config = $c->getConfig(); |
562 | 562 | return new \OC\BackgroundJob\JobList( |
563 | 563 | $c->getDatabaseConnection(), |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | }); |
568 | 568 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
569 | 569 | |
570 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
570 | + $this->registerService(\OCP\Route\IRouter::class, function(Server $c) { |
|
571 | 571 | $cacheFactory = $c->getMemCacheFactory(); |
572 | 572 | $logger = $c->getLogger(); |
573 | 573 | if ($cacheFactory->isAvailableLowLatency()) { |
@@ -579,12 +579,12 @@ discard block |
||
579 | 579 | }); |
580 | 580 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
581 | 581 | |
582 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
582 | + $this->registerService(\OCP\ISearch::class, function($c) { |
|
583 | 583 | return new Search(); |
584 | 584 | }); |
585 | 585 | $this->registerAlias('Search', \OCP\ISearch::class); |
586 | 586 | |
587 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
587 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) { |
|
588 | 588 | return new \OC\Security\RateLimiting\Limiter( |
589 | 589 | $this->getUserSession(), |
590 | 590 | $this->getRequest(), |
@@ -592,34 +592,34 @@ discard block |
||
592 | 592 | $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
593 | 593 | ); |
594 | 594 | }); |
595 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
595 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
596 | 596 | return new \OC\Security\RateLimiting\Backend\MemoryCache( |
597 | 597 | $this->getMemCacheFactory(), |
598 | 598 | new \OC\AppFramework\Utility\TimeFactory() |
599 | 599 | ); |
600 | 600 | }); |
601 | 601 | |
602 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
602 | + $this->registerService(\OCP\Security\ISecureRandom::class, function($c) { |
|
603 | 603 | return new SecureRandom(); |
604 | 604 | }); |
605 | 605 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
606 | 606 | |
607 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
607 | + $this->registerService(\OCP\Security\ICrypto::class, function(Server $c) { |
|
608 | 608 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
609 | 609 | }); |
610 | 610 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
611 | 611 | |
612 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
612 | + $this->registerService(\OCP\Security\IHasher::class, function(Server $c) { |
|
613 | 613 | return new Hasher($c->getConfig()); |
614 | 614 | }); |
615 | 615 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
616 | 616 | |
617 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
617 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) { |
|
618 | 618 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
619 | 619 | }); |
620 | 620 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
621 | 621 | |
622 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
622 | + $this->registerService(IDBConnection::class, function(Server $c) { |
|
623 | 623 | $systemConfig = $c->getSystemConfig(); |
624 | 624 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
625 | 625 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | }); |
634 | 634 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
635 | 635 | |
636 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
636 | + $this->registerService('HTTPHelper', function(Server $c) { |
|
637 | 637 | $config = $c->getConfig(); |
638 | 638 | return new HTTPHelper( |
639 | 639 | $config, |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | ); |
642 | 642 | }); |
643 | 643 | |
644 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
644 | + $this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) { |
|
645 | 645 | $user = \OC_User::getUser(); |
646 | 646 | $uid = $user ? $user : null; |
647 | 647 | return new ClientService( |
@@ -656,7 +656,7 @@ discard block |
||
656 | 656 | ); |
657 | 657 | }); |
658 | 658 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
659 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
659 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) { |
|
660 | 660 | $eventLogger = new EventLogger(); |
661 | 661 | if ($c->getSystemConfig()->getValue('debug', false)) { |
662 | 662 | // In debug mode, module is being activated by default |
@@ -666,7 +666,7 @@ discard block |
||
666 | 666 | }); |
667 | 667 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
668 | 668 | |
669 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
669 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) { |
|
670 | 670 | $queryLogger = new QueryLogger(); |
671 | 671 | if ($c->getSystemConfig()->getValue('debug', false)) { |
672 | 672 | // In debug mode, module is being activated by default |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | }); |
677 | 677 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
678 | 678 | |
679 | - $this->registerService(TempManager::class, function (Server $c) { |
|
679 | + $this->registerService(TempManager::class, function(Server $c) { |
|
680 | 680 | return new TempManager( |
681 | 681 | $c->getLogger(), |
682 | 682 | $c->getConfig() |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | $this->registerAlias('TempManager', TempManager::class); |
686 | 686 | $this->registerAlias(ITempManager::class, TempManager::class); |
687 | 687 | |
688 | - $this->registerService(AppManager::class, function (Server $c) { |
|
688 | + $this->registerService(AppManager::class, function(Server $c) { |
|
689 | 689 | return new \OC\App\AppManager( |
690 | 690 | $c->getUserSession(), |
691 | 691 | $c->query(\OC\AppConfig::class), |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | $this->registerAlias('AppManager', AppManager::class); |
698 | 698 | $this->registerAlias(IAppManager::class, AppManager::class); |
699 | 699 | |
700 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
700 | + $this->registerService(\OCP\IDateTimeZone::class, function(Server $c) { |
|
701 | 701 | return new DateTimeZone( |
702 | 702 | $c->getConfig(), |
703 | 703 | $c->getSession() |
@@ -705,7 +705,7 @@ discard block |
||
705 | 705 | }); |
706 | 706 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
707 | 707 | |
708 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
708 | + $this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) { |
|
709 | 709 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
710 | 710 | |
711 | 711 | return new DateTimeFormatter( |
@@ -715,7 +715,7 @@ discard block |
||
715 | 715 | }); |
716 | 716 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
717 | 717 | |
718 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
718 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) { |
|
719 | 719 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
720 | 720 | $listener = new UserMountCacheListener($mountCache); |
721 | 721 | $listener->listen($c->getUserManager()); |
@@ -723,7 +723,7 @@ discard block |
||
723 | 723 | }); |
724 | 724 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
725 | 725 | |
726 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
726 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) { |
|
727 | 727 | $loader = \OC\Files\Filesystem::getLoader(); |
728 | 728 | $mountCache = $c->query('UserMountCache'); |
729 | 729 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
@@ -739,10 +739,10 @@ discard block |
||
739 | 739 | }); |
740 | 740 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
741 | 741 | |
742 | - $this->registerService('IniWrapper', function ($c) { |
|
742 | + $this->registerService('IniWrapper', function($c) { |
|
743 | 743 | return new IniGetWrapper(); |
744 | 744 | }); |
745 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
745 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
746 | 746 | $busClass = $c->getConfig()->getSystemValue('commandbus'); |
747 | 747 | if ($busClass) { |
748 | 748 | list($app, $class) = explode('::', $busClass, 2); |
@@ -757,10 +757,10 @@ discard block |
||
757 | 757 | return new CronBus($jobList); |
758 | 758 | } |
759 | 759 | }); |
760 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
760 | + $this->registerService('TrustedDomainHelper', function($c) { |
|
761 | 761 | return new TrustedDomainHelper($this->getConfig()); |
762 | 762 | }); |
763 | - $this->registerService('Throttler', function (Server $c) { |
|
763 | + $this->registerService('Throttler', function(Server $c) { |
|
764 | 764 | return new Throttler( |
765 | 765 | $c->getDatabaseConnection(), |
766 | 766 | new TimeFactory(), |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | $c->getConfig() |
769 | 769 | ); |
770 | 770 | }); |
771 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
771 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
772 | 772 | // IConfig and IAppManager requires a working database. This code |
773 | 773 | // might however be called when ownCloud is not yet setup. |
774 | 774 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
@@ -789,7 +789,7 @@ discard block |
||
789 | 789 | $c->getTempManager() |
790 | 790 | ); |
791 | 791 | }); |
792 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
792 | + $this->registerService(\OCP\IRequest::class, function($c) { |
|
793 | 793 | if (isset($this['urlParams'])) { |
794 | 794 | $urlParams = $this['urlParams']; |
795 | 795 | } else { |
@@ -825,7 +825,7 @@ discard block |
||
825 | 825 | }); |
826 | 826 | $this->registerAlias('Request', \OCP\IRequest::class); |
827 | 827 | |
828 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
828 | + $this->registerService(\OCP\Mail\IMailer::class, function(Server $c) { |
|
829 | 829 | return new Mailer( |
830 | 830 | $c->getConfig(), |
831 | 831 | $c->getLogger(), |
@@ -836,7 +836,7 @@ discard block |
||
836 | 836 | }); |
837 | 837 | $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
838 | 838 | |
839 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
839 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
840 | 840 | $config = $c->getConfig(); |
841 | 841 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
842 | 842 | if (is_null($factoryClass)) { |
@@ -846,7 +846,7 @@ discard block |
||
846 | 846 | $factory = new $factoryClass($this); |
847 | 847 | return $factory->getLDAPProvider(); |
848 | 848 | }); |
849 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
849 | + $this->registerService(ILockingProvider::class, function(Server $c) { |
|
850 | 850 | $ini = $c->getIniWrapper(); |
851 | 851 | $config = $c->getConfig(); |
852 | 852 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -863,49 +863,49 @@ discard block |
||
863 | 863 | }); |
864 | 864 | $this->registerAlias('LockingProvider', ILockingProvider::class); |
865 | 865 | |
866 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
866 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function() { |
|
867 | 867 | return new \OC\Files\Mount\Manager(); |
868 | 868 | }); |
869 | 869 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
870 | 870 | |
871 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
871 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) { |
|
872 | 872 | return new \OC\Files\Type\Detection( |
873 | 873 | $c->getURLGenerator(), |
874 | 874 | \OC::$configDir, |
875 | - \OC::$SERVERROOT . '/resources/config/' |
|
875 | + \OC::$SERVERROOT.'/resources/config/' |
|
876 | 876 | ); |
877 | 877 | }); |
878 | 878 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
879 | 879 | |
880 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
880 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) { |
|
881 | 881 | return new \OC\Files\Type\Loader( |
882 | 882 | $c->getDatabaseConnection() |
883 | 883 | ); |
884 | 884 | }); |
885 | 885 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
886 | - $this->registerService(BundleFetcher::class, function () { |
|
886 | + $this->registerService(BundleFetcher::class, function() { |
|
887 | 887 | return new BundleFetcher($this->getL10N('lib')); |
888 | 888 | }); |
889 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
889 | + $this->registerService(\OCP\Notification\IManager::class, function(Server $c) { |
|
890 | 890 | return new Manager( |
891 | 891 | $c->query(IValidator::class) |
892 | 892 | ); |
893 | 893 | }); |
894 | 894 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
895 | 895 | |
896 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
896 | + $this->registerService(\OC\CapabilitiesManager::class, function(Server $c) { |
|
897 | 897 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
898 | - $manager->registerCapability(function () use ($c) { |
|
898 | + $manager->registerCapability(function() use ($c) { |
|
899 | 899 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
900 | 900 | }); |
901 | - $manager->registerCapability(function () use ($c) { |
|
901 | + $manager->registerCapability(function() use ($c) { |
|
902 | 902 | return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
903 | 903 | }); |
904 | 904 | return $manager; |
905 | 905 | }); |
906 | 906 | $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
907 | 907 | |
908 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
908 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
909 | 909 | $config = $c->getConfig(); |
910 | 910 | $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
911 | 911 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
@@ -915,7 +915,7 @@ discard block |
||
915 | 915 | $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
916 | 916 | $manager = $c->getUserManager(); |
917 | 917 | $user = $manager->get($id); |
918 | - if(is_null($user)) { |
|
918 | + if (is_null($user)) { |
|
919 | 919 | $l = $c->getL10N('core'); |
920 | 920 | $displayName = $l->t('Unknown user'); |
921 | 921 | } else { |
@@ -928,7 +928,7 @@ discard block |
||
928 | 928 | }); |
929 | 929 | $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
930 | 930 | |
931 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
931 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
932 | 932 | /* |
933 | 933 | * Dark magic for autoloader. |
934 | 934 | * If we do a class_exists it will try to load the class which will |
@@ -955,7 +955,7 @@ discard block |
||
955 | 955 | } |
956 | 956 | return new \OC_Defaults(); |
957 | 957 | }); |
958 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
958 | + $this->registerService(SCSSCacher::class, function(Server $c) { |
|
959 | 959 | /** @var Factory $cacheFactory */ |
960 | 960 | $cacheFactory = $c->query(Factory::class); |
961 | 961 | return new SCSSCacher( |
@@ -968,7 +968,7 @@ discard block |
||
968 | 968 | $cacheFactory->createDistributed('SCSS') |
969 | 969 | ); |
970 | 970 | }); |
971 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
971 | + $this->registerService(JSCombiner::class, function(Server $c) { |
|
972 | 972 | /** @var Factory $cacheFactory */ |
973 | 973 | $cacheFactory = $c->query(Factory::class); |
974 | 974 | return new JSCombiner( |
@@ -979,13 +979,13 @@ discard block |
||
979 | 979 | $c->getLogger() |
980 | 980 | ); |
981 | 981 | }); |
982 | - $this->registerService(EventDispatcher::class, function () { |
|
982 | + $this->registerService(EventDispatcher::class, function() { |
|
983 | 983 | return new EventDispatcher(); |
984 | 984 | }); |
985 | 985 | $this->registerAlias('EventDispatcher', EventDispatcher::class); |
986 | 986 | $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
987 | 987 | |
988 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
988 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
989 | 989 | // FIXME: Instantiiated here due to cyclic dependency |
990 | 990 | $request = new Request( |
991 | 991 | [ |
@@ -1010,7 +1010,7 @@ discard block |
||
1010 | 1010 | $request |
1011 | 1011 | ); |
1012 | 1012 | }); |
1013 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1013 | + $this->registerService('CsrfTokenManager', function(Server $c) { |
|
1014 | 1014 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
1015 | 1015 | |
1016 | 1016 | return new CsrfTokenManager( |
@@ -1018,22 +1018,22 @@ discard block |
||
1018 | 1018 | $c->query(SessionStorage::class) |
1019 | 1019 | ); |
1020 | 1020 | }); |
1021 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1021 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
1022 | 1022 | return new SessionStorage($c->getSession()); |
1023 | 1023 | }); |
1024 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1024 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) { |
|
1025 | 1025 | return new ContentSecurityPolicyManager(); |
1026 | 1026 | }); |
1027 | 1027 | $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
1028 | 1028 | |
1029 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1029 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
1030 | 1030 | return new ContentSecurityPolicyNonceManager( |
1031 | 1031 | $c->getCsrfTokenManager(), |
1032 | 1032 | $c->getRequest() |
1033 | 1033 | ); |
1034 | 1034 | }); |
1035 | 1035 | |
1036 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1036 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
1037 | 1037 | $config = $c->getConfig(); |
1038 | 1038 | $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
1039 | 1039 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -1076,7 +1076,7 @@ discard block |
||
1076 | 1076 | |
1077 | 1077 | $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
1078 | 1078 | |
1079 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1079 | + $this->registerService('SettingsManager', function(Server $c) { |
|
1080 | 1080 | $manager = new \OC\Settings\Manager( |
1081 | 1081 | $c->getLogger(), |
1082 | 1082 | $c->getDatabaseConnection(), |
@@ -1094,24 +1094,24 @@ discard block |
||
1094 | 1094 | ); |
1095 | 1095 | return $manager; |
1096 | 1096 | }); |
1097 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1097 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
1098 | 1098 | return new \OC\Files\AppData\Factory( |
1099 | 1099 | $c->getRootFolder(), |
1100 | 1100 | $c->getSystemConfig() |
1101 | 1101 | ); |
1102 | 1102 | }); |
1103 | 1103 | |
1104 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1105 | - return new LockdownManager(function () use ($c) { |
|
1104 | + $this->registerService('LockdownManager', function(Server $c) { |
|
1105 | + return new LockdownManager(function() use ($c) { |
|
1106 | 1106 | return $c->getSession(); |
1107 | 1107 | }); |
1108 | 1108 | }); |
1109 | 1109 | |
1110 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1110 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) { |
|
1111 | 1111 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
1112 | 1112 | }); |
1113 | 1113 | |
1114 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1114 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
1115 | 1115 | return new CloudIdManager(); |
1116 | 1116 | }); |
1117 | 1117 | |
@@ -1121,18 +1121,18 @@ discard block |
||
1121 | 1121 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
1122 | 1122 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
1123 | 1123 | |
1124 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1124 | + $this->registerService(Defaults::class, function(Server $c) { |
|
1125 | 1125 | return new Defaults( |
1126 | 1126 | $c->getThemingDefaults() |
1127 | 1127 | ); |
1128 | 1128 | }); |
1129 | 1129 | $this->registerAlias('Defaults', \OCP\Defaults::class); |
1130 | 1130 | |
1131 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1131 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
1132 | 1132 | return $c->query(\OCP\IUserSession::class)->getSession(); |
1133 | 1133 | }); |
1134 | 1134 | |
1135 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1135 | + $this->registerService(IShareHelper::class, function(Server $c) { |
|
1136 | 1136 | return new ShareHelper( |
1137 | 1137 | $c->query(\OCP\Share\IManager::class) |
1138 | 1138 | ); |
@@ -1194,11 +1194,11 @@ discard block |
||
1194 | 1194 | // no avatar to remove |
1195 | 1195 | } catch (\Exception $e) { |
1196 | 1196 | // Ignore exceptions |
1197 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1197 | + $logger->info('Could not cleanup avatar of '.$user->getUID()); |
|
1198 | 1198 | } |
1199 | 1199 | }); |
1200 | 1200 | |
1201 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1201 | + $dispatcher->addListener('OCP\IUser::changeUser', function(GenericEvent $e) { |
|
1202 | 1202 | $manager = $this->getAvatarManager(); |
1203 | 1203 | /** @var IUser $user */ |
1204 | 1204 | $user = $e->getSubject(); |
@@ -1349,7 +1349,7 @@ discard block |
||
1349 | 1349 | * @deprecated since 9.2.0 use IAppData |
1350 | 1350 | */ |
1351 | 1351 | public function getAppFolder() { |
1352 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1352 | + $dir = '/'.\OC_App::getCurrentApp(); |
|
1353 | 1353 | $root = $this->getRootFolder(); |
1354 | 1354 | if (!$root->nodeExists($dir)) { |
1355 | 1355 | $folder = $root->newFolder($dir); |
@@ -1933,7 +1933,7 @@ discard block |
||
1933 | 1933 | /** |
1934 | 1934 | * @return \OCP\Collaboration\AutoComplete\IManager |
1935 | 1935 | */ |
1936 | - public function getAutoCompleteManager(){ |
|
1936 | + public function getAutoCompleteManager() { |
|
1937 | 1937 | return $this->query(IManager::class); |
1938 | 1938 | } |
1939 | 1939 |
@@ -150,1843 +150,1843 @@ |
||
150 | 150 | * TODO: hookup all manager classes |
151 | 151 | */ |
152 | 152 | class Server extends ServerContainer implements IServerContainer { |
153 | - /** @var string */ |
|
154 | - private $webRoot; |
|
155 | - |
|
156 | - /** |
|
157 | - * @param string $webRoot |
|
158 | - * @param \OC\Config $config |
|
159 | - */ |
|
160 | - public function __construct($webRoot, \OC\Config $config) { |
|
161 | - parent::__construct(); |
|
162 | - $this->webRoot = $webRoot; |
|
163 | - |
|
164 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
165 | - return $c; |
|
166 | - }); |
|
167 | - |
|
168 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
169 | - $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
170 | - |
|
171 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
172 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
173 | - |
|
174 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
175 | - |
|
176 | - |
|
177 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
178 | - return new PreviewManager( |
|
179 | - $c->getConfig(), |
|
180 | - $c->getRootFolder(), |
|
181 | - $c->getAppDataDir('preview'), |
|
182 | - $c->getEventDispatcher(), |
|
183 | - $c->getSession()->get('user_id') |
|
184 | - ); |
|
185 | - }); |
|
186 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
187 | - |
|
188 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
189 | - return new \OC\Preview\Watcher( |
|
190 | - $c->getAppDataDir('preview') |
|
191 | - ); |
|
192 | - }); |
|
193 | - |
|
194 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
195 | - $view = new View(); |
|
196 | - $util = new Encryption\Util( |
|
197 | - $view, |
|
198 | - $c->getUserManager(), |
|
199 | - $c->getGroupManager(), |
|
200 | - $c->getConfig() |
|
201 | - ); |
|
202 | - return new Encryption\Manager( |
|
203 | - $c->getConfig(), |
|
204 | - $c->getLogger(), |
|
205 | - $c->getL10N('core'), |
|
206 | - new View(), |
|
207 | - $util, |
|
208 | - new ArrayCache() |
|
209 | - ); |
|
210 | - }); |
|
211 | - |
|
212 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
213 | - $util = new Encryption\Util( |
|
214 | - new View(), |
|
215 | - $c->getUserManager(), |
|
216 | - $c->getGroupManager(), |
|
217 | - $c->getConfig() |
|
218 | - ); |
|
219 | - return new Encryption\File( |
|
220 | - $util, |
|
221 | - $c->getRootFolder(), |
|
222 | - $c->getShareManager() |
|
223 | - ); |
|
224 | - }); |
|
225 | - |
|
226 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
227 | - $view = new View(); |
|
228 | - $util = new Encryption\Util( |
|
229 | - $view, |
|
230 | - $c->getUserManager(), |
|
231 | - $c->getGroupManager(), |
|
232 | - $c->getConfig() |
|
233 | - ); |
|
234 | - |
|
235 | - return new Encryption\Keys\Storage($view, $util); |
|
236 | - }); |
|
237 | - $this->registerService('TagMapper', function (Server $c) { |
|
238 | - return new TagMapper($c->getDatabaseConnection()); |
|
239 | - }); |
|
240 | - |
|
241 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
242 | - $tagMapper = $c->query('TagMapper'); |
|
243 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
244 | - }); |
|
245 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
246 | - |
|
247 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
248 | - $config = $c->getConfig(); |
|
249 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
250 | - return new $factoryClass($this); |
|
251 | - }); |
|
252 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
253 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
254 | - }); |
|
255 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
256 | - |
|
257 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
258 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
259 | - }); |
|
260 | - $this->registerService('RootFolder', function (Server $c) { |
|
261 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
262 | - $view = new View(); |
|
263 | - $root = new Root( |
|
264 | - $manager, |
|
265 | - $view, |
|
266 | - null, |
|
267 | - $c->getUserMountCache(), |
|
268 | - $this->getLogger(), |
|
269 | - $this->getUserManager() |
|
270 | - ); |
|
271 | - $connector = new HookConnector($root, $view); |
|
272 | - $connector->viewToNode(); |
|
273 | - |
|
274 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
275 | - $previewConnector->connectWatcher(); |
|
276 | - |
|
277 | - return $root; |
|
278 | - }); |
|
279 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
280 | - |
|
281 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
282 | - return new LazyRoot(function () use ($c) { |
|
283 | - return $c->query('RootFolder'); |
|
284 | - }); |
|
285 | - }); |
|
286 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
287 | - |
|
288 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
289 | - $config = $c->getConfig(); |
|
290 | - return new \OC\User\Manager($config); |
|
291 | - }); |
|
292 | - $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
293 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
294 | - |
|
295 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
296 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
297 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
298 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
299 | - }); |
|
300 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
301 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
302 | - }); |
|
303 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
304 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
305 | - }); |
|
306 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
307 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
308 | - }); |
|
309 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
310 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
311 | - }); |
|
312 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
313 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
314 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
315 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
316 | - }); |
|
317 | - return $groupManager; |
|
318 | - }); |
|
319 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
320 | - |
|
321 | - $this->registerService(Store::class, function (Server $c) { |
|
322 | - $session = $c->getSession(); |
|
323 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
324 | - $tokenProvider = $c->query(IProvider::class); |
|
325 | - } else { |
|
326 | - $tokenProvider = null; |
|
327 | - } |
|
328 | - $logger = $c->getLogger(); |
|
329 | - return new Store($session, $logger, $tokenProvider); |
|
330 | - }); |
|
331 | - $this->registerAlias(IStore::class, Store::class); |
|
332 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
333 | - $dbConnection = $c->getDatabaseConnection(); |
|
334 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
335 | - }); |
|
336 | - $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
|
337 | - $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
|
338 | - $crypto = $c->getCrypto(); |
|
339 | - $config = $c->getConfig(); |
|
340 | - $logger = $c->getLogger(); |
|
341 | - $timeFactory = new TimeFactory(); |
|
342 | - return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
343 | - }); |
|
344 | - $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
|
345 | - |
|
346 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
347 | - $manager = $c->getUserManager(); |
|
348 | - $session = new \OC\Session\Memory(''); |
|
349 | - $timeFactory = new TimeFactory(); |
|
350 | - // Token providers might require a working database. This code |
|
351 | - // might however be called when ownCloud is not yet setup. |
|
352 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
353 | - $defaultTokenProvider = $c->query(IProvider::class); |
|
354 | - } else { |
|
355 | - $defaultTokenProvider = null; |
|
356 | - } |
|
357 | - |
|
358 | - $dispatcher = $c->getEventDispatcher(); |
|
359 | - |
|
360 | - $userSession = new \OC\User\Session( |
|
361 | - $manager, |
|
362 | - $session, |
|
363 | - $timeFactory, |
|
364 | - $defaultTokenProvider, |
|
365 | - $c->getConfig(), |
|
366 | - $c->getSecureRandom(), |
|
367 | - $c->getLockdownManager(), |
|
368 | - $c->getLogger() |
|
369 | - ); |
|
370 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
371 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
372 | - }); |
|
373 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
374 | - /** @var $user \OC\User\User */ |
|
375 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
376 | - }); |
|
377 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
378 | - /** @var $user \OC\User\User */ |
|
379 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
380 | - $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
381 | - }); |
|
382 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
383 | - /** @var $user \OC\User\User */ |
|
384 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
385 | - }); |
|
386 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
387 | - /** @var $user \OC\User\User */ |
|
388 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
389 | - }); |
|
390 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
391 | - /** @var $user \OC\User\User */ |
|
392 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
393 | - }); |
|
394 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
395 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
396 | - }); |
|
397 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
398 | - /** @var $user \OC\User\User */ |
|
399 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
400 | - }); |
|
401 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
402 | - /** @var $user \OC\User\User */ |
|
403 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
404 | - }); |
|
405 | - $userSession->listen('\OC\User', 'logout', function () { |
|
406 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
407 | - }); |
|
408 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
409 | - /** @var $user \OC\User\User */ |
|
410 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
411 | - $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
412 | - }); |
|
413 | - return $userSession; |
|
414 | - }); |
|
415 | - $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
416 | - |
|
417 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
418 | - return new \OC\Authentication\TwoFactorAuth\Manager( |
|
419 | - $c->getAppManager(), |
|
420 | - $c->getSession(), |
|
421 | - $c->getConfig(), |
|
422 | - $c->getActivityManager(), |
|
423 | - $c->getLogger(), |
|
424 | - $c->query(IProvider::class), |
|
425 | - $c->query(ITimeFactory::class), |
|
426 | - $c->query(EventDispatcherInterface::class) |
|
427 | - ); |
|
428 | - }); |
|
429 | - |
|
430 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
431 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
432 | - |
|
433 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
434 | - return new \OC\AllConfig( |
|
435 | - $c->getSystemConfig() |
|
436 | - ); |
|
437 | - }); |
|
438 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
439 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
440 | - |
|
441 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
442 | - return new \OC\SystemConfig($config); |
|
443 | - }); |
|
444 | - |
|
445 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
446 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
447 | - }); |
|
448 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
449 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
450 | - |
|
451 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
452 | - return new \OC\L10N\Factory( |
|
453 | - $c->getConfig(), |
|
454 | - $c->getRequest(), |
|
455 | - $c->getUserSession(), |
|
456 | - \OC::$SERVERROOT |
|
457 | - ); |
|
458 | - }); |
|
459 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
460 | - |
|
461 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
462 | - $config = $c->getConfig(); |
|
463 | - $cacheFactory = $c->getMemCacheFactory(); |
|
464 | - $request = $c->getRequest(); |
|
465 | - return new \OC\URLGenerator( |
|
466 | - $config, |
|
467 | - $cacheFactory, |
|
468 | - $request |
|
469 | - ); |
|
470 | - }); |
|
471 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
472 | - |
|
473 | - $this->registerService('AppHelper', function ($c) { |
|
474 | - return new \OC\AppHelper(); |
|
475 | - }); |
|
476 | - $this->registerAlias('AppFetcher', AppFetcher::class); |
|
477 | - $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
478 | - |
|
479 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
480 | - return new Cache\File(); |
|
481 | - }); |
|
482 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
483 | - |
|
484 | - $this->registerService(Factory::class, function (Server $c) { |
|
485 | - |
|
486 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
487 | - ArrayCache::class, |
|
488 | - ArrayCache::class, |
|
489 | - ArrayCache::class |
|
490 | - ); |
|
491 | - $config = $c->getConfig(); |
|
492 | - $request = $c->getRequest(); |
|
493 | - $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
494 | - |
|
495 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
496 | - $v = \OC_App::getAppVersions(); |
|
497 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
498 | - $version = implode(',', $v); |
|
499 | - $instanceId = \OC_Util::getInstanceId(); |
|
500 | - $path = \OC::$SERVERROOT; |
|
501 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
502 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
503 | - $config->getSystemValue('memcache.local', null), |
|
504 | - $config->getSystemValue('memcache.distributed', null), |
|
505 | - $config->getSystemValue('memcache.locking', null) |
|
506 | - ); |
|
507 | - } |
|
508 | - return $arrayCacheFactory; |
|
509 | - |
|
510 | - }); |
|
511 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
512 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
513 | - |
|
514 | - $this->registerService('RedisFactory', function (Server $c) { |
|
515 | - $systemConfig = $c->getSystemConfig(); |
|
516 | - return new RedisFactory($systemConfig); |
|
517 | - }); |
|
518 | - |
|
519 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
520 | - return new \OC\Activity\Manager( |
|
521 | - $c->getRequest(), |
|
522 | - $c->getUserSession(), |
|
523 | - $c->getConfig(), |
|
524 | - $c->query(IValidator::class) |
|
525 | - ); |
|
526 | - }); |
|
527 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
528 | - |
|
529 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
530 | - return new \OC\Activity\EventMerger( |
|
531 | - $c->getL10N('lib') |
|
532 | - ); |
|
533 | - }); |
|
534 | - $this->registerAlias(IValidator::class, Validator::class); |
|
535 | - |
|
536 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
537 | - return new AvatarManager( |
|
538 | - $c->query(\OC\User\Manager::class), |
|
539 | - $c->getAppDataDir('avatar'), |
|
540 | - $c->getL10N('lib'), |
|
541 | - $c->getLogger(), |
|
542 | - $c->getConfig() |
|
543 | - ); |
|
544 | - }); |
|
545 | - $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
546 | - |
|
547 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
548 | - |
|
549 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
550 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
551 | - $logger = Log::getLogClass($logType); |
|
552 | - call_user_func(array($logger, 'init')); |
|
553 | - $config = $this->getSystemConfig(); |
|
554 | - $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
555 | - |
|
556 | - return new Log($logger, $config, null, $registry); |
|
557 | - }); |
|
558 | - $this->registerAlias('Logger', \OCP\ILogger::class); |
|
559 | - |
|
560 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
561 | - $config = $c->getConfig(); |
|
562 | - return new \OC\BackgroundJob\JobList( |
|
563 | - $c->getDatabaseConnection(), |
|
564 | - $config, |
|
565 | - new TimeFactory() |
|
566 | - ); |
|
567 | - }); |
|
568 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
569 | - |
|
570 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
571 | - $cacheFactory = $c->getMemCacheFactory(); |
|
572 | - $logger = $c->getLogger(); |
|
573 | - if ($cacheFactory->isAvailableLowLatency()) { |
|
574 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
575 | - } else { |
|
576 | - $router = new \OC\Route\Router($logger); |
|
577 | - } |
|
578 | - return $router; |
|
579 | - }); |
|
580 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
581 | - |
|
582 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
583 | - return new Search(); |
|
584 | - }); |
|
585 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
586 | - |
|
587 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
588 | - return new \OC\Security\RateLimiting\Limiter( |
|
589 | - $this->getUserSession(), |
|
590 | - $this->getRequest(), |
|
591 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
592 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
593 | - ); |
|
594 | - }); |
|
595 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
596 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
597 | - $this->getMemCacheFactory(), |
|
598 | - new \OC\AppFramework\Utility\TimeFactory() |
|
599 | - ); |
|
600 | - }); |
|
601 | - |
|
602 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
603 | - return new SecureRandom(); |
|
604 | - }); |
|
605 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
606 | - |
|
607 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
608 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
609 | - }); |
|
610 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
611 | - |
|
612 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
613 | - return new Hasher($c->getConfig()); |
|
614 | - }); |
|
615 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
616 | - |
|
617 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
618 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
619 | - }); |
|
620 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
621 | - |
|
622 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
623 | - $systemConfig = $c->getSystemConfig(); |
|
624 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
625 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
626 | - if (!$factory->isValidType($type)) { |
|
627 | - throw new \OC\DatabaseException('Invalid database type'); |
|
628 | - } |
|
629 | - $connectionParams = $factory->createConnectionParams(); |
|
630 | - $connection = $factory->getConnection($type, $connectionParams); |
|
631 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
632 | - return $connection; |
|
633 | - }); |
|
634 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
635 | - |
|
636 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
637 | - $config = $c->getConfig(); |
|
638 | - return new HTTPHelper( |
|
639 | - $config, |
|
640 | - $c->getHTTPClientService() |
|
641 | - ); |
|
642 | - }); |
|
643 | - |
|
644 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
645 | - $user = \OC_User::getUser(); |
|
646 | - $uid = $user ? $user : null; |
|
647 | - return new ClientService( |
|
648 | - $c->getConfig(), |
|
649 | - new \OC\Security\CertificateManager( |
|
650 | - $uid, |
|
651 | - new View(), |
|
652 | - $c->getConfig(), |
|
653 | - $c->getLogger(), |
|
654 | - $c->getSecureRandom() |
|
655 | - ) |
|
656 | - ); |
|
657 | - }); |
|
658 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
659 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
660 | - $eventLogger = new EventLogger(); |
|
661 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
662 | - // In debug mode, module is being activated by default |
|
663 | - $eventLogger->activate(); |
|
664 | - } |
|
665 | - return $eventLogger; |
|
666 | - }); |
|
667 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
668 | - |
|
669 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
670 | - $queryLogger = new QueryLogger(); |
|
671 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
672 | - // In debug mode, module is being activated by default |
|
673 | - $queryLogger->activate(); |
|
674 | - } |
|
675 | - return $queryLogger; |
|
676 | - }); |
|
677 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
678 | - |
|
679 | - $this->registerService(TempManager::class, function (Server $c) { |
|
680 | - return new TempManager( |
|
681 | - $c->getLogger(), |
|
682 | - $c->getConfig() |
|
683 | - ); |
|
684 | - }); |
|
685 | - $this->registerAlias('TempManager', TempManager::class); |
|
686 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
687 | - |
|
688 | - $this->registerService(AppManager::class, function (Server $c) { |
|
689 | - return new \OC\App\AppManager( |
|
690 | - $c->getUserSession(), |
|
691 | - $c->query(\OC\AppConfig::class), |
|
692 | - $c->getGroupManager(), |
|
693 | - $c->getMemCacheFactory(), |
|
694 | - $c->getEventDispatcher() |
|
695 | - ); |
|
696 | - }); |
|
697 | - $this->registerAlias('AppManager', AppManager::class); |
|
698 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
699 | - |
|
700 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
701 | - return new DateTimeZone( |
|
702 | - $c->getConfig(), |
|
703 | - $c->getSession() |
|
704 | - ); |
|
705 | - }); |
|
706 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
707 | - |
|
708 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
709 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
710 | - |
|
711 | - return new DateTimeFormatter( |
|
712 | - $c->getDateTimeZone()->getTimeZone(), |
|
713 | - $c->getL10N('lib', $language) |
|
714 | - ); |
|
715 | - }); |
|
716 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
717 | - |
|
718 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
719 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
720 | - $listener = new UserMountCacheListener($mountCache); |
|
721 | - $listener->listen($c->getUserManager()); |
|
722 | - return $mountCache; |
|
723 | - }); |
|
724 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
725 | - |
|
726 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
727 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
728 | - $mountCache = $c->query('UserMountCache'); |
|
729 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
730 | - |
|
731 | - // builtin providers |
|
732 | - |
|
733 | - $config = $c->getConfig(); |
|
734 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
735 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
736 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
737 | - |
|
738 | - return $manager; |
|
739 | - }); |
|
740 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
741 | - |
|
742 | - $this->registerService('IniWrapper', function ($c) { |
|
743 | - return new IniGetWrapper(); |
|
744 | - }); |
|
745 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
746 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
747 | - if ($busClass) { |
|
748 | - list($app, $class) = explode('::', $busClass, 2); |
|
749 | - if ($c->getAppManager()->isInstalled($app)) { |
|
750 | - \OC_App::loadApp($app); |
|
751 | - return $c->query($class); |
|
752 | - } else { |
|
753 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
754 | - } |
|
755 | - } else { |
|
756 | - $jobList = $c->getJobList(); |
|
757 | - return new CronBus($jobList); |
|
758 | - } |
|
759 | - }); |
|
760 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
761 | - return new TrustedDomainHelper($this->getConfig()); |
|
762 | - }); |
|
763 | - $this->registerService('Throttler', function (Server $c) { |
|
764 | - return new Throttler( |
|
765 | - $c->getDatabaseConnection(), |
|
766 | - new TimeFactory(), |
|
767 | - $c->getLogger(), |
|
768 | - $c->getConfig() |
|
769 | - ); |
|
770 | - }); |
|
771 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
772 | - // IConfig and IAppManager requires a working database. This code |
|
773 | - // might however be called when ownCloud is not yet setup. |
|
774 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
775 | - $config = $c->getConfig(); |
|
776 | - $appManager = $c->getAppManager(); |
|
777 | - } else { |
|
778 | - $config = null; |
|
779 | - $appManager = null; |
|
780 | - } |
|
781 | - |
|
782 | - return new Checker( |
|
783 | - new EnvironmentHelper(), |
|
784 | - new FileAccessHelper(), |
|
785 | - new AppLocator(), |
|
786 | - $config, |
|
787 | - $c->getMemCacheFactory(), |
|
788 | - $appManager, |
|
789 | - $c->getTempManager() |
|
790 | - ); |
|
791 | - }); |
|
792 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
793 | - if (isset($this['urlParams'])) { |
|
794 | - $urlParams = $this['urlParams']; |
|
795 | - } else { |
|
796 | - $urlParams = []; |
|
797 | - } |
|
798 | - |
|
799 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
800 | - && in_array('fakeinput', stream_get_wrappers()) |
|
801 | - ) { |
|
802 | - $stream = 'fakeinput://data'; |
|
803 | - } else { |
|
804 | - $stream = 'php://input'; |
|
805 | - } |
|
806 | - |
|
807 | - return new Request( |
|
808 | - [ |
|
809 | - 'get' => $_GET, |
|
810 | - 'post' => $_POST, |
|
811 | - 'files' => $_FILES, |
|
812 | - 'server' => $_SERVER, |
|
813 | - 'env' => $_ENV, |
|
814 | - 'cookies' => $_COOKIE, |
|
815 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
816 | - ? $_SERVER['REQUEST_METHOD'] |
|
817 | - : '', |
|
818 | - 'urlParams' => $urlParams, |
|
819 | - ], |
|
820 | - $this->getSecureRandom(), |
|
821 | - $this->getConfig(), |
|
822 | - $this->getCsrfTokenManager(), |
|
823 | - $stream |
|
824 | - ); |
|
825 | - }); |
|
826 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
827 | - |
|
828 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
829 | - return new Mailer( |
|
830 | - $c->getConfig(), |
|
831 | - $c->getLogger(), |
|
832 | - $c->query(Defaults::class), |
|
833 | - $c->getURLGenerator(), |
|
834 | - $c->getL10N('lib') |
|
835 | - ); |
|
836 | - }); |
|
837 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
838 | - |
|
839 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
840 | - $config = $c->getConfig(); |
|
841 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
842 | - if (is_null($factoryClass)) { |
|
843 | - throw new \Exception('ldapProviderFactory not set'); |
|
844 | - } |
|
845 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
846 | - $factory = new $factoryClass($this); |
|
847 | - return $factory->getLDAPProvider(); |
|
848 | - }); |
|
849 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
850 | - $ini = $c->getIniWrapper(); |
|
851 | - $config = $c->getConfig(); |
|
852 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
853 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
854 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
855 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
856 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
857 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
858 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
859 | - } |
|
860 | - return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
861 | - } |
|
862 | - return new NoopLockingProvider(); |
|
863 | - }); |
|
864 | - $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
865 | - |
|
866 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
867 | - return new \OC\Files\Mount\Manager(); |
|
868 | - }); |
|
869 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
870 | - |
|
871 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
872 | - return new \OC\Files\Type\Detection( |
|
873 | - $c->getURLGenerator(), |
|
874 | - \OC::$configDir, |
|
875 | - \OC::$SERVERROOT . '/resources/config/' |
|
876 | - ); |
|
877 | - }); |
|
878 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
879 | - |
|
880 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
881 | - return new \OC\Files\Type\Loader( |
|
882 | - $c->getDatabaseConnection() |
|
883 | - ); |
|
884 | - }); |
|
885 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
886 | - $this->registerService(BundleFetcher::class, function () { |
|
887 | - return new BundleFetcher($this->getL10N('lib')); |
|
888 | - }); |
|
889 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
890 | - return new Manager( |
|
891 | - $c->query(IValidator::class) |
|
892 | - ); |
|
893 | - }); |
|
894 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
895 | - |
|
896 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
897 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
898 | - $manager->registerCapability(function () use ($c) { |
|
899 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
900 | - }); |
|
901 | - $manager->registerCapability(function () use ($c) { |
|
902 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
903 | - }); |
|
904 | - return $manager; |
|
905 | - }); |
|
906 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
907 | - |
|
908 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
909 | - $config = $c->getConfig(); |
|
910 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
911 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
912 | - $factory = new $factoryClass($this); |
|
913 | - $manager = $factory->getManager(); |
|
914 | - |
|
915 | - $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
916 | - $manager = $c->getUserManager(); |
|
917 | - $user = $manager->get($id); |
|
918 | - if(is_null($user)) { |
|
919 | - $l = $c->getL10N('core'); |
|
920 | - $displayName = $l->t('Unknown user'); |
|
921 | - } else { |
|
922 | - $displayName = $user->getDisplayName(); |
|
923 | - } |
|
924 | - return $displayName; |
|
925 | - }); |
|
926 | - |
|
927 | - return $manager; |
|
928 | - }); |
|
929 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
930 | - |
|
931 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
932 | - /* |
|
153 | + /** @var string */ |
|
154 | + private $webRoot; |
|
155 | + |
|
156 | + /** |
|
157 | + * @param string $webRoot |
|
158 | + * @param \OC\Config $config |
|
159 | + */ |
|
160 | + public function __construct($webRoot, \OC\Config $config) { |
|
161 | + parent::__construct(); |
|
162 | + $this->webRoot = $webRoot; |
|
163 | + |
|
164 | + $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
165 | + return $c; |
|
166 | + }); |
|
167 | + |
|
168 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
169 | + $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
170 | + |
|
171 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
172 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
173 | + |
|
174 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
175 | + |
|
176 | + |
|
177 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
178 | + return new PreviewManager( |
|
179 | + $c->getConfig(), |
|
180 | + $c->getRootFolder(), |
|
181 | + $c->getAppDataDir('preview'), |
|
182 | + $c->getEventDispatcher(), |
|
183 | + $c->getSession()->get('user_id') |
|
184 | + ); |
|
185 | + }); |
|
186 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
187 | + |
|
188 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
189 | + return new \OC\Preview\Watcher( |
|
190 | + $c->getAppDataDir('preview') |
|
191 | + ); |
|
192 | + }); |
|
193 | + |
|
194 | + $this->registerService('EncryptionManager', function (Server $c) { |
|
195 | + $view = new View(); |
|
196 | + $util = new Encryption\Util( |
|
197 | + $view, |
|
198 | + $c->getUserManager(), |
|
199 | + $c->getGroupManager(), |
|
200 | + $c->getConfig() |
|
201 | + ); |
|
202 | + return new Encryption\Manager( |
|
203 | + $c->getConfig(), |
|
204 | + $c->getLogger(), |
|
205 | + $c->getL10N('core'), |
|
206 | + new View(), |
|
207 | + $util, |
|
208 | + new ArrayCache() |
|
209 | + ); |
|
210 | + }); |
|
211 | + |
|
212 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
213 | + $util = new Encryption\Util( |
|
214 | + new View(), |
|
215 | + $c->getUserManager(), |
|
216 | + $c->getGroupManager(), |
|
217 | + $c->getConfig() |
|
218 | + ); |
|
219 | + return new Encryption\File( |
|
220 | + $util, |
|
221 | + $c->getRootFolder(), |
|
222 | + $c->getShareManager() |
|
223 | + ); |
|
224 | + }); |
|
225 | + |
|
226 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
227 | + $view = new View(); |
|
228 | + $util = new Encryption\Util( |
|
229 | + $view, |
|
230 | + $c->getUserManager(), |
|
231 | + $c->getGroupManager(), |
|
232 | + $c->getConfig() |
|
233 | + ); |
|
234 | + |
|
235 | + return new Encryption\Keys\Storage($view, $util); |
|
236 | + }); |
|
237 | + $this->registerService('TagMapper', function (Server $c) { |
|
238 | + return new TagMapper($c->getDatabaseConnection()); |
|
239 | + }); |
|
240 | + |
|
241 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
242 | + $tagMapper = $c->query('TagMapper'); |
|
243 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
244 | + }); |
|
245 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
246 | + |
|
247 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
248 | + $config = $c->getConfig(); |
|
249 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
250 | + return new $factoryClass($this); |
|
251 | + }); |
|
252 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
253 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
254 | + }); |
|
255 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
256 | + |
|
257 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
258 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
259 | + }); |
|
260 | + $this->registerService('RootFolder', function (Server $c) { |
|
261 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
262 | + $view = new View(); |
|
263 | + $root = new Root( |
|
264 | + $manager, |
|
265 | + $view, |
|
266 | + null, |
|
267 | + $c->getUserMountCache(), |
|
268 | + $this->getLogger(), |
|
269 | + $this->getUserManager() |
|
270 | + ); |
|
271 | + $connector = new HookConnector($root, $view); |
|
272 | + $connector->viewToNode(); |
|
273 | + |
|
274 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
275 | + $previewConnector->connectWatcher(); |
|
276 | + |
|
277 | + return $root; |
|
278 | + }); |
|
279 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
280 | + |
|
281 | + $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
282 | + return new LazyRoot(function () use ($c) { |
|
283 | + return $c->query('RootFolder'); |
|
284 | + }); |
|
285 | + }); |
|
286 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
287 | + |
|
288 | + $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
289 | + $config = $c->getConfig(); |
|
290 | + return new \OC\User\Manager($config); |
|
291 | + }); |
|
292 | + $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
293 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
294 | + |
|
295 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
296 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
297 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
298 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
299 | + }); |
|
300 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
301 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
302 | + }); |
|
303 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
304 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
305 | + }); |
|
306 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
307 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
308 | + }); |
|
309 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
310 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
311 | + }); |
|
312 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
313 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
314 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
315 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
316 | + }); |
|
317 | + return $groupManager; |
|
318 | + }); |
|
319 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
320 | + |
|
321 | + $this->registerService(Store::class, function (Server $c) { |
|
322 | + $session = $c->getSession(); |
|
323 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
324 | + $tokenProvider = $c->query(IProvider::class); |
|
325 | + } else { |
|
326 | + $tokenProvider = null; |
|
327 | + } |
|
328 | + $logger = $c->getLogger(); |
|
329 | + return new Store($session, $logger, $tokenProvider); |
|
330 | + }); |
|
331 | + $this->registerAlias(IStore::class, Store::class); |
|
332 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
333 | + $dbConnection = $c->getDatabaseConnection(); |
|
334 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
335 | + }); |
|
336 | + $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
|
337 | + $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
|
338 | + $crypto = $c->getCrypto(); |
|
339 | + $config = $c->getConfig(); |
|
340 | + $logger = $c->getLogger(); |
|
341 | + $timeFactory = new TimeFactory(); |
|
342 | + return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
343 | + }); |
|
344 | + $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
|
345 | + |
|
346 | + $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
347 | + $manager = $c->getUserManager(); |
|
348 | + $session = new \OC\Session\Memory(''); |
|
349 | + $timeFactory = new TimeFactory(); |
|
350 | + // Token providers might require a working database. This code |
|
351 | + // might however be called when ownCloud is not yet setup. |
|
352 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
353 | + $defaultTokenProvider = $c->query(IProvider::class); |
|
354 | + } else { |
|
355 | + $defaultTokenProvider = null; |
|
356 | + } |
|
357 | + |
|
358 | + $dispatcher = $c->getEventDispatcher(); |
|
359 | + |
|
360 | + $userSession = new \OC\User\Session( |
|
361 | + $manager, |
|
362 | + $session, |
|
363 | + $timeFactory, |
|
364 | + $defaultTokenProvider, |
|
365 | + $c->getConfig(), |
|
366 | + $c->getSecureRandom(), |
|
367 | + $c->getLockdownManager(), |
|
368 | + $c->getLogger() |
|
369 | + ); |
|
370 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
371 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
372 | + }); |
|
373 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
374 | + /** @var $user \OC\User\User */ |
|
375 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
376 | + }); |
|
377 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
378 | + /** @var $user \OC\User\User */ |
|
379 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
380 | + $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
381 | + }); |
|
382 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
383 | + /** @var $user \OC\User\User */ |
|
384 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
385 | + }); |
|
386 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
387 | + /** @var $user \OC\User\User */ |
|
388 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
389 | + }); |
|
390 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
391 | + /** @var $user \OC\User\User */ |
|
392 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
393 | + }); |
|
394 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
395 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
396 | + }); |
|
397 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
398 | + /** @var $user \OC\User\User */ |
|
399 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
400 | + }); |
|
401 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
402 | + /** @var $user \OC\User\User */ |
|
403 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
404 | + }); |
|
405 | + $userSession->listen('\OC\User', 'logout', function () { |
|
406 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
407 | + }); |
|
408 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
409 | + /** @var $user \OC\User\User */ |
|
410 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
411 | + $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
412 | + }); |
|
413 | + return $userSession; |
|
414 | + }); |
|
415 | + $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
416 | + |
|
417 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
418 | + return new \OC\Authentication\TwoFactorAuth\Manager( |
|
419 | + $c->getAppManager(), |
|
420 | + $c->getSession(), |
|
421 | + $c->getConfig(), |
|
422 | + $c->getActivityManager(), |
|
423 | + $c->getLogger(), |
|
424 | + $c->query(IProvider::class), |
|
425 | + $c->query(ITimeFactory::class), |
|
426 | + $c->query(EventDispatcherInterface::class) |
|
427 | + ); |
|
428 | + }); |
|
429 | + |
|
430 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
431 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
432 | + |
|
433 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
434 | + return new \OC\AllConfig( |
|
435 | + $c->getSystemConfig() |
|
436 | + ); |
|
437 | + }); |
|
438 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
439 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
440 | + |
|
441 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
442 | + return new \OC\SystemConfig($config); |
|
443 | + }); |
|
444 | + |
|
445 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
446 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
447 | + }); |
|
448 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
449 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
450 | + |
|
451 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
452 | + return new \OC\L10N\Factory( |
|
453 | + $c->getConfig(), |
|
454 | + $c->getRequest(), |
|
455 | + $c->getUserSession(), |
|
456 | + \OC::$SERVERROOT |
|
457 | + ); |
|
458 | + }); |
|
459 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
460 | + |
|
461 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
462 | + $config = $c->getConfig(); |
|
463 | + $cacheFactory = $c->getMemCacheFactory(); |
|
464 | + $request = $c->getRequest(); |
|
465 | + return new \OC\URLGenerator( |
|
466 | + $config, |
|
467 | + $cacheFactory, |
|
468 | + $request |
|
469 | + ); |
|
470 | + }); |
|
471 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
472 | + |
|
473 | + $this->registerService('AppHelper', function ($c) { |
|
474 | + return new \OC\AppHelper(); |
|
475 | + }); |
|
476 | + $this->registerAlias('AppFetcher', AppFetcher::class); |
|
477 | + $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
478 | + |
|
479 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
480 | + return new Cache\File(); |
|
481 | + }); |
|
482 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
483 | + |
|
484 | + $this->registerService(Factory::class, function (Server $c) { |
|
485 | + |
|
486 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
487 | + ArrayCache::class, |
|
488 | + ArrayCache::class, |
|
489 | + ArrayCache::class |
|
490 | + ); |
|
491 | + $config = $c->getConfig(); |
|
492 | + $request = $c->getRequest(); |
|
493 | + $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
494 | + |
|
495 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
496 | + $v = \OC_App::getAppVersions(); |
|
497 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
498 | + $version = implode(',', $v); |
|
499 | + $instanceId = \OC_Util::getInstanceId(); |
|
500 | + $path = \OC::$SERVERROOT; |
|
501 | + $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
502 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
503 | + $config->getSystemValue('memcache.local', null), |
|
504 | + $config->getSystemValue('memcache.distributed', null), |
|
505 | + $config->getSystemValue('memcache.locking', null) |
|
506 | + ); |
|
507 | + } |
|
508 | + return $arrayCacheFactory; |
|
509 | + |
|
510 | + }); |
|
511 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
512 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
513 | + |
|
514 | + $this->registerService('RedisFactory', function (Server $c) { |
|
515 | + $systemConfig = $c->getSystemConfig(); |
|
516 | + return new RedisFactory($systemConfig); |
|
517 | + }); |
|
518 | + |
|
519 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
520 | + return new \OC\Activity\Manager( |
|
521 | + $c->getRequest(), |
|
522 | + $c->getUserSession(), |
|
523 | + $c->getConfig(), |
|
524 | + $c->query(IValidator::class) |
|
525 | + ); |
|
526 | + }); |
|
527 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
528 | + |
|
529 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
530 | + return new \OC\Activity\EventMerger( |
|
531 | + $c->getL10N('lib') |
|
532 | + ); |
|
533 | + }); |
|
534 | + $this->registerAlias(IValidator::class, Validator::class); |
|
535 | + |
|
536 | + $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
537 | + return new AvatarManager( |
|
538 | + $c->query(\OC\User\Manager::class), |
|
539 | + $c->getAppDataDir('avatar'), |
|
540 | + $c->getL10N('lib'), |
|
541 | + $c->getLogger(), |
|
542 | + $c->getConfig() |
|
543 | + ); |
|
544 | + }); |
|
545 | + $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
546 | + |
|
547 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
548 | + |
|
549 | + $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
550 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
551 | + $logger = Log::getLogClass($logType); |
|
552 | + call_user_func(array($logger, 'init')); |
|
553 | + $config = $this->getSystemConfig(); |
|
554 | + $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
555 | + |
|
556 | + return new Log($logger, $config, null, $registry); |
|
557 | + }); |
|
558 | + $this->registerAlias('Logger', \OCP\ILogger::class); |
|
559 | + |
|
560 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
561 | + $config = $c->getConfig(); |
|
562 | + return new \OC\BackgroundJob\JobList( |
|
563 | + $c->getDatabaseConnection(), |
|
564 | + $config, |
|
565 | + new TimeFactory() |
|
566 | + ); |
|
567 | + }); |
|
568 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
569 | + |
|
570 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
571 | + $cacheFactory = $c->getMemCacheFactory(); |
|
572 | + $logger = $c->getLogger(); |
|
573 | + if ($cacheFactory->isAvailableLowLatency()) { |
|
574 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
575 | + } else { |
|
576 | + $router = new \OC\Route\Router($logger); |
|
577 | + } |
|
578 | + return $router; |
|
579 | + }); |
|
580 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
581 | + |
|
582 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
583 | + return new Search(); |
|
584 | + }); |
|
585 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
586 | + |
|
587 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
588 | + return new \OC\Security\RateLimiting\Limiter( |
|
589 | + $this->getUserSession(), |
|
590 | + $this->getRequest(), |
|
591 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
592 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
593 | + ); |
|
594 | + }); |
|
595 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
596 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
597 | + $this->getMemCacheFactory(), |
|
598 | + new \OC\AppFramework\Utility\TimeFactory() |
|
599 | + ); |
|
600 | + }); |
|
601 | + |
|
602 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
603 | + return new SecureRandom(); |
|
604 | + }); |
|
605 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
606 | + |
|
607 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
608 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
609 | + }); |
|
610 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
611 | + |
|
612 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
613 | + return new Hasher($c->getConfig()); |
|
614 | + }); |
|
615 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
616 | + |
|
617 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
618 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
619 | + }); |
|
620 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
621 | + |
|
622 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
623 | + $systemConfig = $c->getSystemConfig(); |
|
624 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
625 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
626 | + if (!$factory->isValidType($type)) { |
|
627 | + throw new \OC\DatabaseException('Invalid database type'); |
|
628 | + } |
|
629 | + $connectionParams = $factory->createConnectionParams(); |
|
630 | + $connection = $factory->getConnection($type, $connectionParams); |
|
631 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
632 | + return $connection; |
|
633 | + }); |
|
634 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
635 | + |
|
636 | + $this->registerService('HTTPHelper', function (Server $c) { |
|
637 | + $config = $c->getConfig(); |
|
638 | + return new HTTPHelper( |
|
639 | + $config, |
|
640 | + $c->getHTTPClientService() |
|
641 | + ); |
|
642 | + }); |
|
643 | + |
|
644 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
645 | + $user = \OC_User::getUser(); |
|
646 | + $uid = $user ? $user : null; |
|
647 | + return new ClientService( |
|
648 | + $c->getConfig(), |
|
649 | + new \OC\Security\CertificateManager( |
|
650 | + $uid, |
|
651 | + new View(), |
|
652 | + $c->getConfig(), |
|
653 | + $c->getLogger(), |
|
654 | + $c->getSecureRandom() |
|
655 | + ) |
|
656 | + ); |
|
657 | + }); |
|
658 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
659 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
660 | + $eventLogger = new EventLogger(); |
|
661 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
662 | + // In debug mode, module is being activated by default |
|
663 | + $eventLogger->activate(); |
|
664 | + } |
|
665 | + return $eventLogger; |
|
666 | + }); |
|
667 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
668 | + |
|
669 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
670 | + $queryLogger = new QueryLogger(); |
|
671 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
672 | + // In debug mode, module is being activated by default |
|
673 | + $queryLogger->activate(); |
|
674 | + } |
|
675 | + return $queryLogger; |
|
676 | + }); |
|
677 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
678 | + |
|
679 | + $this->registerService(TempManager::class, function (Server $c) { |
|
680 | + return new TempManager( |
|
681 | + $c->getLogger(), |
|
682 | + $c->getConfig() |
|
683 | + ); |
|
684 | + }); |
|
685 | + $this->registerAlias('TempManager', TempManager::class); |
|
686 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
687 | + |
|
688 | + $this->registerService(AppManager::class, function (Server $c) { |
|
689 | + return new \OC\App\AppManager( |
|
690 | + $c->getUserSession(), |
|
691 | + $c->query(\OC\AppConfig::class), |
|
692 | + $c->getGroupManager(), |
|
693 | + $c->getMemCacheFactory(), |
|
694 | + $c->getEventDispatcher() |
|
695 | + ); |
|
696 | + }); |
|
697 | + $this->registerAlias('AppManager', AppManager::class); |
|
698 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
699 | + |
|
700 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
701 | + return new DateTimeZone( |
|
702 | + $c->getConfig(), |
|
703 | + $c->getSession() |
|
704 | + ); |
|
705 | + }); |
|
706 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
707 | + |
|
708 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
709 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
710 | + |
|
711 | + return new DateTimeFormatter( |
|
712 | + $c->getDateTimeZone()->getTimeZone(), |
|
713 | + $c->getL10N('lib', $language) |
|
714 | + ); |
|
715 | + }); |
|
716 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
717 | + |
|
718 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
719 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
720 | + $listener = new UserMountCacheListener($mountCache); |
|
721 | + $listener->listen($c->getUserManager()); |
|
722 | + return $mountCache; |
|
723 | + }); |
|
724 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
725 | + |
|
726 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
727 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
728 | + $mountCache = $c->query('UserMountCache'); |
|
729 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
730 | + |
|
731 | + // builtin providers |
|
732 | + |
|
733 | + $config = $c->getConfig(); |
|
734 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
735 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
736 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
737 | + |
|
738 | + return $manager; |
|
739 | + }); |
|
740 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
741 | + |
|
742 | + $this->registerService('IniWrapper', function ($c) { |
|
743 | + return new IniGetWrapper(); |
|
744 | + }); |
|
745 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
746 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
747 | + if ($busClass) { |
|
748 | + list($app, $class) = explode('::', $busClass, 2); |
|
749 | + if ($c->getAppManager()->isInstalled($app)) { |
|
750 | + \OC_App::loadApp($app); |
|
751 | + return $c->query($class); |
|
752 | + } else { |
|
753 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
754 | + } |
|
755 | + } else { |
|
756 | + $jobList = $c->getJobList(); |
|
757 | + return new CronBus($jobList); |
|
758 | + } |
|
759 | + }); |
|
760 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
761 | + return new TrustedDomainHelper($this->getConfig()); |
|
762 | + }); |
|
763 | + $this->registerService('Throttler', function (Server $c) { |
|
764 | + return new Throttler( |
|
765 | + $c->getDatabaseConnection(), |
|
766 | + new TimeFactory(), |
|
767 | + $c->getLogger(), |
|
768 | + $c->getConfig() |
|
769 | + ); |
|
770 | + }); |
|
771 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
772 | + // IConfig and IAppManager requires a working database. This code |
|
773 | + // might however be called when ownCloud is not yet setup. |
|
774 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
775 | + $config = $c->getConfig(); |
|
776 | + $appManager = $c->getAppManager(); |
|
777 | + } else { |
|
778 | + $config = null; |
|
779 | + $appManager = null; |
|
780 | + } |
|
781 | + |
|
782 | + return new Checker( |
|
783 | + new EnvironmentHelper(), |
|
784 | + new FileAccessHelper(), |
|
785 | + new AppLocator(), |
|
786 | + $config, |
|
787 | + $c->getMemCacheFactory(), |
|
788 | + $appManager, |
|
789 | + $c->getTempManager() |
|
790 | + ); |
|
791 | + }); |
|
792 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
793 | + if (isset($this['urlParams'])) { |
|
794 | + $urlParams = $this['urlParams']; |
|
795 | + } else { |
|
796 | + $urlParams = []; |
|
797 | + } |
|
798 | + |
|
799 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
800 | + && in_array('fakeinput', stream_get_wrappers()) |
|
801 | + ) { |
|
802 | + $stream = 'fakeinput://data'; |
|
803 | + } else { |
|
804 | + $stream = 'php://input'; |
|
805 | + } |
|
806 | + |
|
807 | + return new Request( |
|
808 | + [ |
|
809 | + 'get' => $_GET, |
|
810 | + 'post' => $_POST, |
|
811 | + 'files' => $_FILES, |
|
812 | + 'server' => $_SERVER, |
|
813 | + 'env' => $_ENV, |
|
814 | + 'cookies' => $_COOKIE, |
|
815 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
816 | + ? $_SERVER['REQUEST_METHOD'] |
|
817 | + : '', |
|
818 | + 'urlParams' => $urlParams, |
|
819 | + ], |
|
820 | + $this->getSecureRandom(), |
|
821 | + $this->getConfig(), |
|
822 | + $this->getCsrfTokenManager(), |
|
823 | + $stream |
|
824 | + ); |
|
825 | + }); |
|
826 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
827 | + |
|
828 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
829 | + return new Mailer( |
|
830 | + $c->getConfig(), |
|
831 | + $c->getLogger(), |
|
832 | + $c->query(Defaults::class), |
|
833 | + $c->getURLGenerator(), |
|
834 | + $c->getL10N('lib') |
|
835 | + ); |
|
836 | + }); |
|
837 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
838 | + |
|
839 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
840 | + $config = $c->getConfig(); |
|
841 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
842 | + if (is_null($factoryClass)) { |
|
843 | + throw new \Exception('ldapProviderFactory not set'); |
|
844 | + } |
|
845 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
846 | + $factory = new $factoryClass($this); |
|
847 | + return $factory->getLDAPProvider(); |
|
848 | + }); |
|
849 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
850 | + $ini = $c->getIniWrapper(); |
|
851 | + $config = $c->getConfig(); |
|
852 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
853 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
854 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
855 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
856 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
857 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
858 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
859 | + } |
|
860 | + return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
861 | + } |
|
862 | + return new NoopLockingProvider(); |
|
863 | + }); |
|
864 | + $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
865 | + |
|
866 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
867 | + return new \OC\Files\Mount\Manager(); |
|
868 | + }); |
|
869 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
870 | + |
|
871 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
872 | + return new \OC\Files\Type\Detection( |
|
873 | + $c->getURLGenerator(), |
|
874 | + \OC::$configDir, |
|
875 | + \OC::$SERVERROOT . '/resources/config/' |
|
876 | + ); |
|
877 | + }); |
|
878 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
879 | + |
|
880 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
881 | + return new \OC\Files\Type\Loader( |
|
882 | + $c->getDatabaseConnection() |
|
883 | + ); |
|
884 | + }); |
|
885 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
886 | + $this->registerService(BundleFetcher::class, function () { |
|
887 | + return new BundleFetcher($this->getL10N('lib')); |
|
888 | + }); |
|
889 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
890 | + return new Manager( |
|
891 | + $c->query(IValidator::class) |
|
892 | + ); |
|
893 | + }); |
|
894 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
895 | + |
|
896 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
897 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
898 | + $manager->registerCapability(function () use ($c) { |
|
899 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
900 | + }); |
|
901 | + $manager->registerCapability(function () use ($c) { |
|
902 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
903 | + }); |
|
904 | + return $manager; |
|
905 | + }); |
|
906 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
907 | + |
|
908 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
909 | + $config = $c->getConfig(); |
|
910 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
911 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
912 | + $factory = new $factoryClass($this); |
|
913 | + $manager = $factory->getManager(); |
|
914 | + |
|
915 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
916 | + $manager = $c->getUserManager(); |
|
917 | + $user = $manager->get($id); |
|
918 | + if(is_null($user)) { |
|
919 | + $l = $c->getL10N('core'); |
|
920 | + $displayName = $l->t('Unknown user'); |
|
921 | + } else { |
|
922 | + $displayName = $user->getDisplayName(); |
|
923 | + } |
|
924 | + return $displayName; |
|
925 | + }); |
|
926 | + |
|
927 | + return $manager; |
|
928 | + }); |
|
929 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
930 | + |
|
931 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
932 | + /* |
|
933 | 933 | * Dark magic for autoloader. |
934 | 934 | * If we do a class_exists it will try to load the class which will |
935 | 935 | * make composer cache the result. Resulting in errors when enabling |
936 | 936 | * the theming app. |
937 | 937 | */ |
938 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
939 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
940 | - $classExists = true; |
|
941 | - } else { |
|
942 | - $classExists = false; |
|
943 | - } |
|
944 | - |
|
945 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
946 | - return new ThemingDefaults( |
|
947 | - $c->getConfig(), |
|
948 | - $c->getL10N('theming'), |
|
949 | - $c->getURLGenerator(), |
|
950 | - $c->getAppDataDir('theming'), |
|
951 | - $c->getMemCacheFactory(), |
|
952 | - new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')), |
|
953 | - $this->getAppManager() |
|
954 | - ); |
|
955 | - } |
|
956 | - return new \OC_Defaults(); |
|
957 | - }); |
|
958 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
959 | - /** @var Factory $cacheFactory */ |
|
960 | - $cacheFactory = $c->query(Factory::class); |
|
961 | - return new SCSSCacher( |
|
962 | - $c->getLogger(), |
|
963 | - $c->query(\OC\Files\AppData\Factory::class), |
|
964 | - $c->getURLGenerator(), |
|
965 | - $c->getConfig(), |
|
966 | - $c->getThemingDefaults(), |
|
967 | - \OC::$SERVERROOT, |
|
968 | - $cacheFactory->createDistributed('SCSS') |
|
969 | - ); |
|
970 | - }); |
|
971 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
972 | - /** @var Factory $cacheFactory */ |
|
973 | - $cacheFactory = $c->query(Factory::class); |
|
974 | - return new JSCombiner( |
|
975 | - $c->getAppDataDir('js'), |
|
976 | - $c->getURLGenerator(), |
|
977 | - $cacheFactory->createDistributed('JS'), |
|
978 | - $c->getSystemConfig(), |
|
979 | - $c->getLogger() |
|
980 | - ); |
|
981 | - }); |
|
982 | - $this->registerService(EventDispatcher::class, function () { |
|
983 | - return new EventDispatcher(); |
|
984 | - }); |
|
985 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
986 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
987 | - |
|
988 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
989 | - // FIXME: Instantiiated here due to cyclic dependency |
|
990 | - $request = new Request( |
|
991 | - [ |
|
992 | - 'get' => $_GET, |
|
993 | - 'post' => $_POST, |
|
994 | - 'files' => $_FILES, |
|
995 | - 'server' => $_SERVER, |
|
996 | - 'env' => $_ENV, |
|
997 | - 'cookies' => $_COOKIE, |
|
998 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
999 | - ? $_SERVER['REQUEST_METHOD'] |
|
1000 | - : null, |
|
1001 | - ], |
|
1002 | - $c->getSecureRandom(), |
|
1003 | - $c->getConfig() |
|
1004 | - ); |
|
1005 | - |
|
1006 | - return new CryptoWrapper( |
|
1007 | - $c->getConfig(), |
|
1008 | - $c->getCrypto(), |
|
1009 | - $c->getSecureRandom(), |
|
1010 | - $request |
|
1011 | - ); |
|
1012 | - }); |
|
1013 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1014 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1015 | - |
|
1016 | - return new CsrfTokenManager( |
|
1017 | - $tokenGenerator, |
|
1018 | - $c->query(SessionStorage::class) |
|
1019 | - ); |
|
1020 | - }); |
|
1021 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1022 | - return new SessionStorage($c->getSession()); |
|
1023 | - }); |
|
1024 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1025 | - return new ContentSecurityPolicyManager(); |
|
1026 | - }); |
|
1027 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
1028 | - |
|
1029 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1030 | - return new ContentSecurityPolicyNonceManager( |
|
1031 | - $c->getCsrfTokenManager(), |
|
1032 | - $c->getRequest() |
|
1033 | - ); |
|
1034 | - }); |
|
1035 | - |
|
1036 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1037 | - $config = $c->getConfig(); |
|
1038 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1039 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
1040 | - $factory = new $factoryClass($this); |
|
1041 | - |
|
1042 | - $manager = new \OC\Share20\Manager( |
|
1043 | - $c->getLogger(), |
|
1044 | - $c->getConfig(), |
|
1045 | - $c->getSecureRandom(), |
|
1046 | - $c->getHasher(), |
|
1047 | - $c->getMountManager(), |
|
1048 | - $c->getGroupManager(), |
|
1049 | - $c->getL10N('lib'), |
|
1050 | - $c->getL10NFactory(), |
|
1051 | - $factory, |
|
1052 | - $c->getUserManager(), |
|
1053 | - $c->getLazyRootFolder(), |
|
1054 | - $c->getEventDispatcher(), |
|
1055 | - $c->getMailer(), |
|
1056 | - $c->getURLGenerator(), |
|
1057 | - $c->getThemingDefaults() |
|
1058 | - ); |
|
1059 | - |
|
1060 | - return $manager; |
|
1061 | - }); |
|
1062 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1063 | - |
|
1064 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1065 | - $instance = new Collaboration\Collaborators\Search($c); |
|
1066 | - |
|
1067 | - // register default plugins |
|
1068 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1069 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1070 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1071 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1072 | - |
|
1073 | - return $instance; |
|
1074 | - }); |
|
1075 | - $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1076 | - |
|
1077 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1078 | - |
|
1079 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1080 | - $manager = new \OC\Settings\Manager( |
|
1081 | - $c->getLogger(), |
|
1082 | - $c->getDatabaseConnection(), |
|
1083 | - $c->getL10N('lib'), |
|
1084 | - $c->getConfig(), |
|
1085 | - $c->getEncryptionManager(), |
|
1086 | - $c->getUserManager(), |
|
1087 | - $c->getLockingProvider(), |
|
1088 | - $c->getRequest(), |
|
1089 | - $c->getURLGenerator(), |
|
1090 | - $c->query(AccountManager::class), |
|
1091 | - $c->getGroupManager(), |
|
1092 | - $c->getL10NFactory(), |
|
1093 | - $c->getAppManager() |
|
1094 | - ); |
|
1095 | - return $manager; |
|
1096 | - }); |
|
1097 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1098 | - return new \OC\Files\AppData\Factory( |
|
1099 | - $c->getRootFolder(), |
|
1100 | - $c->getSystemConfig() |
|
1101 | - ); |
|
1102 | - }); |
|
1103 | - |
|
1104 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1105 | - return new LockdownManager(function () use ($c) { |
|
1106 | - return $c->getSession(); |
|
1107 | - }); |
|
1108 | - }); |
|
1109 | - |
|
1110 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1111 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1112 | - }); |
|
1113 | - |
|
1114 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1115 | - return new CloudIdManager(); |
|
1116 | - }); |
|
1117 | - |
|
1118 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1119 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1120 | - |
|
1121 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1122 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1123 | - |
|
1124 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1125 | - return new Defaults( |
|
1126 | - $c->getThemingDefaults() |
|
1127 | - ); |
|
1128 | - }); |
|
1129 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1130 | - |
|
1131 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1132 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1133 | - }); |
|
1134 | - |
|
1135 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1136 | - return new ShareHelper( |
|
1137 | - $c->query(\OCP\Share\IManager::class) |
|
1138 | - ); |
|
1139 | - }); |
|
1140 | - |
|
1141 | - $this->registerService(Installer::class, function(Server $c) { |
|
1142 | - return new Installer( |
|
1143 | - $c->getAppFetcher(), |
|
1144 | - $c->getHTTPClientService(), |
|
1145 | - $c->getTempManager(), |
|
1146 | - $c->getLogger(), |
|
1147 | - $c->getConfig() |
|
1148 | - ); |
|
1149 | - }); |
|
1150 | - |
|
1151 | - $this->registerService(IApiFactory::class, function(Server $c) { |
|
1152 | - return new ApiFactory($c->getHTTPClientService()); |
|
1153 | - }); |
|
1154 | - |
|
1155 | - $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1156 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
1157 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1158 | - }); |
|
1159 | - |
|
1160 | - $this->registerService(IContactsStore::class, function(Server $c) { |
|
1161 | - return new ContactsStore( |
|
1162 | - $c->getContactsManager(), |
|
1163 | - $c->getConfig(), |
|
1164 | - $c->getUserManager(), |
|
1165 | - $c->getGroupManager() |
|
1166 | - ); |
|
1167 | - }); |
|
1168 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1169 | - |
|
1170 | - $this->connectDispatcher(); |
|
1171 | - } |
|
1172 | - |
|
1173 | - /** |
|
1174 | - * @return \OCP\Calendar\IManager |
|
1175 | - */ |
|
1176 | - public function getCalendarManager() { |
|
1177 | - return $this->query('CalendarManager'); |
|
1178 | - } |
|
1179 | - |
|
1180 | - private function connectDispatcher() { |
|
1181 | - $dispatcher = $this->getEventDispatcher(); |
|
1182 | - |
|
1183 | - // Delete avatar on user deletion |
|
1184 | - $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1185 | - $logger = $this->getLogger(); |
|
1186 | - $manager = $this->getAvatarManager(); |
|
1187 | - /** @var IUser $user */ |
|
1188 | - $user = $e->getSubject(); |
|
1189 | - |
|
1190 | - try { |
|
1191 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1192 | - $avatar->remove(); |
|
1193 | - } catch (NotFoundException $e) { |
|
1194 | - // no avatar to remove |
|
1195 | - } catch (\Exception $e) { |
|
1196 | - // Ignore exceptions |
|
1197 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1198 | - } |
|
1199 | - }); |
|
1200 | - |
|
1201 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1202 | - $manager = $this->getAvatarManager(); |
|
1203 | - /** @var IUser $user */ |
|
1204 | - $user = $e->getSubject(); |
|
1205 | - $feature = $e->getArgument('feature'); |
|
1206 | - $oldValue = $e->getArgument('oldValue'); |
|
1207 | - $value = $e->getArgument('value'); |
|
1208 | - |
|
1209 | - try { |
|
1210 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1211 | - $avatar->userChanged($feature, $oldValue, $value); |
|
1212 | - } catch (NotFoundException $e) { |
|
1213 | - // no avatar to remove |
|
1214 | - } |
|
1215 | - }); |
|
1216 | - } |
|
1217 | - |
|
1218 | - /** |
|
1219 | - * @return \OCP\Contacts\IManager |
|
1220 | - */ |
|
1221 | - public function getContactsManager() { |
|
1222 | - return $this->query('ContactsManager'); |
|
1223 | - } |
|
1224 | - |
|
1225 | - /** |
|
1226 | - * @return \OC\Encryption\Manager |
|
1227 | - */ |
|
1228 | - public function getEncryptionManager() { |
|
1229 | - return $this->query('EncryptionManager'); |
|
1230 | - } |
|
1231 | - |
|
1232 | - /** |
|
1233 | - * @return \OC\Encryption\File |
|
1234 | - */ |
|
1235 | - public function getEncryptionFilesHelper() { |
|
1236 | - return $this->query('EncryptionFileHelper'); |
|
1237 | - } |
|
1238 | - |
|
1239 | - /** |
|
1240 | - * @return \OCP\Encryption\Keys\IStorage |
|
1241 | - */ |
|
1242 | - public function getEncryptionKeyStorage() { |
|
1243 | - return $this->query('EncryptionKeyStorage'); |
|
1244 | - } |
|
1245 | - |
|
1246 | - /** |
|
1247 | - * The current request object holding all information about the request |
|
1248 | - * currently being processed is returned from this method. |
|
1249 | - * In case the current execution was not initiated by a web request null is returned |
|
1250 | - * |
|
1251 | - * @return \OCP\IRequest |
|
1252 | - */ |
|
1253 | - public function getRequest() { |
|
1254 | - return $this->query('Request'); |
|
1255 | - } |
|
1256 | - |
|
1257 | - /** |
|
1258 | - * Returns the preview manager which can create preview images for a given file |
|
1259 | - * |
|
1260 | - * @return \OCP\IPreview |
|
1261 | - */ |
|
1262 | - public function getPreviewManager() { |
|
1263 | - return $this->query('PreviewManager'); |
|
1264 | - } |
|
1265 | - |
|
1266 | - /** |
|
1267 | - * Returns the tag manager which can get and set tags for different object types |
|
1268 | - * |
|
1269 | - * @see \OCP\ITagManager::load() |
|
1270 | - * @return \OCP\ITagManager |
|
1271 | - */ |
|
1272 | - public function getTagManager() { |
|
1273 | - return $this->query('TagManager'); |
|
1274 | - } |
|
1275 | - |
|
1276 | - /** |
|
1277 | - * Returns the system-tag manager |
|
1278 | - * |
|
1279 | - * @return \OCP\SystemTag\ISystemTagManager |
|
1280 | - * |
|
1281 | - * @since 9.0.0 |
|
1282 | - */ |
|
1283 | - public function getSystemTagManager() { |
|
1284 | - return $this->query('SystemTagManager'); |
|
1285 | - } |
|
1286 | - |
|
1287 | - /** |
|
1288 | - * Returns the system-tag object mapper |
|
1289 | - * |
|
1290 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1291 | - * |
|
1292 | - * @since 9.0.0 |
|
1293 | - */ |
|
1294 | - public function getSystemTagObjectMapper() { |
|
1295 | - return $this->query('SystemTagObjectMapper'); |
|
1296 | - } |
|
1297 | - |
|
1298 | - /** |
|
1299 | - * Returns the avatar manager, used for avatar functionality |
|
1300 | - * |
|
1301 | - * @return \OCP\IAvatarManager |
|
1302 | - */ |
|
1303 | - public function getAvatarManager() { |
|
1304 | - return $this->query('AvatarManager'); |
|
1305 | - } |
|
1306 | - |
|
1307 | - /** |
|
1308 | - * Returns the root folder of ownCloud's data directory |
|
1309 | - * |
|
1310 | - * @return \OCP\Files\IRootFolder |
|
1311 | - */ |
|
1312 | - public function getRootFolder() { |
|
1313 | - return $this->query('LazyRootFolder'); |
|
1314 | - } |
|
1315 | - |
|
1316 | - /** |
|
1317 | - * Returns the root folder of ownCloud's data directory |
|
1318 | - * This is the lazy variant so this gets only initialized once it |
|
1319 | - * is actually used. |
|
1320 | - * |
|
1321 | - * @return \OCP\Files\IRootFolder |
|
1322 | - */ |
|
1323 | - public function getLazyRootFolder() { |
|
1324 | - return $this->query('LazyRootFolder'); |
|
1325 | - } |
|
1326 | - |
|
1327 | - /** |
|
1328 | - * Returns a view to ownCloud's files folder |
|
1329 | - * |
|
1330 | - * @param string $userId user ID |
|
1331 | - * @return \OCP\Files\Folder|null |
|
1332 | - */ |
|
1333 | - public function getUserFolder($userId = null) { |
|
1334 | - if ($userId === null) { |
|
1335 | - $user = $this->getUserSession()->getUser(); |
|
1336 | - if (!$user) { |
|
1337 | - return null; |
|
1338 | - } |
|
1339 | - $userId = $user->getUID(); |
|
1340 | - } |
|
1341 | - $root = $this->getRootFolder(); |
|
1342 | - return $root->getUserFolder($userId); |
|
1343 | - } |
|
1344 | - |
|
1345 | - /** |
|
1346 | - * Returns an app-specific view in ownClouds data directory |
|
1347 | - * |
|
1348 | - * @return \OCP\Files\Folder |
|
1349 | - * @deprecated since 9.2.0 use IAppData |
|
1350 | - */ |
|
1351 | - public function getAppFolder() { |
|
1352 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1353 | - $root = $this->getRootFolder(); |
|
1354 | - if (!$root->nodeExists($dir)) { |
|
1355 | - $folder = $root->newFolder($dir); |
|
1356 | - } else { |
|
1357 | - $folder = $root->get($dir); |
|
1358 | - } |
|
1359 | - return $folder; |
|
1360 | - } |
|
1361 | - |
|
1362 | - /** |
|
1363 | - * @return \OC\User\Manager |
|
1364 | - */ |
|
1365 | - public function getUserManager() { |
|
1366 | - return $this->query('UserManager'); |
|
1367 | - } |
|
1368 | - |
|
1369 | - /** |
|
1370 | - * @return \OC\Group\Manager |
|
1371 | - */ |
|
1372 | - public function getGroupManager() { |
|
1373 | - return $this->query('GroupManager'); |
|
1374 | - } |
|
1375 | - |
|
1376 | - /** |
|
1377 | - * @return \OC\User\Session |
|
1378 | - */ |
|
1379 | - public function getUserSession() { |
|
1380 | - return $this->query('UserSession'); |
|
1381 | - } |
|
1382 | - |
|
1383 | - /** |
|
1384 | - * @return \OCP\ISession |
|
1385 | - */ |
|
1386 | - public function getSession() { |
|
1387 | - return $this->query('UserSession')->getSession(); |
|
1388 | - } |
|
1389 | - |
|
1390 | - /** |
|
1391 | - * @param \OCP\ISession $session |
|
1392 | - */ |
|
1393 | - public function setSession(\OCP\ISession $session) { |
|
1394 | - $this->query(SessionStorage::class)->setSession($session); |
|
1395 | - $this->query('UserSession')->setSession($session); |
|
1396 | - $this->query(Store::class)->setSession($session); |
|
1397 | - } |
|
1398 | - |
|
1399 | - /** |
|
1400 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1401 | - */ |
|
1402 | - public function getTwoFactorAuthManager() { |
|
1403 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1404 | - } |
|
1405 | - |
|
1406 | - /** |
|
1407 | - * @return \OC\NavigationManager |
|
1408 | - */ |
|
1409 | - public function getNavigationManager() { |
|
1410 | - return $this->query('NavigationManager'); |
|
1411 | - } |
|
1412 | - |
|
1413 | - /** |
|
1414 | - * @return \OCP\IConfig |
|
1415 | - */ |
|
1416 | - public function getConfig() { |
|
1417 | - return $this->query('AllConfig'); |
|
1418 | - } |
|
1419 | - |
|
1420 | - /** |
|
1421 | - * @return \OC\SystemConfig |
|
1422 | - */ |
|
1423 | - public function getSystemConfig() { |
|
1424 | - return $this->query('SystemConfig'); |
|
1425 | - } |
|
1426 | - |
|
1427 | - /** |
|
1428 | - * Returns the app config manager |
|
1429 | - * |
|
1430 | - * @return \OCP\IAppConfig |
|
1431 | - */ |
|
1432 | - public function getAppConfig() { |
|
1433 | - return $this->query('AppConfig'); |
|
1434 | - } |
|
1435 | - |
|
1436 | - /** |
|
1437 | - * @return \OCP\L10N\IFactory |
|
1438 | - */ |
|
1439 | - public function getL10NFactory() { |
|
1440 | - return $this->query('L10NFactory'); |
|
1441 | - } |
|
1442 | - |
|
1443 | - /** |
|
1444 | - * get an L10N instance |
|
1445 | - * |
|
1446 | - * @param string $app appid |
|
1447 | - * @param string $lang |
|
1448 | - * @return IL10N |
|
1449 | - */ |
|
1450 | - public function getL10N($app, $lang = null) { |
|
1451 | - return $this->getL10NFactory()->get($app, $lang); |
|
1452 | - } |
|
1453 | - |
|
1454 | - /** |
|
1455 | - * @return \OCP\IURLGenerator |
|
1456 | - */ |
|
1457 | - public function getURLGenerator() { |
|
1458 | - return $this->query('URLGenerator'); |
|
1459 | - } |
|
1460 | - |
|
1461 | - /** |
|
1462 | - * @return \OCP\IHelper |
|
1463 | - */ |
|
1464 | - public function getHelper() { |
|
1465 | - return $this->query('AppHelper'); |
|
1466 | - } |
|
1467 | - |
|
1468 | - /** |
|
1469 | - * @return AppFetcher |
|
1470 | - */ |
|
1471 | - public function getAppFetcher() { |
|
1472 | - return $this->query(AppFetcher::class); |
|
1473 | - } |
|
1474 | - |
|
1475 | - /** |
|
1476 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1477 | - * getMemCacheFactory() instead. |
|
1478 | - * |
|
1479 | - * @return \OCP\ICache |
|
1480 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1481 | - */ |
|
1482 | - public function getCache() { |
|
1483 | - return $this->query('UserCache'); |
|
1484 | - } |
|
1485 | - |
|
1486 | - /** |
|
1487 | - * Returns an \OCP\CacheFactory instance |
|
1488 | - * |
|
1489 | - * @return \OCP\ICacheFactory |
|
1490 | - */ |
|
1491 | - public function getMemCacheFactory() { |
|
1492 | - return $this->query('MemCacheFactory'); |
|
1493 | - } |
|
1494 | - |
|
1495 | - /** |
|
1496 | - * Returns an \OC\RedisFactory instance |
|
1497 | - * |
|
1498 | - * @return \OC\RedisFactory |
|
1499 | - */ |
|
1500 | - public function getGetRedisFactory() { |
|
1501 | - return $this->query('RedisFactory'); |
|
1502 | - } |
|
1503 | - |
|
1504 | - |
|
1505 | - /** |
|
1506 | - * Returns the current session |
|
1507 | - * |
|
1508 | - * @return \OCP\IDBConnection |
|
1509 | - */ |
|
1510 | - public function getDatabaseConnection() { |
|
1511 | - return $this->query('DatabaseConnection'); |
|
1512 | - } |
|
1513 | - |
|
1514 | - /** |
|
1515 | - * Returns the activity manager |
|
1516 | - * |
|
1517 | - * @return \OCP\Activity\IManager |
|
1518 | - */ |
|
1519 | - public function getActivityManager() { |
|
1520 | - return $this->query('ActivityManager'); |
|
1521 | - } |
|
1522 | - |
|
1523 | - /** |
|
1524 | - * Returns an job list for controlling background jobs |
|
1525 | - * |
|
1526 | - * @return \OCP\BackgroundJob\IJobList |
|
1527 | - */ |
|
1528 | - public function getJobList() { |
|
1529 | - return $this->query('JobList'); |
|
1530 | - } |
|
1531 | - |
|
1532 | - /** |
|
1533 | - * Returns a logger instance |
|
1534 | - * |
|
1535 | - * @return \OCP\ILogger |
|
1536 | - */ |
|
1537 | - public function getLogger() { |
|
1538 | - return $this->query('Logger'); |
|
1539 | - } |
|
1540 | - |
|
1541 | - /** |
|
1542 | - * Returns a router for generating and matching urls |
|
1543 | - * |
|
1544 | - * @return \OCP\Route\IRouter |
|
1545 | - */ |
|
1546 | - public function getRouter() { |
|
1547 | - return $this->query('Router'); |
|
1548 | - } |
|
1549 | - |
|
1550 | - /** |
|
1551 | - * Returns a search instance |
|
1552 | - * |
|
1553 | - * @return \OCP\ISearch |
|
1554 | - */ |
|
1555 | - public function getSearch() { |
|
1556 | - return $this->query('Search'); |
|
1557 | - } |
|
1558 | - |
|
1559 | - /** |
|
1560 | - * Returns a SecureRandom instance |
|
1561 | - * |
|
1562 | - * @return \OCP\Security\ISecureRandom |
|
1563 | - */ |
|
1564 | - public function getSecureRandom() { |
|
1565 | - return $this->query('SecureRandom'); |
|
1566 | - } |
|
1567 | - |
|
1568 | - /** |
|
1569 | - * Returns a Crypto instance |
|
1570 | - * |
|
1571 | - * @return \OCP\Security\ICrypto |
|
1572 | - */ |
|
1573 | - public function getCrypto() { |
|
1574 | - return $this->query('Crypto'); |
|
1575 | - } |
|
1576 | - |
|
1577 | - /** |
|
1578 | - * Returns a Hasher instance |
|
1579 | - * |
|
1580 | - * @return \OCP\Security\IHasher |
|
1581 | - */ |
|
1582 | - public function getHasher() { |
|
1583 | - return $this->query('Hasher'); |
|
1584 | - } |
|
1585 | - |
|
1586 | - /** |
|
1587 | - * Returns a CredentialsManager instance |
|
1588 | - * |
|
1589 | - * @return \OCP\Security\ICredentialsManager |
|
1590 | - */ |
|
1591 | - public function getCredentialsManager() { |
|
1592 | - return $this->query('CredentialsManager'); |
|
1593 | - } |
|
1594 | - |
|
1595 | - /** |
|
1596 | - * Returns an instance of the HTTP helper class |
|
1597 | - * |
|
1598 | - * @deprecated Use getHTTPClientService() |
|
1599 | - * @return \OC\HTTPHelper |
|
1600 | - */ |
|
1601 | - public function getHTTPHelper() { |
|
1602 | - return $this->query('HTTPHelper'); |
|
1603 | - } |
|
1604 | - |
|
1605 | - /** |
|
1606 | - * Get the certificate manager for the user |
|
1607 | - * |
|
1608 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1609 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1610 | - */ |
|
1611 | - public function getCertificateManager($userId = '') { |
|
1612 | - if ($userId === '') { |
|
1613 | - $userSession = $this->getUserSession(); |
|
1614 | - $user = $userSession->getUser(); |
|
1615 | - if (is_null($user)) { |
|
1616 | - return null; |
|
1617 | - } |
|
1618 | - $userId = $user->getUID(); |
|
1619 | - } |
|
1620 | - return new CertificateManager( |
|
1621 | - $userId, |
|
1622 | - new View(), |
|
1623 | - $this->getConfig(), |
|
1624 | - $this->getLogger(), |
|
1625 | - $this->getSecureRandom() |
|
1626 | - ); |
|
1627 | - } |
|
1628 | - |
|
1629 | - /** |
|
1630 | - * Returns an instance of the HTTP client service |
|
1631 | - * |
|
1632 | - * @return \OCP\Http\Client\IClientService |
|
1633 | - */ |
|
1634 | - public function getHTTPClientService() { |
|
1635 | - return $this->query('HttpClientService'); |
|
1636 | - } |
|
1637 | - |
|
1638 | - /** |
|
1639 | - * Create a new event source |
|
1640 | - * |
|
1641 | - * @return \OCP\IEventSource |
|
1642 | - */ |
|
1643 | - public function createEventSource() { |
|
1644 | - return new \OC_EventSource(); |
|
1645 | - } |
|
1646 | - |
|
1647 | - /** |
|
1648 | - * Get the active event logger |
|
1649 | - * |
|
1650 | - * The returned logger only logs data when debug mode is enabled |
|
1651 | - * |
|
1652 | - * @return \OCP\Diagnostics\IEventLogger |
|
1653 | - */ |
|
1654 | - public function getEventLogger() { |
|
1655 | - return $this->query('EventLogger'); |
|
1656 | - } |
|
1657 | - |
|
1658 | - /** |
|
1659 | - * Get the active query logger |
|
1660 | - * |
|
1661 | - * The returned logger only logs data when debug mode is enabled |
|
1662 | - * |
|
1663 | - * @return \OCP\Diagnostics\IQueryLogger |
|
1664 | - */ |
|
1665 | - public function getQueryLogger() { |
|
1666 | - return $this->query('QueryLogger'); |
|
1667 | - } |
|
1668 | - |
|
1669 | - /** |
|
1670 | - * Get the manager for temporary files and folders |
|
1671 | - * |
|
1672 | - * @return \OCP\ITempManager |
|
1673 | - */ |
|
1674 | - public function getTempManager() { |
|
1675 | - return $this->query('TempManager'); |
|
1676 | - } |
|
1677 | - |
|
1678 | - /** |
|
1679 | - * Get the app manager |
|
1680 | - * |
|
1681 | - * @return \OCP\App\IAppManager |
|
1682 | - */ |
|
1683 | - public function getAppManager() { |
|
1684 | - return $this->query('AppManager'); |
|
1685 | - } |
|
1686 | - |
|
1687 | - /** |
|
1688 | - * Creates a new mailer |
|
1689 | - * |
|
1690 | - * @return \OCP\Mail\IMailer |
|
1691 | - */ |
|
1692 | - public function getMailer() { |
|
1693 | - return $this->query('Mailer'); |
|
1694 | - } |
|
1695 | - |
|
1696 | - /** |
|
1697 | - * Get the webroot |
|
1698 | - * |
|
1699 | - * @return string |
|
1700 | - */ |
|
1701 | - public function getWebRoot() { |
|
1702 | - return $this->webRoot; |
|
1703 | - } |
|
1704 | - |
|
1705 | - /** |
|
1706 | - * @return \OC\OCSClient |
|
1707 | - */ |
|
1708 | - public function getOcsClient() { |
|
1709 | - return $this->query('OcsClient'); |
|
1710 | - } |
|
1711 | - |
|
1712 | - /** |
|
1713 | - * @return \OCP\IDateTimeZone |
|
1714 | - */ |
|
1715 | - public function getDateTimeZone() { |
|
1716 | - return $this->query('DateTimeZone'); |
|
1717 | - } |
|
1718 | - |
|
1719 | - /** |
|
1720 | - * @return \OCP\IDateTimeFormatter |
|
1721 | - */ |
|
1722 | - public function getDateTimeFormatter() { |
|
1723 | - return $this->query('DateTimeFormatter'); |
|
1724 | - } |
|
1725 | - |
|
1726 | - /** |
|
1727 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
1728 | - */ |
|
1729 | - public function getMountProviderCollection() { |
|
1730 | - return $this->query('MountConfigManager'); |
|
1731 | - } |
|
1732 | - |
|
1733 | - /** |
|
1734 | - * Get the IniWrapper |
|
1735 | - * |
|
1736 | - * @return IniGetWrapper |
|
1737 | - */ |
|
1738 | - public function getIniWrapper() { |
|
1739 | - return $this->query('IniWrapper'); |
|
1740 | - } |
|
1741 | - |
|
1742 | - /** |
|
1743 | - * @return \OCP\Command\IBus |
|
1744 | - */ |
|
1745 | - public function getCommandBus() { |
|
1746 | - return $this->query('AsyncCommandBus'); |
|
1747 | - } |
|
1748 | - |
|
1749 | - /** |
|
1750 | - * Get the trusted domain helper |
|
1751 | - * |
|
1752 | - * @return TrustedDomainHelper |
|
1753 | - */ |
|
1754 | - public function getTrustedDomainHelper() { |
|
1755 | - return $this->query('TrustedDomainHelper'); |
|
1756 | - } |
|
1757 | - |
|
1758 | - /** |
|
1759 | - * Get the locking provider |
|
1760 | - * |
|
1761 | - * @return \OCP\Lock\ILockingProvider |
|
1762 | - * @since 8.1.0 |
|
1763 | - */ |
|
1764 | - public function getLockingProvider() { |
|
1765 | - return $this->query('LockingProvider'); |
|
1766 | - } |
|
1767 | - |
|
1768 | - /** |
|
1769 | - * @return \OCP\Files\Mount\IMountManager |
|
1770 | - **/ |
|
1771 | - function getMountManager() { |
|
1772 | - return $this->query('MountManager'); |
|
1773 | - } |
|
1774 | - |
|
1775 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
1776 | - function getUserMountCache() { |
|
1777 | - return $this->query('UserMountCache'); |
|
1778 | - } |
|
1779 | - |
|
1780 | - /** |
|
1781 | - * Get the MimeTypeDetector |
|
1782 | - * |
|
1783 | - * @return \OCP\Files\IMimeTypeDetector |
|
1784 | - */ |
|
1785 | - public function getMimeTypeDetector() { |
|
1786 | - return $this->query('MimeTypeDetector'); |
|
1787 | - } |
|
1788 | - |
|
1789 | - /** |
|
1790 | - * Get the MimeTypeLoader |
|
1791 | - * |
|
1792 | - * @return \OCP\Files\IMimeTypeLoader |
|
1793 | - */ |
|
1794 | - public function getMimeTypeLoader() { |
|
1795 | - return $this->query('MimeTypeLoader'); |
|
1796 | - } |
|
1797 | - |
|
1798 | - /** |
|
1799 | - * Get the manager of all the capabilities |
|
1800 | - * |
|
1801 | - * @return \OC\CapabilitiesManager |
|
1802 | - */ |
|
1803 | - public function getCapabilitiesManager() { |
|
1804 | - return $this->query('CapabilitiesManager'); |
|
1805 | - } |
|
1806 | - |
|
1807 | - /** |
|
1808 | - * Get the EventDispatcher |
|
1809 | - * |
|
1810 | - * @return EventDispatcherInterface |
|
1811 | - * @since 8.2.0 |
|
1812 | - */ |
|
1813 | - public function getEventDispatcher() { |
|
1814 | - return $this->query('EventDispatcher'); |
|
1815 | - } |
|
1816 | - |
|
1817 | - /** |
|
1818 | - * Get the Notification Manager |
|
1819 | - * |
|
1820 | - * @return \OCP\Notification\IManager |
|
1821 | - * @since 8.2.0 |
|
1822 | - */ |
|
1823 | - public function getNotificationManager() { |
|
1824 | - return $this->query('NotificationManager'); |
|
1825 | - } |
|
1826 | - |
|
1827 | - /** |
|
1828 | - * @return \OCP\Comments\ICommentsManager |
|
1829 | - */ |
|
1830 | - public function getCommentsManager() { |
|
1831 | - return $this->query('CommentsManager'); |
|
1832 | - } |
|
1833 | - |
|
1834 | - /** |
|
1835 | - * @return \OCA\Theming\ThemingDefaults |
|
1836 | - */ |
|
1837 | - public function getThemingDefaults() { |
|
1838 | - return $this->query('ThemingDefaults'); |
|
1839 | - } |
|
1840 | - |
|
1841 | - /** |
|
1842 | - * @return \OC\IntegrityCheck\Checker |
|
1843 | - */ |
|
1844 | - public function getIntegrityCodeChecker() { |
|
1845 | - return $this->query('IntegrityCodeChecker'); |
|
1846 | - } |
|
1847 | - |
|
1848 | - /** |
|
1849 | - * @return \OC\Session\CryptoWrapper |
|
1850 | - */ |
|
1851 | - public function getSessionCryptoWrapper() { |
|
1852 | - return $this->query('CryptoWrapper'); |
|
1853 | - } |
|
1854 | - |
|
1855 | - /** |
|
1856 | - * @return CsrfTokenManager |
|
1857 | - */ |
|
1858 | - public function getCsrfTokenManager() { |
|
1859 | - return $this->query('CsrfTokenManager'); |
|
1860 | - } |
|
1861 | - |
|
1862 | - /** |
|
1863 | - * @return Throttler |
|
1864 | - */ |
|
1865 | - public function getBruteForceThrottler() { |
|
1866 | - return $this->query('Throttler'); |
|
1867 | - } |
|
1868 | - |
|
1869 | - /** |
|
1870 | - * @return IContentSecurityPolicyManager |
|
1871 | - */ |
|
1872 | - public function getContentSecurityPolicyManager() { |
|
1873 | - return $this->query('ContentSecurityPolicyManager'); |
|
1874 | - } |
|
1875 | - |
|
1876 | - /** |
|
1877 | - * @return ContentSecurityPolicyNonceManager |
|
1878 | - */ |
|
1879 | - public function getContentSecurityPolicyNonceManager() { |
|
1880 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
1881 | - } |
|
1882 | - |
|
1883 | - /** |
|
1884 | - * Not a public API as of 8.2, wait for 9.0 |
|
1885 | - * |
|
1886 | - * @return \OCA\Files_External\Service\BackendService |
|
1887 | - */ |
|
1888 | - public function getStoragesBackendService() { |
|
1889 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1890 | - } |
|
1891 | - |
|
1892 | - /** |
|
1893 | - * Not a public API as of 8.2, wait for 9.0 |
|
1894 | - * |
|
1895 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1896 | - */ |
|
1897 | - public function getGlobalStoragesService() { |
|
1898 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1899 | - } |
|
1900 | - |
|
1901 | - /** |
|
1902 | - * Not a public API as of 8.2, wait for 9.0 |
|
1903 | - * |
|
1904 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1905 | - */ |
|
1906 | - public function getUserGlobalStoragesService() { |
|
1907 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1908 | - } |
|
1909 | - |
|
1910 | - /** |
|
1911 | - * Not a public API as of 8.2, wait for 9.0 |
|
1912 | - * |
|
1913 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
1914 | - */ |
|
1915 | - public function getUserStoragesService() { |
|
1916 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1917 | - } |
|
1918 | - |
|
1919 | - /** |
|
1920 | - * @return \OCP\Share\IManager |
|
1921 | - */ |
|
1922 | - public function getShareManager() { |
|
1923 | - return $this->query('ShareManager'); |
|
1924 | - } |
|
1925 | - |
|
1926 | - /** |
|
1927 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
1928 | - */ |
|
1929 | - public function getCollaboratorSearch() { |
|
1930 | - return $this->query('CollaboratorSearch'); |
|
1931 | - } |
|
1932 | - |
|
1933 | - /** |
|
1934 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
1935 | - */ |
|
1936 | - public function getAutoCompleteManager(){ |
|
1937 | - return $this->query(IManager::class); |
|
1938 | - } |
|
1939 | - |
|
1940 | - /** |
|
1941 | - * Returns the LDAP Provider |
|
1942 | - * |
|
1943 | - * @return \OCP\LDAP\ILDAPProvider |
|
1944 | - */ |
|
1945 | - public function getLDAPProvider() { |
|
1946 | - return $this->query('LDAPProvider'); |
|
1947 | - } |
|
1948 | - |
|
1949 | - /** |
|
1950 | - * @return \OCP\Settings\IManager |
|
1951 | - */ |
|
1952 | - public function getSettingsManager() { |
|
1953 | - return $this->query('SettingsManager'); |
|
1954 | - } |
|
1955 | - |
|
1956 | - /** |
|
1957 | - * @return \OCP\Files\IAppData |
|
1958 | - */ |
|
1959 | - public function getAppDataDir($app) { |
|
1960 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
1961 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1962 | - return $factory->get($app); |
|
1963 | - } |
|
1964 | - |
|
1965 | - /** |
|
1966 | - * @return \OCP\Lockdown\ILockdownManager |
|
1967 | - */ |
|
1968 | - public function getLockdownManager() { |
|
1969 | - return $this->query('LockdownManager'); |
|
1970 | - } |
|
1971 | - |
|
1972 | - /** |
|
1973 | - * @return \OCP\Federation\ICloudIdManager |
|
1974 | - */ |
|
1975 | - public function getCloudIdManager() { |
|
1976 | - return $this->query(ICloudIdManager::class); |
|
1977 | - } |
|
1978 | - |
|
1979 | - /** |
|
1980 | - * @return \OCP\Remote\Api\IApiFactory |
|
1981 | - */ |
|
1982 | - public function getRemoteApiFactory() { |
|
1983 | - return $this->query(IApiFactory::class); |
|
1984 | - } |
|
1985 | - |
|
1986 | - /** |
|
1987 | - * @return \OCP\Remote\IInstanceFactory |
|
1988 | - */ |
|
1989 | - public function getRemoteInstanceFactory() { |
|
1990 | - return $this->query(IInstanceFactory::class); |
|
1991 | - } |
|
938 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
939 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
940 | + $classExists = true; |
|
941 | + } else { |
|
942 | + $classExists = false; |
|
943 | + } |
|
944 | + |
|
945 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
946 | + return new ThemingDefaults( |
|
947 | + $c->getConfig(), |
|
948 | + $c->getL10N('theming'), |
|
949 | + $c->getURLGenerator(), |
|
950 | + $c->getAppDataDir('theming'), |
|
951 | + $c->getMemCacheFactory(), |
|
952 | + new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')), |
|
953 | + $this->getAppManager() |
|
954 | + ); |
|
955 | + } |
|
956 | + return new \OC_Defaults(); |
|
957 | + }); |
|
958 | + $this->registerService(SCSSCacher::class, function (Server $c) { |
|
959 | + /** @var Factory $cacheFactory */ |
|
960 | + $cacheFactory = $c->query(Factory::class); |
|
961 | + return new SCSSCacher( |
|
962 | + $c->getLogger(), |
|
963 | + $c->query(\OC\Files\AppData\Factory::class), |
|
964 | + $c->getURLGenerator(), |
|
965 | + $c->getConfig(), |
|
966 | + $c->getThemingDefaults(), |
|
967 | + \OC::$SERVERROOT, |
|
968 | + $cacheFactory->createDistributed('SCSS') |
|
969 | + ); |
|
970 | + }); |
|
971 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
972 | + /** @var Factory $cacheFactory */ |
|
973 | + $cacheFactory = $c->query(Factory::class); |
|
974 | + return new JSCombiner( |
|
975 | + $c->getAppDataDir('js'), |
|
976 | + $c->getURLGenerator(), |
|
977 | + $cacheFactory->createDistributed('JS'), |
|
978 | + $c->getSystemConfig(), |
|
979 | + $c->getLogger() |
|
980 | + ); |
|
981 | + }); |
|
982 | + $this->registerService(EventDispatcher::class, function () { |
|
983 | + return new EventDispatcher(); |
|
984 | + }); |
|
985 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
986 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
987 | + |
|
988 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
989 | + // FIXME: Instantiiated here due to cyclic dependency |
|
990 | + $request = new Request( |
|
991 | + [ |
|
992 | + 'get' => $_GET, |
|
993 | + 'post' => $_POST, |
|
994 | + 'files' => $_FILES, |
|
995 | + 'server' => $_SERVER, |
|
996 | + 'env' => $_ENV, |
|
997 | + 'cookies' => $_COOKIE, |
|
998 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
999 | + ? $_SERVER['REQUEST_METHOD'] |
|
1000 | + : null, |
|
1001 | + ], |
|
1002 | + $c->getSecureRandom(), |
|
1003 | + $c->getConfig() |
|
1004 | + ); |
|
1005 | + |
|
1006 | + return new CryptoWrapper( |
|
1007 | + $c->getConfig(), |
|
1008 | + $c->getCrypto(), |
|
1009 | + $c->getSecureRandom(), |
|
1010 | + $request |
|
1011 | + ); |
|
1012 | + }); |
|
1013 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1014 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1015 | + |
|
1016 | + return new CsrfTokenManager( |
|
1017 | + $tokenGenerator, |
|
1018 | + $c->query(SessionStorage::class) |
|
1019 | + ); |
|
1020 | + }); |
|
1021 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
1022 | + return new SessionStorage($c->getSession()); |
|
1023 | + }); |
|
1024 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1025 | + return new ContentSecurityPolicyManager(); |
|
1026 | + }); |
|
1027 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
1028 | + |
|
1029 | + $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1030 | + return new ContentSecurityPolicyNonceManager( |
|
1031 | + $c->getCsrfTokenManager(), |
|
1032 | + $c->getRequest() |
|
1033 | + ); |
|
1034 | + }); |
|
1035 | + |
|
1036 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1037 | + $config = $c->getConfig(); |
|
1038 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1039 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
1040 | + $factory = new $factoryClass($this); |
|
1041 | + |
|
1042 | + $manager = new \OC\Share20\Manager( |
|
1043 | + $c->getLogger(), |
|
1044 | + $c->getConfig(), |
|
1045 | + $c->getSecureRandom(), |
|
1046 | + $c->getHasher(), |
|
1047 | + $c->getMountManager(), |
|
1048 | + $c->getGroupManager(), |
|
1049 | + $c->getL10N('lib'), |
|
1050 | + $c->getL10NFactory(), |
|
1051 | + $factory, |
|
1052 | + $c->getUserManager(), |
|
1053 | + $c->getLazyRootFolder(), |
|
1054 | + $c->getEventDispatcher(), |
|
1055 | + $c->getMailer(), |
|
1056 | + $c->getURLGenerator(), |
|
1057 | + $c->getThemingDefaults() |
|
1058 | + ); |
|
1059 | + |
|
1060 | + return $manager; |
|
1061 | + }); |
|
1062 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1063 | + |
|
1064 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1065 | + $instance = new Collaboration\Collaborators\Search($c); |
|
1066 | + |
|
1067 | + // register default plugins |
|
1068 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1069 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1070 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1071 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1072 | + |
|
1073 | + return $instance; |
|
1074 | + }); |
|
1075 | + $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1076 | + |
|
1077 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1078 | + |
|
1079 | + $this->registerService('SettingsManager', function (Server $c) { |
|
1080 | + $manager = new \OC\Settings\Manager( |
|
1081 | + $c->getLogger(), |
|
1082 | + $c->getDatabaseConnection(), |
|
1083 | + $c->getL10N('lib'), |
|
1084 | + $c->getConfig(), |
|
1085 | + $c->getEncryptionManager(), |
|
1086 | + $c->getUserManager(), |
|
1087 | + $c->getLockingProvider(), |
|
1088 | + $c->getRequest(), |
|
1089 | + $c->getURLGenerator(), |
|
1090 | + $c->query(AccountManager::class), |
|
1091 | + $c->getGroupManager(), |
|
1092 | + $c->getL10NFactory(), |
|
1093 | + $c->getAppManager() |
|
1094 | + ); |
|
1095 | + return $manager; |
|
1096 | + }); |
|
1097 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1098 | + return new \OC\Files\AppData\Factory( |
|
1099 | + $c->getRootFolder(), |
|
1100 | + $c->getSystemConfig() |
|
1101 | + ); |
|
1102 | + }); |
|
1103 | + |
|
1104 | + $this->registerService('LockdownManager', function (Server $c) { |
|
1105 | + return new LockdownManager(function () use ($c) { |
|
1106 | + return $c->getSession(); |
|
1107 | + }); |
|
1108 | + }); |
|
1109 | + |
|
1110 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1111 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1112 | + }); |
|
1113 | + |
|
1114 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1115 | + return new CloudIdManager(); |
|
1116 | + }); |
|
1117 | + |
|
1118 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1119 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1120 | + |
|
1121 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1122 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1123 | + |
|
1124 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1125 | + return new Defaults( |
|
1126 | + $c->getThemingDefaults() |
|
1127 | + ); |
|
1128 | + }); |
|
1129 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1130 | + |
|
1131 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1132 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1133 | + }); |
|
1134 | + |
|
1135 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
1136 | + return new ShareHelper( |
|
1137 | + $c->query(\OCP\Share\IManager::class) |
|
1138 | + ); |
|
1139 | + }); |
|
1140 | + |
|
1141 | + $this->registerService(Installer::class, function(Server $c) { |
|
1142 | + return new Installer( |
|
1143 | + $c->getAppFetcher(), |
|
1144 | + $c->getHTTPClientService(), |
|
1145 | + $c->getTempManager(), |
|
1146 | + $c->getLogger(), |
|
1147 | + $c->getConfig() |
|
1148 | + ); |
|
1149 | + }); |
|
1150 | + |
|
1151 | + $this->registerService(IApiFactory::class, function(Server $c) { |
|
1152 | + return new ApiFactory($c->getHTTPClientService()); |
|
1153 | + }); |
|
1154 | + |
|
1155 | + $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1156 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
1157 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1158 | + }); |
|
1159 | + |
|
1160 | + $this->registerService(IContactsStore::class, function(Server $c) { |
|
1161 | + return new ContactsStore( |
|
1162 | + $c->getContactsManager(), |
|
1163 | + $c->getConfig(), |
|
1164 | + $c->getUserManager(), |
|
1165 | + $c->getGroupManager() |
|
1166 | + ); |
|
1167 | + }); |
|
1168 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1169 | + |
|
1170 | + $this->connectDispatcher(); |
|
1171 | + } |
|
1172 | + |
|
1173 | + /** |
|
1174 | + * @return \OCP\Calendar\IManager |
|
1175 | + */ |
|
1176 | + public function getCalendarManager() { |
|
1177 | + return $this->query('CalendarManager'); |
|
1178 | + } |
|
1179 | + |
|
1180 | + private function connectDispatcher() { |
|
1181 | + $dispatcher = $this->getEventDispatcher(); |
|
1182 | + |
|
1183 | + // Delete avatar on user deletion |
|
1184 | + $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1185 | + $logger = $this->getLogger(); |
|
1186 | + $manager = $this->getAvatarManager(); |
|
1187 | + /** @var IUser $user */ |
|
1188 | + $user = $e->getSubject(); |
|
1189 | + |
|
1190 | + try { |
|
1191 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1192 | + $avatar->remove(); |
|
1193 | + } catch (NotFoundException $e) { |
|
1194 | + // no avatar to remove |
|
1195 | + } catch (\Exception $e) { |
|
1196 | + // Ignore exceptions |
|
1197 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1198 | + } |
|
1199 | + }); |
|
1200 | + |
|
1201 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1202 | + $manager = $this->getAvatarManager(); |
|
1203 | + /** @var IUser $user */ |
|
1204 | + $user = $e->getSubject(); |
|
1205 | + $feature = $e->getArgument('feature'); |
|
1206 | + $oldValue = $e->getArgument('oldValue'); |
|
1207 | + $value = $e->getArgument('value'); |
|
1208 | + |
|
1209 | + try { |
|
1210 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1211 | + $avatar->userChanged($feature, $oldValue, $value); |
|
1212 | + } catch (NotFoundException $e) { |
|
1213 | + // no avatar to remove |
|
1214 | + } |
|
1215 | + }); |
|
1216 | + } |
|
1217 | + |
|
1218 | + /** |
|
1219 | + * @return \OCP\Contacts\IManager |
|
1220 | + */ |
|
1221 | + public function getContactsManager() { |
|
1222 | + return $this->query('ContactsManager'); |
|
1223 | + } |
|
1224 | + |
|
1225 | + /** |
|
1226 | + * @return \OC\Encryption\Manager |
|
1227 | + */ |
|
1228 | + public function getEncryptionManager() { |
|
1229 | + return $this->query('EncryptionManager'); |
|
1230 | + } |
|
1231 | + |
|
1232 | + /** |
|
1233 | + * @return \OC\Encryption\File |
|
1234 | + */ |
|
1235 | + public function getEncryptionFilesHelper() { |
|
1236 | + return $this->query('EncryptionFileHelper'); |
|
1237 | + } |
|
1238 | + |
|
1239 | + /** |
|
1240 | + * @return \OCP\Encryption\Keys\IStorage |
|
1241 | + */ |
|
1242 | + public function getEncryptionKeyStorage() { |
|
1243 | + return $this->query('EncryptionKeyStorage'); |
|
1244 | + } |
|
1245 | + |
|
1246 | + /** |
|
1247 | + * The current request object holding all information about the request |
|
1248 | + * currently being processed is returned from this method. |
|
1249 | + * In case the current execution was not initiated by a web request null is returned |
|
1250 | + * |
|
1251 | + * @return \OCP\IRequest |
|
1252 | + */ |
|
1253 | + public function getRequest() { |
|
1254 | + return $this->query('Request'); |
|
1255 | + } |
|
1256 | + |
|
1257 | + /** |
|
1258 | + * Returns the preview manager which can create preview images for a given file |
|
1259 | + * |
|
1260 | + * @return \OCP\IPreview |
|
1261 | + */ |
|
1262 | + public function getPreviewManager() { |
|
1263 | + return $this->query('PreviewManager'); |
|
1264 | + } |
|
1265 | + |
|
1266 | + /** |
|
1267 | + * Returns the tag manager which can get and set tags for different object types |
|
1268 | + * |
|
1269 | + * @see \OCP\ITagManager::load() |
|
1270 | + * @return \OCP\ITagManager |
|
1271 | + */ |
|
1272 | + public function getTagManager() { |
|
1273 | + return $this->query('TagManager'); |
|
1274 | + } |
|
1275 | + |
|
1276 | + /** |
|
1277 | + * Returns the system-tag manager |
|
1278 | + * |
|
1279 | + * @return \OCP\SystemTag\ISystemTagManager |
|
1280 | + * |
|
1281 | + * @since 9.0.0 |
|
1282 | + */ |
|
1283 | + public function getSystemTagManager() { |
|
1284 | + return $this->query('SystemTagManager'); |
|
1285 | + } |
|
1286 | + |
|
1287 | + /** |
|
1288 | + * Returns the system-tag object mapper |
|
1289 | + * |
|
1290 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1291 | + * |
|
1292 | + * @since 9.0.0 |
|
1293 | + */ |
|
1294 | + public function getSystemTagObjectMapper() { |
|
1295 | + return $this->query('SystemTagObjectMapper'); |
|
1296 | + } |
|
1297 | + |
|
1298 | + /** |
|
1299 | + * Returns the avatar manager, used for avatar functionality |
|
1300 | + * |
|
1301 | + * @return \OCP\IAvatarManager |
|
1302 | + */ |
|
1303 | + public function getAvatarManager() { |
|
1304 | + return $this->query('AvatarManager'); |
|
1305 | + } |
|
1306 | + |
|
1307 | + /** |
|
1308 | + * Returns the root folder of ownCloud's data directory |
|
1309 | + * |
|
1310 | + * @return \OCP\Files\IRootFolder |
|
1311 | + */ |
|
1312 | + public function getRootFolder() { |
|
1313 | + return $this->query('LazyRootFolder'); |
|
1314 | + } |
|
1315 | + |
|
1316 | + /** |
|
1317 | + * Returns the root folder of ownCloud's data directory |
|
1318 | + * This is the lazy variant so this gets only initialized once it |
|
1319 | + * is actually used. |
|
1320 | + * |
|
1321 | + * @return \OCP\Files\IRootFolder |
|
1322 | + */ |
|
1323 | + public function getLazyRootFolder() { |
|
1324 | + return $this->query('LazyRootFolder'); |
|
1325 | + } |
|
1326 | + |
|
1327 | + /** |
|
1328 | + * Returns a view to ownCloud's files folder |
|
1329 | + * |
|
1330 | + * @param string $userId user ID |
|
1331 | + * @return \OCP\Files\Folder|null |
|
1332 | + */ |
|
1333 | + public function getUserFolder($userId = null) { |
|
1334 | + if ($userId === null) { |
|
1335 | + $user = $this->getUserSession()->getUser(); |
|
1336 | + if (!$user) { |
|
1337 | + return null; |
|
1338 | + } |
|
1339 | + $userId = $user->getUID(); |
|
1340 | + } |
|
1341 | + $root = $this->getRootFolder(); |
|
1342 | + return $root->getUserFolder($userId); |
|
1343 | + } |
|
1344 | + |
|
1345 | + /** |
|
1346 | + * Returns an app-specific view in ownClouds data directory |
|
1347 | + * |
|
1348 | + * @return \OCP\Files\Folder |
|
1349 | + * @deprecated since 9.2.0 use IAppData |
|
1350 | + */ |
|
1351 | + public function getAppFolder() { |
|
1352 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
1353 | + $root = $this->getRootFolder(); |
|
1354 | + if (!$root->nodeExists($dir)) { |
|
1355 | + $folder = $root->newFolder($dir); |
|
1356 | + } else { |
|
1357 | + $folder = $root->get($dir); |
|
1358 | + } |
|
1359 | + return $folder; |
|
1360 | + } |
|
1361 | + |
|
1362 | + /** |
|
1363 | + * @return \OC\User\Manager |
|
1364 | + */ |
|
1365 | + public function getUserManager() { |
|
1366 | + return $this->query('UserManager'); |
|
1367 | + } |
|
1368 | + |
|
1369 | + /** |
|
1370 | + * @return \OC\Group\Manager |
|
1371 | + */ |
|
1372 | + public function getGroupManager() { |
|
1373 | + return $this->query('GroupManager'); |
|
1374 | + } |
|
1375 | + |
|
1376 | + /** |
|
1377 | + * @return \OC\User\Session |
|
1378 | + */ |
|
1379 | + public function getUserSession() { |
|
1380 | + return $this->query('UserSession'); |
|
1381 | + } |
|
1382 | + |
|
1383 | + /** |
|
1384 | + * @return \OCP\ISession |
|
1385 | + */ |
|
1386 | + public function getSession() { |
|
1387 | + return $this->query('UserSession')->getSession(); |
|
1388 | + } |
|
1389 | + |
|
1390 | + /** |
|
1391 | + * @param \OCP\ISession $session |
|
1392 | + */ |
|
1393 | + public function setSession(\OCP\ISession $session) { |
|
1394 | + $this->query(SessionStorage::class)->setSession($session); |
|
1395 | + $this->query('UserSession')->setSession($session); |
|
1396 | + $this->query(Store::class)->setSession($session); |
|
1397 | + } |
|
1398 | + |
|
1399 | + /** |
|
1400 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1401 | + */ |
|
1402 | + public function getTwoFactorAuthManager() { |
|
1403 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1404 | + } |
|
1405 | + |
|
1406 | + /** |
|
1407 | + * @return \OC\NavigationManager |
|
1408 | + */ |
|
1409 | + public function getNavigationManager() { |
|
1410 | + return $this->query('NavigationManager'); |
|
1411 | + } |
|
1412 | + |
|
1413 | + /** |
|
1414 | + * @return \OCP\IConfig |
|
1415 | + */ |
|
1416 | + public function getConfig() { |
|
1417 | + return $this->query('AllConfig'); |
|
1418 | + } |
|
1419 | + |
|
1420 | + /** |
|
1421 | + * @return \OC\SystemConfig |
|
1422 | + */ |
|
1423 | + public function getSystemConfig() { |
|
1424 | + return $this->query('SystemConfig'); |
|
1425 | + } |
|
1426 | + |
|
1427 | + /** |
|
1428 | + * Returns the app config manager |
|
1429 | + * |
|
1430 | + * @return \OCP\IAppConfig |
|
1431 | + */ |
|
1432 | + public function getAppConfig() { |
|
1433 | + return $this->query('AppConfig'); |
|
1434 | + } |
|
1435 | + |
|
1436 | + /** |
|
1437 | + * @return \OCP\L10N\IFactory |
|
1438 | + */ |
|
1439 | + public function getL10NFactory() { |
|
1440 | + return $this->query('L10NFactory'); |
|
1441 | + } |
|
1442 | + |
|
1443 | + /** |
|
1444 | + * get an L10N instance |
|
1445 | + * |
|
1446 | + * @param string $app appid |
|
1447 | + * @param string $lang |
|
1448 | + * @return IL10N |
|
1449 | + */ |
|
1450 | + public function getL10N($app, $lang = null) { |
|
1451 | + return $this->getL10NFactory()->get($app, $lang); |
|
1452 | + } |
|
1453 | + |
|
1454 | + /** |
|
1455 | + * @return \OCP\IURLGenerator |
|
1456 | + */ |
|
1457 | + public function getURLGenerator() { |
|
1458 | + return $this->query('URLGenerator'); |
|
1459 | + } |
|
1460 | + |
|
1461 | + /** |
|
1462 | + * @return \OCP\IHelper |
|
1463 | + */ |
|
1464 | + public function getHelper() { |
|
1465 | + return $this->query('AppHelper'); |
|
1466 | + } |
|
1467 | + |
|
1468 | + /** |
|
1469 | + * @return AppFetcher |
|
1470 | + */ |
|
1471 | + public function getAppFetcher() { |
|
1472 | + return $this->query(AppFetcher::class); |
|
1473 | + } |
|
1474 | + |
|
1475 | + /** |
|
1476 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1477 | + * getMemCacheFactory() instead. |
|
1478 | + * |
|
1479 | + * @return \OCP\ICache |
|
1480 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1481 | + */ |
|
1482 | + public function getCache() { |
|
1483 | + return $this->query('UserCache'); |
|
1484 | + } |
|
1485 | + |
|
1486 | + /** |
|
1487 | + * Returns an \OCP\CacheFactory instance |
|
1488 | + * |
|
1489 | + * @return \OCP\ICacheFactory |
|
1490 | + */ |
|
1491 | + public function getMemCacheFactory() { |
|
1492 | + return $this->query('MemCacheFactory'); |
|
1493 | + } |
|
1494 | + |
|
1495 | + /** |
|
1496 | + * Returns an \OC\RedisFactory instance |
|
1497 | + * |
|
1498 | + * @return \OC\RedisFactory |
|
1499 | + */ |
|
1500 | + public function getGetRedisFactory() { |
|
1501 | + return $this->query('RedisFactory'); |
|
1502 | + } |
|
1503 | + |
|
1504 | + |
|
1505 | + /** |
|
1506 | + * Returns the current session |
|
1507 | + * |
|
1508 | + * @return \OCP\IDBConnection |
|
1509 | + */ |
|
1510 | + public function getDatabaseConnection() { |
|
1511 | + return $this->query('DatabaseConnection'); |
|
1512 | + } |
|
1513 | + |
|
1514 | + /** |
|
1515 | + * Returns the activity manager |
|
1516 | + * |
|
1517 | + * @return \OCP\Activity\IManager |
|
1518 | + */ |
|
1519 | + public function getActivityManager() { |
|
1520 | + return $this->query('ActivityManager'); |
|
1521 | + } |
|
1522 | + |
|
1523 | + /** |
|
1524 | + * Returns an job list for controlling background jobs |
|
1525 | + * |
|
1526 | + * @return \OCP\BackgroundJob\IJobList |
|
1527 | + */ |
|
1528 | + public function getJobList() { |
|
1529 | + return $this->query('JobList'); |
|
1530 | + } |
|
1531 | + |
|
1532 | + /** |
|
1533 | + * Returns a logger instance |
|
1534 | + * |
|
1535 | + * @return \OCP\ILogger |
|
1536 | + */ |
|
1537 | + public function getLogger() { |
|
1538 | + return $this->query('Logger'); |
|
1539 | + } |
|
1540 | + |
|
1541 | + /** |
|
1542 | + * Returns a router for generating and matching urls |
|
1543 | + * |
|
1544 | + * @return \OCP\Route\IRouter |
|
1545 | + */ |
|
1546 | + public function getRouter() { |
|
1547 | + return $this->query('Router'); |
|
1548 | + } |
|
1549 | + |
|
1550 | + /** |
|
1551 | + * Returns a search instance |
|
1552 | + * |
|
1553 | + * @return \OCP\ISearch |
|
1554 | + */ |
|
1555 | + public function getSearch() { |
|
1556 | + return $this->query('Search'); |
|
1557 | + } |
|
1558 | + |
|
1559 | + /** |
|
1560 | + * Returns a SecureRandom instance |
|
1561 | + * |
|
1562 | + * @return \OCP\Security\ISecureRandom |
|
1563 | + */ |
|
1564 | + public function getSecureRandom() { |
|
1565 | + return $this->query('SecureRandom'); |
|
1566 | + } |
|
1567 | + |
|
1568 | + /** |
|
1569 | + * Returns a Crypto instance |
|
1570 | + * |
|
1571 | + * @return \OCP\Security\ICrypto |
|
1572 | + */ |
|
1573 | + public function getCrypto() { |
|
1574 | + return $this->query('Crypto'); |
|
1575 | + } |
|
1576 | + |
|
1577 | + /** |
|
1578 | + * Returns a Hasher instance |
|
1579 | + * |
|
1580 | + * @return \OCP\Security\IHasher |
|
1581 | + */ |
|
1582 | + public function getHasher() { |
|
1583 | + return $this->query('Hasher'); |
|
1584 | + } |
|
1585 | + |
|
1586 | + /** |
|
1587 | + * Returns a CredentialsManager instance |
|
1588 | + * |
|
1589 | + * @return \OCP\Security\ICredentialsManager |
|
1590 | + */ |
|
1591 | + public function getCredentialsManager() { |
|
1592 | + return $this->query('CredentialsManager'); |
|
1593 | + } |
|
1594 | + |
|
1595 | + /** |
|
1596 | + * Returns an instance of the HTTP helper class |
|
1597 | + * |
|
1598 | + * @deprecated Use getHTTPClientService() |
|
1599 | + * @return \OC\HTTPHelper |
|
1600 | + */ |
|
1601 | + public function getHTTPHelper() { |
|
1602 | + return $this->query('HTTPHelper'); |
|
1603 | + } |
|
1604 | + |
|
1605 | + /** |
|
1606 | + * Get the certificate manager for the user |
|
1607 | + * |
|
1608 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1609 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1610 | + */ |
|
1611 | + public function getCertificateManager($userId = '') { |
|
1612 | + if ($userId === '') { |
|
1613 | + $userSession = $this->getUserSession(); |
|
1614 | + $user = $userSession->getUser(); |
|
1615 | + if (is_null($user)) { |
|
1616 | + return null; |
|
1617 | + } |
|
1618 | + $userId = $user->getUID(); |
|
1619 | + } |
|
1620 | + return new CertificateManager( |
|
1621 | + $userId, |
|
1622 | + new View(), |
|
1623 | + $this->getConfig(), |
|
1624 | + $this->getLogger(), |
|
1625 | + $this->getSecureRandom() |
|
1626 | + ); |
|
1627 | + } |
|
1628 | + |
|
1629 | + /** |
|
1630 | + * Returns an instance of the HTTP client service |
|
1631 | + * |
|
1632 | + * @return \OCP\Http\Client\IClientService |
|
1633 | + */ |
|
1634 | + public function getHTTPClientService() { |
|
1635 | + return $this->query('HttpClientService'); |
|
1636 | + } |
|
1637 | + |
|
1638 | + /** |
|
1639 | + * Create a new event source |
|
1640 | + * |
|
1641 | + * @return \OCP\IEventSource |
|
1642 | + */ |
|
1643 | + public function createEventSource() { |
|
1644 | + return new \OC_EventSource(); |
|
1645 | + } |
|
1646 | + |
|
1647 | + /** |
|
1648 | + * Get the active event logger |
|
1649 | + * |
|
1650 | + * The returned logger only logs data when debug mode is enabled |
|
1651 | + * |
|
1652 | + * @return \OCP\Diagnostics\IEventLogger |
|
1653 | + */ |
|
1654 | + public function getEventLogger() { |
|
1655 | + return $this->query('EventLogger'); |
|
1656 | + } |
|
1657 | + |
|
1658 | + /** |
|
1659 | + * Get the active query logger |
|
1660 | + * |
|
1661 | + * The returned logger only logs data when debug mode is enabled |
|
1662 | + * |
|
1663 | + * @return \OCP\Diagnostics\IQueryLogger |
|
1664 | + */ |
|
1665 | + public function getQueryLogger() { |
|
1666 | + return $this->query('QueryLogger'); |
|
1667 | + } |
|
1668 | + |
|
1669 | + /** |
|
1670 | + * Get the manager for temporary files and folders |
|
1671 | + * |
|
1672 | + * @return \OCP\ITempManager |
|
1673 | + */ |
|
1674 | + public function getTempManager() { |
|
1675 | + return $this->query('TempManager'); |
|
1676 | + } |
|
1677 | + |
|
1678 | + /** |
|
1679 | + * Get the app manager |
|
1680 | + * |
|
1681 | + * @return \OCP\App\IAppManager |
|
1682 | + */ |
|
1683 | + public function getAppManager() { |
|
1684 | + return $this->query('AppManager'); |
|
1685 | + } |
|
1686 | + |
|
1687 | + /** |
|
1688 | + * Creates a new mailer |
|
1689 | + * |
|
1690 | + * @return \OCP\Mail\IMailer |
|
1691 | + */ |
|
1692 | + public function getMailer() { |
|
1693 | + return $this->query('Mailer'); |
|
1694 | + } |
|
1695 | + |
|
1696 | + /** |
|
1697 | + * Get the webroot |
|
1698 | + * |
|
1699 | + * @return string |
|
1700 | + */ |
|
1701 | + public function getWebRoot() { |
|
1702 | + return $this->webRoot; |
|
1703 | + } |
|
1704 | + |
|
1705 | + /** |
|
1706 | + * @return \OC\OCSClient |
|
1707 | + */ |
|
1708 | + public function getOcsClient() { |
|
1709 | + return $this->query('OcsClient'); |
|
1710 | + } |
|
1711 | + |
|
1712 | + /** |
|
1713 | + * @return \OCP\IDateTimeZone |
|
1714 | + */ |
|
1715 | + public function getDateTimeZone() { |
|
1716 | + return $this->query('DateTimeZone'); |
|
1717 | + } |
|
1718 | + |
|
1719 | + /** |
|
1720 | + * @return \OCP\IDateTimeFormatter |
|
1721 | + */ |
|
1722 | + public function getDateTimeFormatter() { |
|
1723 | + return $this->query('DateTimeFormatter'); |
|
1724 | + } |
|
1725 | + |
|
1726 | + /** |
|
1727 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
1728 | + */ |
|
1729 | + public function getMountProviderCollection() { |
|
1730 | + return $this->query('MountConfigManager'); |
|
1731 | + } |
|
1732 | + |
|
1733 | + /** |
|
1734 | + * Get the IniWrapper |
|
1735 | + * |
|
1736 | + * @return IniGetWrapper |
|
1737 | + */ |
|
1738 | + public function getIniWrapper() { |
|
1739 | + return $this->query('IniWrapper'); |
|
1740 | + } |
|
1741 | + |
|
1742 | + /** |
|
1743 | + * @return \OCP\Command\IBus |
|
1744 | + */ |
|
1745 | + public function getCommandBus() { |
|
1746 | + return $this->query('AsyncCommandBus'); |
|
1747 | + } |
|
1748 | + |
|
1749 | + /** |
|
1750 | + * Get the trusted domain helper |
|
1751 | + * |
|
1752 | + * @return TrustedDomainHelper |
|
1753 | + */ |
|
1754 | + public function getTrustedDomainHelper() { |
|
1755 | + return $this->query('TrustedDomainHelper'); |
|
1756 | + } |
|
1757 | + |
|
1758 | + /** |
|
1759 | + * Get the locking provider |
|
1760 | + * |
|
1761 | + * @return \OCP\Lock\ILockingProvider |
|
1762 | + * @since 8.1.0 |
|
1763 | + */ |
|
1764 | + public function getLockingProvider() { |
|
1765 | + return $this->query('LockingProvider'); |
|
1766 | + } |
|
1767 | + |
|
1768 | + /** |
|
1769 | + * @return \OCP\Files\Mount\IMountManager |
|
1770 | + **/ |
|
1771 | + function getMountManager() { |
|
1772 | + return $this->query('MountManager'); |
|
1773 | + } |
|
1774 | + |
|
1775 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
1776 | + function getUserMountCache() { |
|
1777 | + return $this->query('UserMountCache'); |
|
1778 | + } |
|
1779 | + |
|
1780 | + /** |
|
1781 | + * Get the MimeTypeDetector |
|
1782 | + * |
|
1783 | + * @return \OCP\Files\IMimeTypeDetector |
|
1784 | + */ |
|
1785 | + public function getMimeTypeDetector() { |
|
1786 | + return $this->query('MimeTypeDetector'); |
|
1787 | + } |
|
1788 | + |
|
1789 | + /** |
|
1790 | + * Get the MimeTypeLoader |
|
1791 | + * |
|
1792 | + * @return \OCP\Files\IMimeTypeLoader |
|
1793 | + */ |
|
1794 | + public function getMimeTypeLoader() { |
|
1795 | + return $this->query('MimeTypeLoader'); |
|
1796 | + } |
|
1797 | + |
|
1798 | + /** |
|
1799 | + * Get the manager of all the capabilities |
|
1800 | + * |
|
1801 | + * @return \OC\CapabilitiesManager |
|
1802 | + */ |
|
1803 | + public function getCapabilitiesManager() { |
|
1804 | + return $this->query('CapabilitiesManager'); |
|
1805 | + } |
|
1806 | + |
|
1807 | + /** |
|
1808 | + * Get the EventDispatcher |
|
1809 | + * |
|
1810 | + * @return EventDispatcherInterface |
|
1811 | + * @since 8.2.0 |
|
1812 | + */ |
|
1813 | + public function getEventDispatcher() { |
|
1814 | + return $this->query('EventDispatcher'); |
|
1815 | + } |
|
1816 | + |
|
1817 | + /** |
|
1818 | + * Get the Notification Manager |
|
1819 | + * |
|
1820 | + * @return \OCP\Notification\IManager |
|
1821 | + * @since 8.2.0 |
|
1822 | + */ |
|
1823 | + public function getNotificationManager() { |
|
1824 | + return $this->query('NotificationManager'); |
|
1825 | + } |
|
1826 | + |
|
1827 | + /** |
|
1828 | + * @return \OCP\Comments\ICommentsManager |
|
1829 | + */ |
|
1830 | + public function getCommentsManager() { |
|
1831 | + return $this->query('CommentsManager'); |
|
1832 | + } |
|
1833 | + |
|
1834 | + /** |
|
1835 | + * @return \OCA\Theming\ThemingDefaults |
|
1836 | + */ |
|
1837 | + public function getThemingDefaults() { |
|
1838 | + return $this->query('ThemingDefaults'); |
|
1839 | + } |
|
1840 | + |
|
1841 | + /** |
|
1842 | + * @return \OC\IntegrityCheck\Checker |
|
1843 | + */ |
|
1844 | + public function getIntegrityCodeChecker() { |
|
1845 | + return $this->query('IntegrityCodeChecker'); |
|
1846 | + } |
|
1847 | + |
|
1848 | + /** |
|
1849 | + * @return \OC\Session\CryptoWrapper |
|
1850 | + */ |
|
1851 | + public function getSessionCryptoWrapper() { |
|
1852 | + return $this->query('CryptoWrapper'); |
|
1853 | + } |
|
1854 | + |
|
1855 | + /** |
|
1856 | + * @return CsrfTokenManager |
|
1857 | + */ |
|
1858 | + public function getCsrfTokenManager() { |
|
1859 | + return $this->query('CsrfTokenManager'); |
|
1860 | + } |
|
1861 | + |
|
1862 | + /** |
|
1863 | + * @return Throttler |
|
1864 | + */ |
|
1865 | + public function getBruteForceThrottler() { |
|
1866 | + return $this->query('Throttler'); |
|
1867 | + } |
|
1868 | + |
|
1869 | + /** |
|
1870 | + * @return IContentSecurityPolicyManager |
|
1871 | + */ |
|
1872 | + public function getContentSecurityPolicyManager() { |
|
1873 | + return $this->query('ContentSecurityPolicyManager'); |
|
1874 | + } |
|
1875 | + |
|
1876 | + /** |
|
1877 | + * @return ContentSecurityPolicyNonceManager |
|
1878 | + */ |
|
1879 | + public function getContentSecurityPolicyNonceManager() { |
|
1880 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
1881 | + } |
|
1882 | + |
|
1883 | + /** |
|
1884 | + * Not a public API as of 8.2, wait for 9.0 |
|
1885 | + * |
|
1886 | + * @return \OCA\Files_External\Service\BackendService |
|
1887 | + */ |
|
1888 | + public function getStoragesBackendService() { |
|
1889 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1890 | + } |
|
1891 | + |
|
1892 | + /** |
|
1893 | + * Not a public API as of 8.2, wait for 9.0 |
|
1894 | + * |
|
1895 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1896 | + */ |
|
1897 | + public function getGlobalStoragesService() { |
|
1898 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1899 | + } |
|
1900 | + |
|
1901 | + /** |
|
1902 | + * Not a public API as of 8.2, wait for 9.0 |
|
1903 | + * |
|
1904 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1905 | + */ |
|
1906 | + public function getUserGlobalStoragesService() { |
|
1907 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1908 | + } |
|
1909 | + |
|
1910 | + /** |
|
1911 | + * Not a public API as of 8.2, wait for 9.0 |
|
1912 | + * |
|
1913 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
1914 | + */ |
|
1915 | + public function getUserStoragesService() { |
|
1916 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1917 | + } |
|
1918 | + |
|
1919 | + /** |
|
1920 | + * @return \OCP\Share\IManager |
|
1921 | + */ |
|
1922 | + public function getShareManager() { |
|
1923 | + return $this->query('ShareManager'); |
|
1924 | + } |
|
1925 | + |
|
1926 | + /** |
|
1927 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
1928 | + */ |
|
1929 | + public function getCollaboratorSearch() { |
|
1930 | + return $this->query('CollaboratorSearch'); |
|
1931 | + } |
|
1932 | + |
|
1933 | + /** |
|
1934 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
1935 | + */ |
|
1936 | + public function getAutoCompleteManager(){ |
|
1937 | + return $this->query(IManager::class); |
|
1938 | + } |
|
1939 | + |
|
1940 | + /** |
|
1941 | + * Returns the LDAP Provider |
|
1942 | + * |
|
1943 | + * @return \OCP\LDAP\ILDAPProvider |
|
1944 | + */ |
|
1945 | + public function getLDAPProvider() { |
|
1946 | + return $this->query('LDAPProvider'); |
|
1947 | + } |
|
1948 | + |
|
1949 | + /** |
|
1950 | + * @return \OCP\Settings\IManager |
|
1951 | + */ |
|
1952 | + public function getSettingsManager() { |
|
1953 | + return $this->query('SettingsManager'); |
|
1954 | + } |
|
1955 | + |
|
1956 | + /** |
|
1957 | + * @return \OCP\Files\IAppData |
|
1958 | + */ |
|
1959 | + public function getAppDataDir($app) { |
|
1960 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
1961 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1962 | + return $factory->get($app); |
|
1963 | + } |
|
1964 | + |
|
1965 | + /** |
|
1966 | + * @return \OCP\Lockdown\ILockdownManager |
|
1967 | + */ |
|
1968 | + public function getLockdownManager() { |
|
1969 | + return $this->query('LockdownManager'); |
|
1970 | + } |
|
1971 | + |
|
1972 | + /** |
|
1973 | + * @return \OCP\Federation\ICloudIdManager |
|
1974 | + */ |
|
1975 | + public function getCloudIdManager() { |
|
1976 | + return $this->query(ICloudIdManager::class); |
|
1977 | + } |
|
1978 | + |
|
1979 | + /** |
|
1980 | + * @return \OCP\Remote\Api\IApiFactory |
|
1981 | + */ |
|
1982 | + public function getRemoteApiFactory() { |
|
1983 | + return $this->query(IApiFactory::class); |
|
1984 | + } |
|
1985 | + |
|
1986 | + /** |
|
1987 | + * @return \OCP\Remote\IInstanceFactory |
|
1988 | + */ |
|
1989 | + public function getRemoteInstanceFactory() { |
|
1990 | + return $this->query(IInstanceFactory::class); |
|
1991 | + } |
|
1992 | 1992 | } |
@@ -134,7 +134,7 @@ |
||
134 | 134 | * @param RequestInterface $request |
135 | 135 | * @param ResponseInterface $response |
136 | 136 | * |
137 | - * @return void|bool |
|
137 | + * @return null|false |
|
138 | 138 | */ |
139 | 139 | public function httpPost(RequestInterface $request, ResponseInterface $response) { |
140 | 140 | $path = $request->getPath(); |
@@ -34,194 +34,194 @@ |
||
34 | 34 | use OCP\IConfig; |
35 | 35 | |
36 | 36 | class PublishPlugin extends ServerPlugin { |
37 | - const NS_CALENDARSERVER = 'http://calendarserver.org/ns/'; |
|
38 | - |
|
39 | - /** |
|
40 | - * Reference to SabreDAV server object. |
|
41 | - * |
|
42 | - * @var \Sabre\DAV\Server |
|
43 | - */ |
|
44 | - protected $server; |
|
45 | - |
|
46 | - /** |
|
47 | - * Config instance to get instance secret. |
|
48 | - * |
|
49 | - * @var IConfig |
|
50 | - */ |
|
51 | - protected $config; |
|
52 | - |
|
53 | - /** |
|
54 | - * URL Generator for absolute URLs. |
|
55 | - * |
|
56 | - * @var IURLGenerator |
|
57 | - */ |
|
58 | - protected $urlGenerator; |
|
59 | - |
|
60 | - /** |
|
61 | - * PublishPlugin constructor. |
|
62 | - * |
|
63 | - * @param IConfig $config |
|
64 | - * @param IURLGenerator $urlGenerator |
|
65 | - */ |
|
66 | - public function __construct(IConfig $config, IURLGenerator $urlGenerator) { |
|
67 | - $this->config = $config; |
|
68 | - $this->urlGenerator = $urlGenerator; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * This method should return a list of server-features. |
|
73 | - * |
|
74 | - * This is for example 'versioning' and is added to the DAV: header |
|
75 | - * in an OPTIONS response. |
|
76 | - * |
|
77 | - * @return string[] |
|
78 | - */ |
|
79 | - public function getFeatures() { |
|
80 | - // May have to be changed to be detected |
|
81 | - return ['oc-calendar-publishing', 'calendarserver-sharing']; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Returns a plugin name. |
|
86 | - * |
|
87 | - * Using this name other plugins will be able to access other plugins |
|
88 | - * using Sabre\DAV\Server::getPlugin |
|
89 | - * |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public function getPluginName() { |
|
93 | - return 'oc-calendar-publishing'; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * This initializes the plugin. |
|
98 | - * |
|
99 | - * This function is called by Sabre\DAV\Server, after |
|
100 | - * addPlugin is called. |
|
101 | - * |
|
102 | - * This method should set up the required event subscriptions. |
|
103 | - * |
|
104 | - * @param Server $server |
|
105 | - */ |
|
106 | - public function initialize(Server $server) { |
|
107 | - $this->server = $server; |
|
108 | - |
|
109 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
110 | - $this->server->on('propFind', [$this, 'propFind']); |
|
111 | - } |
|
112 | - |
|
113 | - public function propFind(PropFind $propFind, INode $node) { |
|
114 | - if ($node instanceof Calendar) { |
|
115 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { |
|
116 | - if ($node->getPublishStatus()) { |
|
117 | - // We return the publish-url only if the calendar is published. |
|
118 | - $token = $node->getPublishStatus(); |
|
119 | - $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token; |
|
120 | - |
|
121 | - return new Publisher($publishUrl, true); |
|
122 | - } |
|
123 | - }); |
|
124 | - |
|
125 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function() use ($node) { |
|
126 | - return new AllowedSharingModes(!$node->isSubscription(), !$node->isSubscription()); |
|
127 | - }); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * We intercept this to handle POST requests on calendars. |
|
133 | - * |
|
134 | - * @param RequestInterface $request |
|
135 | - * @param ResponseInterface $response |
|
136 | - * |
|
137 | - * @return void|bool |
|
138 | - */ |
|
139 | - public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
140 | - $path = $request->getPath(); |
|
141 | - |
|
142 | - // Only handling xml |
|
143 | - $contentType = $request->getHeader('Content-Type'); |
|
144 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
145 | - return; |
|
146 | - } |
|
147 | - |
|
148 | - // Making sure the node exists |
|
149 | - try { |
|
150 | - $node = $this->server->tree->getNodeForPath($path); |
|
151 | - } catch (NotFound $e) { |
|
152 | - return; |
|
153 | - } |
|
154 | - |
|
155 | - $requestBody = $request->getBodyAsString(); |
|
156 | - |
|
157 | - // If this request handler could not deal with this POST request, it |
|
158 | - // will return 'null' and other plugins get a chance to handle the |
|
159 | - // request. |
|
160 | - // |
|
161 | - // However, we already requested the full body. This is a problem, |
|
162 | - // because a body can only be read once. This is why we preemptively |
|
163 | - // re-populated the request body with the existing data. |
|
164 | - $request->setBody($requestBody); |
|
165 | - |
|
166 | - $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
167 | - |
|
168 | - switch ($documentType) { |
|
169 | - |
|
170 | - case '{'.self::NS_CALENDARSERVER.'}publish-calendar' : |
|
171 | - |
|
172 | - // We can only deal with IShareableCalendar objects |
|
173 | - if (!$node instanceof Calendar) { |
|
174 | - return; |
|
175 | - } |
|
176 | - $this->server->transactionType = 'post-publish-calendar'; |
|
177 | - |
|
178 | - // Getting ACL info |
|
179 | - $acl = $this->server->getPlugin('acl'); |
|
180 | - |
|
181 | - // If there's no ACL support, we allow everything |
|
182 | - if ($acl) { |
|
183 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
184 | - } |
|
185 | - |
|
186 | - $node->setPublishStatus(true); |
|
187 | - |
|
188 | - // iCloud sends back the 202, so we will too. |
|
189 | - $response->setStatus(202); |
|
190 | - |
|
191 | - // Adding this because sending a response body may cause issues, |
|
192 | - // and I wanted some type of indicator the response was handled. |
|
193 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
194 | - |
|
195 | - // Breaking the event chain |
|
196 | - return false; |
|
197 | - |
|
198 | - case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' : |
|
199 | - |
|
200 | - // We can only deal with IShareableCalendar objects |
|
201 | - if (!$node instanceof Calendar) { |
|
202 | - return; |
|
203 | - } |
|
204 | - $this->server->transactionType = 'post-unpublish-calendar'; |
|
205 | - |
|
206 | - // Getting ACL info |
|
207 | - $acl = $this->server->getPlugin('acl'); |
|
208 | - |
|
209 | - // If there's no ACL support, we allow everything |
|
210 | - if ($acl) { |
|
211 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
212 | - } |
|
213 | - |
|
214 | - $node->setPublishStatus(false); |
|
215 | - |
|
216 | - $response->setStatus(200); |
|
217 | - |
|
218 | - // Adding this because sending a response body may cause issues, |
|
219 | - // and I wanted some type of indicator the response was handled. |
|
220 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
221 | - |
|
222 | - // Breaking the event chain |
|
223 | - return false; |
|
37 | + const NS_CALENDARSERVER = 'http://calendarserver.org/ns/'; |
|
38 | + |
|
39 | + /** |
|
40 | + * Reference to SabreDAV server object. |
|
41 | + * |
|
42 | + * @var \Sabre\DAV\Server |
|
43 | + */ |
|
44 | + protected $server; |
|
45 | + |
|
46 | + /** |
|
47 | + * Config instance to get instance secret. |
|
48 | + * |
|
49 | + * @var IConfig |
|
50 | + */ |
|
51 | + protected $config; |
|
52 | + |
|
53 | + /** |
|
54 | + * URL Generator for absolute URLs. |
|
55 | + * |
|
56 | + * @var IURLGenerator |
|
57 | + */ |
|
58 | + protected $urlGenerator; |
|
59 | + |
|
60 | + /** |
|
61 | + * PublishPlugin constructor. |
|
62 | + * |
|
63 | + * @param IConfig $config |
|
64 | + * @param IURLGenerator $urlGenerator |
|
65 | + */ |
|
66 | + public function __construct(IConfig $config, IURLGenerator $urlGenerator) { |
|
67 | + $this->config = $config; |
|
68 | + $this->urlGenerator = $urlGenerator; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * This method should return a list of server-features. |
|
73 | + * |
|
74 | + * This is for example 'versioning' and is added to the DAV: header |
|
75 | + * in an OPTIONS response. |
|
76 | + * |
|
77 | + * @return string[] |
|
78 | + */ |
|
79 | + public function getFeatures() { |
|
80 | + // May have to be changed to be detected |
|
81 | + return ['oc-calendar-publishing', 'calendarserver-sharing']; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Returns a plugin name. |
|
86 | + * |
|
87 | + * Using this name other plugins will be able to access other plugins |
|
88 | + * using Sabre\DAV\Server::getPlugin |
|
89 | + * |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public function getPluginName() { |
|
93 | + return 'oc-calendar-publishing'; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * This initializes the plugin. |
|
98 | + * |
|
99 | + * This function is called by Sabre\DAV\Server, after |
|
100 | + * addPlugin is called. |
|
101 | + * |
|
102 | + * This method should set up the required event subscriptions. |
|
103 | + * |
|
104 | + * @param Server $server |
|
105 | + */ |
|
106 | + public function initialize(Server $server) { |
|
107 | + $this->server = $server; |
|
108 | + |
|
109 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
110 | + $this->server->on('propFind', [$this, 'propFind']); |
|
111 | + } |
|
112 | + |
|
113 | + public function propFind(PropFind $propFind, INode $node) { |
|
114 | + if ($node instanceof Calendar) { |
|
115 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { |
|
116 | + if ($node->getPublishStatus()) { |
|
117 | + // We return the publish-url only if the calendar is published. |
|
118 | + $token = $node->getPublishStatus(); |
|
119 | + $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token; |
|
120 | + |
|
121 | + return new Publisher($publishUrl, true); |
|
122 | + } |
|
123 | + }); |
|
124 | + |
|
125 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function() use ($node) { |
|
126 | + return new AllowedSharingModes(!$node->isSubscription(), !$node->isSubscription()); |
|
127 | + }); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * We intercept this to handle POST requests on calendars. |
|
133 | + * |
|
134 | + * @param RequestInterface $request |
|
135 | + * @param ResponseInterface $response |
|
136 | + * |
|
137 | + * @return void|bool |
|
138 | + */ |
|
139 | + public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
140 | + $path = $request->getPath(); |
|
141 | + |
|
142 | + // Only handling xml |
|
143 | + $contentType = $request->getHeader('Content-Type'); |
|
144 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
145 | + return; |
|
146 | + } |
|
147 | + |
|
148 | + // Making sure the node exists |
|
149 | + try { |
|
150 | + $node = $this->server->tree->getNodeForPath($path); |
|
151 | + } catch (NotFound $e) { |
|
152 | + return; |
|
153 | + } |
|
154 | + |
|
155 | + $requestBody = $request->getBodyAsString(); |
|
156 | + |
|
157 | + // If this request handler could not deal with this POST request, it |
|
158 | + // will return 'null' and other plugins get a chance to handle the |
|
159 | + // request. |
|
160 | + // |
|
161 | + // However, we already requested the full body. This is a problem, |
|
162 | + // because a body can only be read once. This is why we preemptively |
|
163 | + // re-populated the request body with the existing data. |
|
164 | + $request->setBody($requestBody); |
|
165 | + |
|
166 | + $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
167 | + |
|
168 | + switch ($documentType) { |
|
169 | + |
|
170 | + case '{'.self::NS_CALENDARSERVER.'}publish-calendar' : |
|
171 | + |
|
172 | + // We can only deal with IShareableCalendar objects |
|
173 | + if (!$node instanceof Calendar) { |
|
174 | + return; |
|
175 | + } |
|
176 | + $this->server->transactionType = 'post-publish-calendar'; |
|
177 | + |
|
178 | + // Getting ACL info |
|
179 | + $acl = $this->server->getPlugin('acl'); |
|
180 | + |
|
181 | + // If there's no ACL support, we allow everything |
|
182 | + if ($acl) { |
|
183 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
184 | + } |
|
185 | + |
|
186 | + $node->setPublishStatus(true); |
|
187 | + |
|
188 | + // iCloud sends back the 202, so we will too. |
|
189 | + $response->setStatus(202); |
|
190 | + |
|
191 | + // Adding this because sending a response body may cause issues, |
|
192 | + // and I wanted some type of indicator the response was handled. |
|
193 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
194 | + |
|
195 | + // Breaking the event chain |
|
196 | + return false; |
|
197 | + |
|
198 | + case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' : |
|
199 | + |
|
200 | + // We can only deal with IShareableCalendar objects |
|
201 | + if (!$node instanceof Calendar) { |
|
202 | + return; |
|
203 | + } |
|
204 | + $this->server->transactionType = 'post-unpublish-calendar'; |
|
205 | + |
|
206 | + // Getting ACL info |
|
207 | + $acl = $this->server->getPlugin('acl'); |
|
208 | + |
|
209 | + // If there's no ACL support, we allow everything |
|
210 | + if ($acl) { |
|
211 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
212 | + } |
|
213 | + |
|
214 | + $node->setPublishStatus(false); |
|
215 | + |
|
216 | + $response->setStatus(200); |
|
217 | + |
|
218 | + // Adding this because sending a response body may cause issues, |
|
219 | + // and I wanted some type of indicator the response was handled. |
|
220 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
221 | + |
|
222 | + // Breaking the event chain |
|
223 | + return false; |
|
224 | 224 | |
225 | - } |
|
226 | - } |
|
225 | + } |
|
226 | + } |
|
227 | 227 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return string |
91 | 91 | */ |
92 | - public function getPluginName() { |
|
92 | + public function getPluginName() { |
|
93 | 93 | return 'oc-calendar-publishing'; |
94 | 94 | } |
95 | 95 | |
@@ -107,12 +107,12 @@ discard block |
||
107 | 107 | $this->server = $server; |
108 | 108 | |
109 | 109 | $this->server->on('method:POST', [$this, 'httpPost']); |
110 | - $this->server->on('propFind', [$this, 'propFind']); |
|
110 | + $this->server->on('propFind', [$this, 'propFind']); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | public function propFind(PropFind $propFind, INode $node) { |
114 | 114 | if ($node instanceof Calendar) { |
115 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { |
|
115 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function() use ($node) { |
|
116 | 116 | if ($node->getPublishStatus()) { |
117 | 117 | // We return the publish-url only if the calendar is published. |
118 | 118 | $token = $node->getPublishStatus(); |
@@ -30,7 +30,7 @@ |
||
30 | 30 | |
31 | 31 | /** |
32 | 32 | * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend |
33 | - * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend |
|
33 | + * @param CardDavBackend $carddavBackend |
|
34 | 34 | * @param string $principalPrefix |
35 | 35 | */ |
36 | 36 | public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') { |
@@ -25,46 +25,46 @@ |
||
25 | 25 | |
26 | 26 | class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot { |
27 | 27 | |
28 | - /** @var IL10N */ |
|
29 | - protected $l10n; |
|
28 | + /** @var IL10N */ |
|
29 | + protected $l10n; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend |
|
33 | - * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend |
|
34 | - * @param string $principalPrefix |
|
35 | - */ |
|
36 | - public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') { |
|
37 | - parent::__construct($principalBackend, $carddavBackend, $principalPrefix); |
|
38 | - $this->l10n = \OC::$server->getL10N('dav'); |
|
39 | - } |
|
31 | + /** |
|
32 | + * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend |
|
33 | + * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend |
|
34 | + * @param string $principalPrefix |
|
35 | + */ |
|
36 | + public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') { |
|
37 | + parent::__construct($principalBackend, $carddavBackend, $principalPrefix); |
|
38 | + $this->l10n = \OC::$server->getL10N('dav'); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * This method returns a node for a principal. |
|
43 | - * |
|
44 | - * The passed array contains principal information, and is guaranteed to |
|
45 | - * at least contain a uri item. Other properties may or may not be |
|
46 | - * supplied by the authentication backend. |
|
47 | - * |
|
48 | - * @param array $principal |
|
49 | - * @return \Sabre\DAV\INode |
|
50 | - */ |
|
51 | - function getChildForPrincipal(array $principal) { |
|
41 | + /** |
|
42 | + * This method returns a node for a principal. |
|
43 | + * |
|
44 | + * The passed array contains principal information, and is guaranteed to |
|
45 | + * at least contain a uri item. Other properties may or may not be |
|
46 | + * supplied by the authentication backend. |
|
47 | + * |
|
48 | + * @param array $principal |
|
49 | + * @return \Sabre\DAV\INode |
|
50 | + */ |
|
51 | + function getChildForPrincipal(array $principal) { |
|
52 | 52 | |
53 | - return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->l10n); |
|
53 | + return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->l10n); |
|
54 | 54 | |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - function getName() { |
|
57 | + function getName() { |
|
58 | 58 | |
59 | - if ($this->principalPrefix === 'principals') { |
|
60 | - return parent::getName(); |
|
61 | - } |
|
62 | - // Grabbing all the components of the principal path. |
|
63 | - $parts = explode('/', $this->principalPrefix); |
|
59 | + if ($this->principalPrefix === 'principals') { |
|
60 | + return parent::getName(); |
|
61 | + } |
|
62 | + // Grabbing all the components of the principal path. |
|
63 | + $parts = explode('/', $this->principalPrefix); |
|
64 | 64 | |
65 | - // We are only interested in the second part. |
|
66 | - return $parts[1]; |
|
65 | + // We are only interested in the second part. |
|
66 | + return $parts[1]; |
|
67 | 67 | |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | 70 | } |
@@ -770,7 +770,7 @@ |
||
770 | 770 | |
771 | 771 | /** |
772 | 772 | * @param Share[] $shares |
773 | - * @param $userId |
|
773 | + * @param string $userId |
|
774 | 774 | * @return Share[] The updates shares if no update is found for a share return the original |
775 | 775 | */ |
776 | 776 | private function resolveGroupShares($shares, $userId) { |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | ->orderBy('id'); |
288 | 288 | |
289 | 289 | $cursor = $qb->execute(); |
290 | - while($data = $cursor->fetch()) { |
|
290 | + while ($data = $cursor->fetch()) { |
|
291 | 291 | $children[] = $this->createShare($data); |
292 | 292 | } |
293 | 293 | $cursor->closeCursor(); |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | $user = $this->userManager->get($recipient); |
333 | 333 | |
334 | 334 | if (is_null($group)) { |
335 | - throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
335 | + throw new ProviderException('Group "'.$share->getSharedWith().'" does not exist'); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | if (!$group->inGroup($user)) { |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | ); |
493 | 493 | } |
494 | 494 | |
495 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
495 | + $qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
496 | 496 | $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
497 | 497 | |
498 | 498 | $qb->orderBy('id'); |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | |
549 | 549 | $cursor = $qb->execute(); |
550 | 550 | $shares = []; |
551 | - while($data = $cursor->fetch()) { |
|
551 | + while ($data = $cursor->fetch()) { |
|
552 | 552 | $shares[] = $this->createShare($data); |
553 | 553 | } |
554 | 554 | $cursor->closeCursor(); |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | ->execute(); |
628 | 628 | |
629 | 629 | $shares = []; |
630 | - while($data = $cursor->fetch()) { |
|
630 | + while ($data = $cursor->fetch()) { |
|
631 | 631 | $shares[] = $this->createShare($data); |
632 | 632 | } |
633 | 633 | $cursor->closeCursor(); |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | |
699 | 699 | $cursor = $qb->execute(); |
700 | 700 | |
701 | - while($data = $cursor->fetch()) { |
|
701 | + while ($data = $cursor->fetch()) { |
|
702 | 702 | if ($this->isAccessibleResult($data)) { |
703 | 703 | $shares[] = $this->createShare($data); |
704 | 704 | } |
@@ -713,7 +713,7 @@ discard block |
||
713 | 713 | $shares2 = []; |
714 | 714 | |
715 | 715 | $start = 0; |
716 | - while(true) { |
|
716 | + while (true) { |
|
717 | 717 | $groups = array_slice($allGroups, $start, 100); |
718 | 718 | $start += 100; |
719 | 719 | |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | )); |
759 | 759 | |
760 | 760 | $cursor = $qb->execute(); |
761 | - while($data = $cursor->fetch()) { |
|
761 | + while ($data = $cursor->fetch()) { |
|
762 | 762 | if ($offset > 0) { |
763 | 763 | $offset--; |
764 | 764 | continue; |
@@ -827,14 +827,14 @@ discard block |
||
827 | 827 | */ |
828 | 828 | private function createShare($data) { |
829 | 829 | $share = new Share($this->rootFolder, $this->userManager); |
830 | - $share->setId((int)$data['id']) |
|
831 | - ->setShareType((int)$data['share_type']) |
|
832 | - ->setPermissions((int)$data['permissions']) |
|
830 | + $share->setId((int) $data['id']) |
|
831 | + ->setShareType((int) $data['share_type']) |
|
832 | + ->setPermissions((int) $data['permissions']) |
|
833 | 833 | ->setTarget($data['file_target']) |
834 | - ->setMailSend((bool)$data['mail_send']); |
|
834 | + ->setMailSend((bool) $data['mail_send']); |
|
835 | 835 | |
836 | 836 | $shareTime = new \DateTime(); |
837 | - $shareTime->setTimestamp((int)$data['stime']); |
|
837 | + $shareTime->setTimestamp((int) $data['stime']); |
|
838 | 838 | $share->setShareTime($shareTime); |
839 | 839 | |
840 | 840 | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
@@ -849,7 +849,7 @@ discard block |
||
849 | 849 | $share->setSharedBy($data['uid_initiator']); |
850 | 850 | $share->setShareOwner($data['uid_owner']); |
851 | 851 | |
852 | - $share->setNodeId((int)$data['file_source']); |
|
852 | + $share->setNodeId((int) $data['file_source']); |
|
853 | 853 | $share->setNodeType($data['item_type']); |
854 | 854 | |
855 | 855 | if ($data['expiration'] !== null) { |
@@ -879,7 +879,7 @@ discard block |
||
879 | 879 | $result = []; |
880 | 880 | |
881 | 881 | $start = 0; |
882 | - while(true) { |
|
882 | + while (true) { |
|
883 | 883 | /** @var Share[] $shareSlice */ |
884 | 884 | $shareSlice = array_slice($shares, $start, 100); |
885 | 885 | $start += 100; |
@@ -894,7 +894,7 @@ discard block |
||
894 | 894 | $shareMap = []; |
895 | 895 | |
896 | 896 | foreach ($shareSlice as $share) { |
897 | - $ids[] = (int)$share->getId(); |
|
897 | + $ids[] = (int) $share->getId(); |
|
898 | 898 | $shareMap[$share->getId()] = $share; |
899 | 899 | } |
900 | 900 | |
@@ -911,8 +911,8 @@ discard block |
||
911 | 911 | |
912 | 912 | $stmt = $query->execute(); |
913 | 913 | |
914 | - while($data = $stmt->fetch()) { |
|
915 | - $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); |
|
914 | + while ($data = $stmt->fetch()) { |
|
915 | + $shareMap[$data['parent']]->setPermissions((int) $data['permissions']); |
|
916 | 916 | $shareMap[$data['parent']]->setTarget($data['file_target']); |
917 | 917 | } |
918 | 918 | |
@@ -1009,8 +1009,8 @@ discard block |
||
1009 | 1009 | |
1010 | 1010 | $cursor = $qb->execute(); |
1011 | 1011 | $ids = []; |
1012 | - while($row = $cursor->fetch()) { |
|
1013 | - $ids[] = (int)$row['id']; |
|
1012 | + while ($row = $cursor->fetch()) { |
|
1013 | + $ids[] = (int) $row['id']; |
|
1014 | 1014 | } |
1015 | 1015 | $cursor->closeCursor(); |
1016 | 1016 | |
@@ -1052,8 +1052,8 @@ discard block |
||
1052 | 1052 | |
1053 | 1053 | $cursor = $qb->execute(); |
1054 | 1054 | $ids = []; |
1055 | - while($row = $cursor->fetch()) { |
|
1056 | - $ids[] = (int)$row['id']; |
|
1055 | + while ($row = $cursor->fetch()) { |
|
1056 | + $ids[] = (int) $row['id']; |
|
1057 | 1057 | } |
1058 | 1058 | $cursor->closeCursor(); |
1059 | 1059 | |
@@ -1107,8 +1107,8 @@ discard block |
||
1107 | 1107 | |
1108 | 1108 | $users = []; |
1109 | 1109 | $link = false; |
1110 | - while($row = $cursor->fetch()) { |
|
1111 | - $type = (int)$row['share_type']; |
|
1110 | + while ($row = $cursor->fetch()) { |
|
1111 | + $type = (int) $row['share_type']; |
|
1112 | 1112 | if ($type === \OCP\Share::SHARE_TYPE_USER) { |
1113 | 1113 | $uid = $row['share_with']; |
1114 | 1114 | $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
@@ -52,1143 +52,1143 @@ |
||
52 | 52 | */ |
53 | 53 | class DefaultShareProvider implements IShareProvider { |
54 | 54 | |
55 | - // Special share type for user modified group shares |
|
56 | - const SHARE_TYPE_USERGROUP = 2; |
|
57 | - |
|
58 | - /** @var IDBConnection */ |
|
59 | - private $dbConn; |
|
60 | - |
|
61 | - /** @var IUserManager */ |
|
62 | - private $userManager; |
|
63 | - |
|
64 | - /** @var IGroupManager */ |
|
65 | - private $groupManager; |
|
66 | - |
|
67 | - /** @var IRootFolder */ |
|
68 | - private $rootFolder; |
|
69 | - |
|
70 | - /** |
|
71 | - * DefaultShareProvider constructor. |
|
72 | - * |
|
73 | - * @param IDBConnection $connection |
|
74 | - * @param IUserManager $userManager |
|
75 | - * @param IGroupManager $groupManager |
|
76 | - * @param IRootFolder $rootFolder |
|
77 | - */ |
|
78 | - public function __construct( |
|
79 | - IDBConnection $connection, |
|
80 | - IUserManager $userManager, |
|
81 | - IGroupManager $groupManager, |
|
82 | - IRootFolder $rootFolder) { |
|
83 | - $this->dbConn = $connection; |
|
84 | - $this->userManager = $userManager; |
|
85 | - $this->groupManager = $groupManager; |
|
86 | - $this->rootFolder = $rootFolder; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Return the identifier of this provider. |
|
91 | - * |
|
92 | - * @return string Containing only [a-zA-Z0-9] |
|
93 | - */ |
|
94 | - public function identifier() { |
|
95 | - return 'ocinternal'; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Share a path |
|
100 | - * |
|
101 | - * @param \OCP\Share\IShare $share |
|
102 | - * @return \OCP\Share\IShare The share object |
|
103 | - * @throws ShareNotFound |
|
104 | - * @throws \Exception |
|
105 | - */ |
|
106 | - public function create(\OCP\Share\IShare $share) { |
|
107 | - $qb = $this->dbConn->getQueryBuilder(); |
|
108 | - |
|
109 | - $qb->insert('share'); |
|
110 | - $qb->setValue('share_type', $qb->createNamedParameter($share->getShareType())); |
|
111 | - |
|
112 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
113 | - //Set the UID of the user we share with |
|
114 | - $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
115 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
116 | - //Set the GID of the group we share with |
|
117 | - $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
118 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
119 | - //Set the token of the share |
|
120 | - $qb->setValue('token', $qb->createNamedParameter($share->getToken())); |
|
121 | - |
|
122 | - //If a password is set store it |
|
123 | - if ($share->getPassword() !== null) { |
|
124 | - $qb->setValue('password', $qb->createNamedParameter($share->getPassword())); |
|
125 | - } |
|
126 | - |
|
127 | - //If an expiration date is set store it |
|
128 | - if ($share->getExpirationDate() !== null) { |
|
129 | - $qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime')); |
|
130 | - } |
|
131 | - |
|
132 | - if (method_exists($share, 'getParent')) { |
|
133 | - $qb->setValue('parent', $qb->createNamedParameter($share->getParent())); |
|
134 | - } |
|
135 | - } else { |
|
136 | - throw new \Exception('invalid share type!'); |
|
137 | - } |
|
138 | - |
|
139 | - // Set what is shares |
|
140 | - $qb->setValue('item_type', $qb->createParameter('itemType')); |
|
141 | - if ($share->getNode() instanceof \OCP\Files\File) { |
|
142 | - $qb->setParameter('itemType', 'file'); |
|
143 | - } else { |
|
144 | - $qb->setParameter('itemType', 'folder'); |
|
145 | - } |
|
146 | - |
|
147 | - // Set the file id |
|
148 | - $qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
149 | - $qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
150 | - |
|
151 | - // set the permissions |
|
152 | - $qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions())); |
|
153 | - |
|
154 | - // Set who created this share |
|
155 | - $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy())); |
|
156 | - |
|
157 | - // Set who is the owner of this file/folder (and this the owner of the share) |
|
158 | - $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner())); |
|
159 | - |
|
160 | - // Set the file target |
|
161 | - $qb->setValue('file_target', $qb->createNamedParameter($share->getTarget())); |
|
162 | - |
|
163 | - // Set the time this share was created |
|
164 | - $qb->setValue('stime', $qb->createNamedParameter(time())); |
|
165 | - |
|
166 | - // insert the data and fetch the id of the share |
|
167 | - $this->dbConn->beginTransaction(); |
|
168 | - $qb->execute(); |
|
169 | - $id = $this->dbConn->lastInsertId('*PREFIX*share'); |
|
170 | - |
|
171 | - // Now fetch the inserted share and create a complete share object |
|
172 | - $qb = $this->dbConn->getQueryBuilder(); |
|
173 | - $qb->select('*') |
|
174 | - ->from('share') |
|
175 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
176 | - |
|
177 | - $cursor = $qb->execute(); |
|
178 | - $data = $cursor->fetch(); |
|
179 | - $this->dbConn->commit(); |
|
180 | - $cursor->closeCursor(); |
|
181 | - |
|
182 | - if ($data === false) { |
|
183 | - throw new ShareNotFound(); |
|
184 | - } |
|
185 | - |
|
186 | - $mailSendValue = $share->getMailSend(); |
|
187 | - $data['mail_send'] = ($mailSendValue === null) ? true : $mailSendValue; |
|
188 | - |
|
189 | - $share = $this->createShare($data); |
|
190 | - return $share; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Update a share |
|
195 | - * |
|
196 | - * @param \OCP\Share\IShare $share |
|
197 | - * @return \OCP\Share\IShare The share object |
|
198 | - */ |
|
199 | - public function update(\OCP\Share\IShare $share) { |
|
200 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
201 | - /* |
|
55 | + // Special share type for user modified group shares |
|
56 | + const SHARE_TYPE_USERGROUP = 2; |
|
57 | + |
|
58 | + /** @var IDBConnection */ |
|
59 | + private $dbConn; |
|
60 | + |
|
61 | + /** @var IUserManager */ |
|
62 | + private $userManager; |
|
63 | + |
|
64 | + /** @var IGroupManager */ |
|
65 | + private $groupManager; |
|
66 | + |
|
67 | + /** @var IRootFolder */ |
|
68 | + private $rootFolder; |
|
69 | + |
|
70 | + /** |
|
71 | + * DefaultShareProvider constructor. |
|
72 | + * |
|
73 | + * @param IDBConnection $connection |
|
74 | + * @param IUserManager $userManager |
|
75 | + * @param IGroupManager $groupManager |
|
76 | + * @param IRootFolder $rootFolder |
|
77 | + */ |
|
78 | + public function __construct( |
|
79 | + IDBConnection $connection, |
|
80 | + IUserManager $userManager, |
|
81 | + IGroupManager $groupManager, |
|
82 | + IRootFolder $rootFolder) { |
|
83 | + $this->dbConn = $connection; |
|
84 | + $this->userManager = $userManager; |
|
85 | + $this->groupManager = $groupManager; |
|
86 | + $this->rootFolder = $rootFolder; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Return the identifier of this provider. |
|
91 | + * |
|
92 | + * @return string Containing only [a-zA-Z0-9] |
|
93 | + */ |
|
94 | + public function identifier() { |
|
95 | + return 'ocinternal'; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Share a path |
|
100 | + * |
|
101 | + * @param \OCP\Share\IShare $share |
|
102 | + * @return \OCP\Share\IShare The share object |
|
103 | + * @throws ShareNotFound |
|
104 | + * @throws \Exception |
|
105 | + */ |
|
106 | + public function create(\OCP\Share\IShare $share) { |
|
107 | + $qb = $this->dbConn->getQueryBuilder(); |
|
108 | + |
|
109 | + $qb->insert('share'); |
|
110 | + $qb->setValue('share_type', $qb->createNamedParameter($share->getShareType())); |
|
111 | + |
|
112 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
113 | + //Set the UID of the user we share with |
|
114 | + $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
115 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
116 | + //Set the GID of the group we share with |
|
117 | + $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
118 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
119 | + //Set the token of the share |
|
120 | + $qb->setValue('token', $qb->createNamedParameter($share->getToken())); |
|
121 | + |
|
122 | + //If a password is set store it |
|
123 | + if ($share->getPassword() !== null) { |
|
124 | + $qb->setValue('password', $qb->createNamedParameter($share->getPassword())); |
|
125 | + } |
|
126 | + |
|
127 | + //If an expiration date is set store it |
|
128 | + if ($share->getExpirationDate() !== null) { |
|
129 | + $qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime')); |
|
130 | + } |
|
131 | + |
|
132 | + if (method_exists($share, 'getParent')) { |
|
133 | + $qb->setValue('parent', $qb->createNamedParameter($share->getParent())); |
|
134 | + } |
|
135 | + } else { |
|
136 | + throw new \Exception('invalid share type!'); |
|
137 | + } |
|
138 | + |
|
139 | + // Set what is shares |
|
140 | + $qb->setValue('item_type', $qb->createParameter('itemType')); |
|
141 | + if ($share->getNode() instanceof \OCP\Files\File) { |
|
142 | + $qb->setParameter('itemType', 'file'); |
|
143 | + } else { |
|
144 | + $qb->setParameter('itemType', 'folder'); |
|
145 | + } |
|
146 | + |
|
147 | + // Set the file id |
|
148 | + $qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
149 | + $qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
150 | + |
|
151 | + // set the permissions |
|
152 | + $qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions())); |
|
153 | + |
|
154 | + // Set who created this share |
|
155 | + $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy())); |
|
156 | + |
|
157 | + // Set who is the owner of this file/folder (and this the owner of the share) |
|
158 | + $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner())); |
|
159 | + |
|
160 | + // Set the file target |
|
161 | + $qb->setValue('file_target', $qb->createNamedParameter($share->getTarget())); |
|
162 | + |
|
163 | + // Set the time this share was created |
|
164 | + $qb->setValue('stime', $qb->createNamedParameter(time())); |
|
165 | + |
|
166 | + // insert the data and fetch the id of the share |
|
167 | + $this->dbConn->beginTransaction(); |
|
168 | + $qb->execute(); |
|
169 | + $id = $this->dbConn->lastInsertId('*PREFIX*share'); |
|
170 | + |
|
171 | + // Now fetch the inserted share and create a complete share object |
|
172 | + $qb = $this->dbConn->getQueryBuilder(); |
|
173 | + $qb->select('*') |
|
174 | + ->from('share') |
|
175 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
176 | + |
|
177 | + $cursor = $qb->execute(); |
|
178 | + $data = $cursor->fetch(); |
|
179 | + $this->dbConn->commit(); |
|
180 | + $cursor->closeCursor(); |
|
181 | + |
|
182 | + if ($data === false) { |
|
183 | + throw new ShareNotFound(); |
|
184 | + } |
|
185 | + |
|
186 | + $mailSendValue = $share->getMailSend(); |
|
187 | + $data['mail_send'] = ($mailSendValue === null) ? true : $mailSendValue; |
|
188 | + |
|
189 | + $share = $this->createShare($data); |
|
190 | + return $share; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Update a share |
|
195 | + * |
|
196 | + * @param \OCP\Share\IShare $share |
|
197 | + * @return \OCP\Share\IShare The share object |
|
198 | + */ |
|
199 | + public function update(\OCP\Share\IShare $share) { |
|
200 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
201 | + /* |
|
202 | 202 | * We allow updating the recipient on user shares. |
203 | 203 | */ |
204 | - $qb = $this->dbConn->getQueryBuilder(); |
|
205 | - $qb->update('share') |
|
206 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
207 | - ->set('share_with', $qb->createNamedParameter($share->getSharedWith())) |
|
208 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
209 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
210 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
211 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
212 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
213 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
214 | - ->execute(); |
|
215 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
216 | - $qb = $this->dbConn->getQueryBuilder(); |
|
217 | - $qb->update('share') |
|
218 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
219 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
220 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
221 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
222 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
223 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
224 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
225 | - ->execute(); |
|
226 | - |
|
227 | - /* |
|
204 | + $qb = $this->dbConn->getQueryBuilder(); |
|
205 | + $qb->update('share') |
|
206 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
207 | + ->set('share_with', $qb->createNamedParameter($share->getSharedWith())) |
|
208 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
209 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
210 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
211 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
212 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
213 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
214 | + ->execute(); |
|
215 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
216 | + $qb = $this->dbConn->getQueryBuilder(); |
|
217 | + $qb->update('share') |
|
218 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
219 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
220 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
221 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
222 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
223 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
224 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
225 | + ->execute(); |
|
226 | + |
|
227 | + /* |
|
228 | 228 | * Update all user defined group shares |
229 | 229 | */ |
230 | - $qb = $this->dbConn->getQueryBuilder(); |
|
231 | - $qb->update('share') |
|
232 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
233 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
234 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
235 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
236 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
237 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
238 | - ->execute(); |
|
239 | - |
|
240 | - /* |
|
230 | + $qb = $this->dbConn->getQueryBuilder(); |
|
231 | + $qb->update('share') |
|
232 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
233 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
234 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
235 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
236 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
237 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
238 | + ->execute(); |
|
239 | + |
|
240 | + /* |
|
241 | 241 | * Now update the permissions for all children that have not set it to 0 |
242 | 242 | */ |
243 | - $qb = $this->dbConn->getQueryBuilder(); |
|
244 | - $qb->update('share') |
|
245 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
246 | - ->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0))) |
|
247 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
248 | - ->execute(); |
|
249 | - |
|
250 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
251 | - $qb = $this->dbConn->getQueryBuilder(); |
|
252 | - $qb->update('share') |
|
253 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
254 | - ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
255 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
256 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
257 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
258 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
259 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
260 | - ->set('token', $qb->createNamedParameter($share->getToken())) |
|
261 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
262 | - ->execute(); |
|
263 | - } |
|
264 | - |
|
265 | - return $share; |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * Get all children of this share |
|
270 | - * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
271 | - * |
|
272 | - * @param \OCP\Share\IShare $parent |
|
273 | - * @return \OCP\Share\IShare[] |
|
274 | - */ |
|
275 | - public function getChildren(\OCP\Share\IShare $parent) { |
|
276 | - $children = []; |
|
277 | - |
|
278 | - $qb = $this->dbConn->getQueryBuilder(); |
|
279 | - $qb->select('*') |
|
280 | - ->from('share') |
|
281 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
282 | - ->andWhere( |
|
283 | - $qb->expr()->in( |
|
284 | - 'share_type', |
|
285 | - $qb->createNamedParameter([ |
|
286 | - \OCP\Share::SHARE_TYPE_USER, |
|
287 | - \OCP\Share::SHARE_TYPE_GROUP, |
|
288 | - \OCP\Share::SHARE_TYPE_LINK, |
|
289 | - ], IQueryBuilder::PARAM_INT_ARRAY) |
|
290 | - ) |
|
291 | - ) |
|
292 | - ->andWhere($qb->expr()->orX( |
|
293 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
294 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
295 | - )) |
|
296 | - ->orderBy('id'); |
|
297 | - |
|
298 | - $cursor = $qb->execute(); |
|
299 | - while($data = $cursor->fetch()) { |
|
300 | - $children[] = $this->createShare($data); |
|
301 | - } |
|
302 | - $cursor->closeCursor(); |
|
303 | - |
|
304 | - return $children; |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Delete a share |
|
309 | - * |
|
310 | - * @param \OCP\Share\IShare $share |
|
311 | - */ |
|
312 | - public function delete(\OCP\Share\IShare $share) { |
|
313 | - $qb = $this->dbConn->getQueryBuilder(); |
|
314 | - $qb->delete('share') |
|
315 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))); |
|
316 | - |
|
317 | - /* |
|
243 | + $qb = $this->dbConn->getQueryBuilder(); |
|
244 | + $qb->update('share') |
|
245 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
246 | + ->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0))) |
|
247 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
248 | + ->execute(); |
|
249 | + |
|
250 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
251 | + $qb = $this->dbConn->getQueryBuilder(); |
|
252 | + $qb->update('share') |
|
253 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
254 | + ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
255 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
256 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
257 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
258 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
259 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
260 | + ->set('token', $qb->createNamedParameter($share->getToken())) |
|
261 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
262 | + ->execute(); |
|
263 | + } |
|
264 | + |
|
265 | + return $share; |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * Get all children of this share |
|
270 | + * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
271 | + * |
|
272 | + * @param \OCP\Share\IShare $parent |
|
273 | + * @return \OCP\Share\IShare[] |
|
274 | + */ |
|
275 | + public function getChildren(\OCP\Share\IShare $parent) { |
|
276 | + $children = []; |
|
277 | + |
|
278 | + $qb = $this->dbConn->getQueryBuilder(); |
|
279 | + $qb->select('*') |
|
280 | + ->from('share') |
|
281 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
282 | + ->andWhere( |
|
283 | + $qb->expr()->in( |
|
284 | + 'share_type', |
|
285 | + $qb->createNamedParameter([ |
|
286 | + \OCP\Share::SHARE_TYPE_USER, |
|
287 | + \OCP\Share::SHARE_TYPE_GROUP, |
|
288 | + \OCP\Share::SHARE_TYPE_LINK, |
|
289 | + ], IQueryBuilder::PARAM_INT_ARRAY) |
|
290 | + ) |
|
291 | + ) |
|
292 | + ->andWhere($qb->expr()->orX( |
|
293 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
294 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
295 | + )) |
|
296 | + ->orderBy('id'); |
|
297 | + |
|
298 | + $cursor = $qb->execute(); |
|
299 | + while($data = $cursor->fetch()) { |
|
300 | + $children[] = $this->createShare($data); |
|
301 | + } |
|
302 | + $cursor->closeCursor(); |
|
303 | + |
|
304 | + return $children; |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Delete a share |
|
309 | + * |
|
310 | + * @param \OCP\Share\IShare $share |
|
311 | + */ |
|
312 | + public function delete(\OCP\Share\IShare $share) { |
|
313 | + $qb = $this->dbConn->getQueryBuilder(); |
|
314 | + $qb->delete('share') |
|
315 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))); |
|
316 | + |
|
317 | + /* |
|
318 | 318 | * If the share is a group share delete all possible |
319 | 319 | * user defined groups shares. |
320 | 320 | */ |
321 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
322 | - $qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))); |
|
323 | - } |
|
324 | - |
|
325 | - $qb->execute(); |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * Unshare a share from the recipient. If this is a group share |
|
330 | - * this means we need a special entry in the share db. |
|
331 | - * |
|
332 | - * @param \OCP\Share\IShare $share |
|
333 | - * @param string $recipient UserId of recipient |
|
334 | - * @throws BackendError |
|
335 | - * @throws ProviderException |
|
336 | - */ |
|
337 | - public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) { |
|
338 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
339 | - |
|
340 | - $group = $this->groupManager->get($share->getSharedWith()); |
|
341 | - $user = $this->userManager->get($recipient); |
|
342 | - |
|
343 | - if (is_null($group)) { |
|
344 | - throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
345 | - } |
|
346 | - |
|
347 | - if (!$group->inGroup($user)) { |
|
348 | - throw new ProviderException('Recipient not in receiving group'); |
|
349 | - } |
|
350 | - |
|
351 | - // Try to fetch user specific share |
|
352 | - $qb = $this->dbConn->getQueryBuilder(); |
|
353 | - $stmt = $qb->select('*') |
|
354 | - ->from('share') |
|
355 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
356 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
357 | - ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
358 | - ->andWhere($qb->expr()->orX( |
|
359 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
360 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
361 | - )) |
|
362 | - ->execute(); |
|
363 | - |
|
364 | - $data = $stmt->fetch(); |
|
365 | - |
|
366 | - /* |
|
321 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
322 | + $qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))); |
|
323 | + } |
|
324 | + |
|
325 | + $qb->execute(); |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Unshare a share from the recipient. If this is a group share |
|
330 | + * this means we need a special entry in the share db. |
|
331 | + * |
|
332 | + * @param \OCP\Share\IShare $share |
|
333 | + * @param string $recipient UserId of recipient |
|
334 | + * @throws BackendError |
|
335 | + * @throws ProviderException |
|
336 | + */ |
|
337 | + public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) { |
|
338 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
339 | + |
|
340 | + $group = $this->groupManager->get($share->getSharedWith()); |
|
341 | + $user = $this->userManager->get($recipient); |
|
342 | + |
|
343 | + if (is_null($group)) { |
|
344 | + throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
345 | + } |
|
346 | + |
|
347 | + if (!$group->inGroup($user)) { |
|
348 | + throw new ProviderException('Recipient not in receiving group'); |
|
349 | + } |
|
350 | + |
|
351 | + // Try to fetch user specific share |
|
352 | + $qb = $this->dbConn->getQueryBuilder(); |
|
353 | + $stmt = $qb->select('*') |
|
354 | + ->from('share') |
|
355 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
356 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
357 | + ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
358 | + ->andWhere($qb->expr()->orX( |
|
359 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
360 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
361 | + )) |
|
362 | + ->execute(); |
|
363 | + |
|
364 | + $data = $stmt->fetch(); |
|
365 | + |
|
366 | + /* |
|
367 | 367 | * Check if there already is a user specific group share. |
368 | 368 | * If there is update it (if required). |
369 | 369 | */ |
370 | - if ($data === false) { |
|
371 | - $qb = $this->dbConn->getQueryBuilder(); |
|
372 | - |
|
373 | - $type = $share->getNodeType(); |
|
374 | - |
|
375 | - //Insert new share |
|
376 | - $qb->insert('share') |
|
377 | - ->values([ |
|
378 | - 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
379 | - 'share_with' => $qb->createNamedParameter($recipient), |
|
380 | - 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
381 | - 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
382 | - 'parent' => $qb->createNamedParameter($share->getId()), |
|
383 | - 'item_type' => $qb->createNamedParameter($type), |
|
384 | - 'item_source' => $qb->createNamedParameter($share->getNodeId()), |
|
385 | - 'file_source' => $qb->createNamedParameter($share->getNodeId()), |
|
386 | - 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
387 | - 'permissions' => $qb->createNamedParameter(0), |
|
388 | - 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
389 | - ])->execute(); |
|
390 | - |
|
391 | - } else if ($data['permissions'] !== 0) { |
|
392 | - |
|
393 | - // Update existing usergroup share |
|
394 | - $qb = $this->dbConn->getQueryBuilder(); |
|
395 | - $qb->update('share') |
|
396 | - ->set('permissions', $qb->createNamedParameter(0)) |
|
397 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
398 | - ->execute(); |
|
399 | - } |
|
400 | - |
|
401 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
402 | - |
|
403 | - if ($share->getSharedWith() !== $recipient) { |
|
404 | - throw new ProviderException('Recipient does not match'); |
|
405 | - } |
|
406 | - |
|
407 | - // We can just delete user and link shares |
|
408 | - $this->delete($share); |
|
409 | - } else { |
|
410 | - throw new ProviderException('Invalid shareType'); |
|
411 | - } |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * @inheritdoc |
|
416 | - */ |
|
417 | - public function move(\OCP\Share\IShare $share, $recipient) { |
|
418 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
419 | - // Just update the target |
|
420 | - $qb = $this->dbConn->getQueryBuilder(); |
|
421 | - $qb->update('share') |
|
422 | - ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
423 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
424 | - ->execute(); |
|
425 | - |
|
426 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
427 | - |
|
428 | - // Check if there is a usergroup share |
|
429 | - $qb = $this->dbConn->getQueryBuilder(); |
|
430 | - $stmt = $qb->select('id') |
|
431 | - ->from('share') |
|
432 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
433 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
434 | - ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
435 | - ->andWhere($qb->expr()->orX( |
|
436 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
437 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
438 | - )) |
|
439 | - ->setMaxResults(1) |
|
440 | - ->execute(); |
|
441 | - |
|
442 | - $data = $stmt->fetch(); |
|
443 | - $stmt->closeCursor(); |
|
444 | - |
|
445 | - if ($data === false) { |
|
446 | - // No usergroup share yet. Create one. |
|
447 | - $qb = $this->dbConn->getQueryBuilder(); |
|
448 | - $qb->insert('share') |
|
449 | - ->values([ |
|
450 | - 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
451 | - 'share_with' => $qb->createNamedParameter($recipient), |
|
452 | - 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
453 | - 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
454 | - 'parent' => $qb->createNamedParameter($share->getId()), |
|
455 | - 'item_type' => $qb->createNamedParameter($share->getNodeType()), |
|
456 | - 'item_source' => $qb->createNamedParameter($share->getNodeId()), |
|
457 | - 'file_source' => $qb->createNamedParameter($share->getNodeId()), |
|
458 | - 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
459 | - 'permissions' => $qb->createNamedParameter($share->getPermissions()), |
|
460 | - 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
461 | - ])->execute(); |
|
462 | - } else { |
|
463 | - // Already a usergroup share. Update it. |
|
464 | - $qb = $this->dbConn->getQueryBuilder(); |
|
465 | - $qb->update('share') |
|
466 | - ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
467 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
468 | - ->execute(); |
|
469 | - } |
|
470 | - } |
|
471 | - |
|
472 | - return $share; |
|
473 | - } |
|
474 | - |
|
475 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
476 | - $qb = $this->dbConn->getQueryBuilder(); |
|
477 | - $qb->select('*') |
|
478 | - ->from('share', 's') |
|
479 | - ->andWhere($qb->expr()->orX( |
|
480 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
481 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
482 | - )); |
|
483 | - |
|
484 | - $qb->andWhere($qb->expr()->orX( |
|
485 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
486 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
487 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
488 | - )); |
|
489 | - |
|
490 | - /** |
|
491 | - * Reshares for this user are shares where they are the owner. |
|
492 | - */ |
|
493 | - if ($reshares === false) { |
|
494 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
495 | - } else { |
|
496 | - $qb->andWhere( |
|
497 | - $qb->expr()->orX( |
|
498 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
499 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
500 | - ) |
|
501 | - ); |
|
502 | - } |
|
503 | - |
|
504 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
505 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
506 | - |
|
507 | - $qb->orderBy('id'); |
|
508 | - |
|
509 | - $cursor = $qb->execute(); |
|
510 | - $shares = []; |
|
511 | - while ($data = $cursor->fetch()) { |
|
512 | - $shares[$data['fileid']][] = $this->createShare($data); |
|
513 | - } |
|
514 | - $cursor->closeCursor(); |
|
515 | - |
|
516 | - return $shares; |
|
517 | - } |
|
518 | - |
|
519 | - /** |
|
520 | - * @inheritdoc |
|
521 | - */ |
|
522 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
523 | - $qb = $this->dbConn->getQueryBuilder(); |
|
524 | - $qb->select('*') |
|
525 | - ->from('share') |
|
526 | - ->andWhere($qb->expr()->orX( |
|
527 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
528 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
529 | - )); |
|
530 | - |
|
531 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType))); |
|
532 | - |
|
533 | - /** |
|
534 | - * Reshares for this user are shares where they are the owner. |
|
535 | - */ |
|
536 | - if ($reshares === false) { |
|
537 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
538 | - } else { |
|
539 | - $qb->andWhere( |
|
540 | - $qb->expr()->orX( |
|
541 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
542 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
543 | - ) |
|
544 | - ); |
|
545 | - } |
|
546 | - |
|
547 | - if ($node !== null) { |
|
548 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
549 | - } |
|
550 | - |
|
551 | - if ($limit !== -1) { |
|
552 | - $qb->setMaxResults($limit); |
|
553 | - } |
|
554 | - |
|
555 | - $qb->setFirstResult($offset); |
|
556 | - $qb->orderBy('id'); |
|
557 | - |
|
558 | - $cursor = $qb->execute(); |
|
559 | - $shares = []; |
|
560 | - while($data = $cursor->fetch()) { |
|
561 | - $shares[] = $this->createShare($data); |
|
562 | - } |
|
563 | - $cursor->closeCursor(); |
|
564 | - |
|
565 | - return $shares; |
|
566 | - } |
|
567 | - |
|
568 | - /** |
|
569 | - * @inheritdoc |
|
570 | - */ |
|
571 | - public function getShareById($id, $recipientId = null) { |
|
572 | - $qb = $this->dbConn->getQueryBuilder(); |
|
573 | - |
|
574 | - $qb->select('*') |
|
575 | - ->from('share') |
|
576 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
577 | - ->andWhere( |
|
578 | - $qb->expr()->in( |
|
579 | - 'share_type', |
|
580 | - $qb->createNamedParameter([ |
|
581 | - \OCP\Share::SHARE_TYPE_USER, |
|
582 | - \OCP\Share::SHARE_TYPE_GROUP, |
|
583 | - \OCP\Share::SHARE_TYPE_LINK, |
|
584 | - ], IQueryBuilder::PARAM_INT_ARRAY) |
|
585 | - ) |
|
586 | - ) |
|
587 | - ->andWhere($qb->expr()->orX( |
|
588 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
589 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
590 | - )); |
|
591 | - |
|
592 | - $cursor = $qb->execute(); |
|
593 | - $data = $cursor->fetch(); |
|
594 | - $cursor->closeCursor(); |
|
595 | - |
|
596 | - if ($data === false) { |
|
597 | - throw new ShareNotFound(); |
|
598 | - } |
|
599 | - |
|
600 | - try { |
|
601 | - $share = $this->createShare($data); |
|
602 | - } catch (InvalidShare $e) { |
|
603 | - throw new ShareNotFound(); |
|
604 | - } |
|
605 | - |
|
606 | - // If the recipient is set for a group share resolve to that user |
|
607 | - if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
608 | - $share = $this->resolveGroupShares([$share], $recipientId)[0]; |
|
609 | - } |
|
610 | - |
|
611 | - return $share; |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * Get shares for a given path |
|
616 | - * |
|
617 | - * @param \OCP\Files\Node $path |
|
618 | - * @return \OCP\Share\IShare[] |
|
619 | - */ |
|
620 | - public function getSharesByPath(Node $path) { |
|
621 | - $qb = $this->dbConn->getQueryBuilder(); |
|
622 | - |
|
623 | - $cursor = $qb->select('*') |
|
624 | - ->from('share') |
|
625 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
626 | - ->andWhere( |
|
627 | - $qb->expr()->orX( |
|
628 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
629 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)) |
|
630 | - ) |
|
631 | - ) |
|
632 | - ->andWhere($qb->expr()->orX( |
|
633 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
634 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
635 | - )) |
|
636 | - ->execute(); |
|
637 | - |
|
638 | - $shares = []; |
|
639 | - while($data = $cursor->fetch()) { |
|
640 | - $shares[] = $this->createShare($data); |
|
641 | - } |
|
642 | - $cursor->closeCursor(); |
|
643 | - |
|
644 | - return $shares; |
|
645 | - } |
|
646 | - |
|
647 | - /** |
|
648 | - * Returns whether the given database result can be interpreted as |
|
649 | - * a share with accessible file (not trashed, not deleted) |
|
650 | - */ |
|
651 | - private function isAccessibleResult($data) { |
|
652 | - // exclude shares leading to deleted file entries |
|
653 | - if ($data['fileid'] === null) { |
|
654 | - return false; |
|
655 | - } |
|
656 | - |
|
657 | - // exclude shares leading to trashbin on home storages |
|
658 | - $pathSections = explode('/', $data['path'], 2); |
|
659 | - // FIXME: would not detect rare md5'd home storage case properly |
|
660 | - if ($pathSections[0] !== 'files' |
|
661 | - && in_array(explode(':', $data['storage_string_id'], 2)[0], array('home', 'object'))) { |
|
662 | - return false; |
|
663 | - } |
|
664 | - return true; |
|
665 | - } |
|
666 | - |
|
667 | - /** |
|
668 | - * @inheritdoc |
|
669 | - */ |
|
670 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
671 | - /** @var Share[] $shares */ |
|
672 | - $shares = []; |
|
673 | - |
|
674 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
675 | - //Get shares directly with this user |
|
676 | - $qb = $this->dbConn->getQueryBuilder(); |
|
677 | - $qb->select('s.*', |
|
678 | - 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
679 | - 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
680 | - 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
681 | - ) |
|
682 | - ->selectAlias('st.id', 'storage_string_id') |
|
683 | - ->from('share', 's') |
|
684 | - ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
685 | - ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')); |
|
686 | - |
|
687 | - // Order by id |
|
688 | - $qb->orderBy('s.id'); |
|
689 | - |
|
690 | - // Set limit and offset |
|
691 | - if ($limit !== -1) { |
|
692 | - $qb->setMaxResults($limit); |
|
693 | - } |
|
694 | - $qb->setFirstResult($offset); |
|
695 | - |
|
696 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))) |
|
697 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
698 | - ->andWhere($qb->expr()->orX( |
|
699 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
700 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
701 | - )); |
|
702 | - |
|
703 | - // Filter by node if provided |
|
704 | - if ($node !== null) { |
|
705 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
706 | - } |
|
707 | - |
|
708 | - $cursor = $qb->execute(); |
|
709 | - |
|
710 | - while($data = $cursor->fetch()) { |
|
711 | - if ($this->isAccessibleResult($data)) { |
|
712 | - $shares[] = $this->createShare($data); |
|
713 | - } |
|
714 | - } |
|
715 | - $cursor->closeCursor(); |
|
716 | - |
|
717 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
718 | - $user = $this->userManager->get($userId); |
|
719 | - $allGroups = $this->groupManager->getUserGroups($user); |
|
720 | - |
|
721 | - /** @var Share[] $shares2 */ |
|
722 | - $shares2 = []; |
|
723 | - |
|
724 | - $start = 0; |
|
725 | - while(true) { |
|
726 | - $groups = array_slice($allGroups, $start, 100); |
|
727 | - $start += 100; |
|
728 | - |
|
729 | - if ($groups === []) { |
|
730 | - break; |
|
731 | - } |
|
732 | - |
|
733 | - $qb = $this->dbConn->getQueryBuilder(); |
|
734 | - $qb->select('s.*', |
|
735 | - 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
736 | - 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
737 | - 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
738 | - ) |
|
739 | - ->selectAlias('st.id', 'storage_string_id') |
|
740 | - ->from('share', 's') |
|
741 | - ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
742 | - ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')) |
|
743 | - ->orderBy('s.id') |
|
744 | - ->setFirstResult(0); |
|
745 | - |
|
746 | - if ($limit !== -1) { |
|
747 | - $qb->setMaxResults($limit - count($shares)); |
|
748 | - } |
|
749 | - |
|
750 | - // Filter by node if provided |
|
751 | - if ($node !== null) { |
|
752 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
753 | - } |
|
754 | - |
|
755 | - |
|
756 | - $groups = array_filter($groups, function($group) { return $group instanceof IGroup; }); |
|
757 | - $groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups); |
|
758 | - |
|
759 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
760 | - ->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter( |
|
761 | - $groups, |
|
762 | - IQueryBuilder::PARAM_STR_ARRAY |
|
763 | - ))) |
|
764 | - ->andWhere($qb->expr()->orX( |
|
765 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
766 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
767 | - )); |
|
768 | - |
|
769 | - $cursor = $qb->execute(); |
|
770 | - while($data = $cursor->fetch()) { |
|
771 | - if ($offset > 0) { |
|
772 | - $offset--; |
|
773 | - continue; |
|
774 | - } |
|
775 | - |
|
776 | - if ($this->isAccessibleResult($data)) { |
|
777 | - $shares2[] = $this->createShare($data); |
|
778 | - } |
|
779 | - } |
|
780 | - $cursor->closeCursor(); |
|
781 | - } |
|
782 | - |
|
783 | - /* |
|
370 | + if ($data === false) { |
|
371 | + $qb = $this->dbConn->getQueryBuilder(); |
|
372 | + |
|
373 | + $type = $share->getNodeType(); |
|
374 | + |
|
375 | + //Insert new share |
|
376 | + $qb->insert('share') |
|
377 | + ->values([ |
|
378 | + 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
379 | + 'share_with' => $qb->createNamedParameter($recipient), |
|
380 | + 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
381 | + 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
382 | + 'parent' => $qb->createNamedParameter($share->getId()), |
|
383 | + 'item_type' => $qb->createNamedParameter($type), |
|
384 | + 'item_source' => $qb->createNamedParameter($share->getNodeId()), |
|
385 | + 'file_source' => $qb->createNamedParameter($share->getNodeId()), |
|
386 | + 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
387 | + 'permissions' => $qb->createNamedParameter(0), |
|
388 | + 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
389 | + ])->execute(); |
|
390 | + |
|
391 | + } else if ($data['permissions'] !== 0) { |
|
392 | + |
|
393 | + // Update existing usergroup share |
|
394 | + $qb = $this->dbConn->getQueryBuilder(); |
|
395 | + $qb->update('share') |
|
396 | + ->set('permissions', $qb->createNamedParameter(0)) |
|
397 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
398 | + ->execute(); |
|
399 | + } |
|
400 | + |
|
401 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
402 | + |
|
403 | + if ($share->getSharedWith() !== $recipient) { |
|
404 | + throw new ProviderException('Recipient does not match'); |
|
405 | + } |
|
406 | + |
|
407 | + // We can just delete user and link shares |
|
408 | + $this->delete($share); |
|
409 | + } else { |
|
410 | + throw new ProviderException('Invalid shareType'); |
|
411 | + } |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * @inheritdoc |
|
416 | + */ |
|
417 | + public function move(\OCP\Share\IShare $share, $recipient) { |
|
418 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
419 | + // Just update the target |
|
420 | + $qb = $this->dbConn->getQueryBuilder(); |
|
421 | + $qb->update('share') |
|
422 | + ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
423 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
424 | + ->execute(); |
|
425 | + |
|
426 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
427 | + |
|
428 | + // Check if there is a usergroup share |
|
429 | + $qb = $this->dbConn->getQueryBuilder(); |
|
430 | + $stmt = $qb->select('id') |
|
431 | + ->from('share') |
|
432 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
433 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
434 | + ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
435 | + ->andWhere($qb->expr()->orX( |
|
436 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
437 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
438 | + )) |
|
439 | + ->setMaxResults(1) |
|
440 | + ->execute(); |
|
441 | + |
|
442 | + $data = $stmt->fetch(); |
|
443 | + $stmt->closeCursor(); |
|
444 | + |
|
445 | + if ($data === false) { |
|
446 | + // No usergroup share yet. Create one. |
|
447 | + $qb = $this->dbConn->getQueryBuilder(); |
|
448 | + $qb->insert('share') |
|
449 | + ->values([ |
|
450 | + 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
451 | + 'share_with' => $qb->createNamedParameter($recipient), |
|
452 | + 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
453 | + 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
454 | + 'parent' => $qb->createNamedParameter($share->getId()), |
|
455 | + 'item_type' => $qb->createNamedParameter($share->getNodeType()), |
|
456 | + 'item_source' => $qb->createNamedParameter($share->getNodeId()), |
|
457 | + 'file_source' => $qb->createNamedParameter($share->getNodeId()), |
|
458 | + 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
459 | + 'permissions' => $qb->createNamedParameter($share->getPermissions()), |
|
460 | + 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
461 | + ])->execute(); |
|
462 | + } else { |
|
463 | + // Already a usergroup share. Update it. |
|
464 | + $qb = $this->dbConn->getQueryBuilder(); |
|
465 | + $qb->update('share') |
|
466 | + ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
467 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
468 | + ->execute(); |
|
469 | + } |
|
470 | + } |
|
471 | + |
|
472 | + return $share; |
|
473 | + } |
|
474 | + |
|
475 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
476 | + $qb = $this->dbConn->getQueryBuilder(); |
|
477 | + $qb->select('*') |
|
478 | + ->from('share', 's') |
|
479 | + ->andWhere($qb->expr()->orX( |
|
480 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
481 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
482 | + )); |
|
483 | + |
|
484 | + $qb->andWhere($qb->expr()->orX( |
|
485 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
486 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
487 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
488 | + )); |
|
489 | + |
|
490 | + /** |
|
491 | + * Reshares for this user are shares where they are the owner. |
|
492 | + */ |
|
493 | + if ($reshares === false) { |
|
494 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
495 | + } else { |
|
496 | + $qb->andWhere( |
|
497 | + $qb->expr()->orX( |
|
498 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
499 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
500 | + ) |
|
501 | + ); |
|
502 | + } |
|
503 | + |
|
504 | + $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
505 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
506 | + |
|
507 | + $qb->orderBy('id'); |
|
508 | + |
|
509 | + $cursor = $qb->execute(); |
|
510 | + $shares = []; |
|
511 | + while ($data = $cursor->fetch()) { |
|
512 | + $shares[$data['fileid']][] = $this->createShare($data); |
|
513 | + } |
|
514 | + $cursor->closeCursor(); |
|
515 | + |
|
516 | + return $shares; |
|
517 | + } |
|
518 | + |
|
519 | + /** |
|
520 | + * @inheritdoc |
|
521 | + */ |
|
522 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
523 | + $qb = $this->dbConn->getQueryBuilder(); |
|
524 | + $qb->select('*') |
|
525 | + ->from('share') |
|
526 | + ->andWhere($qb->expr()->orX( |
|
527 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
528 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
529 | + )); |
|
530 | + |
|
531 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType))); |
|
532 | + |
|
533 | + /** |
|
534 | + * Reshares for this user are shares where they are the owner. |
|
535 | + */ |
|
536 | + if ($reshares === false) { |
|
537 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
538 | + } else { |
|
539 | + $qb->andWhere( |
|
540 | + $qb->expr()->orX( |
|
541 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
542 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
543 | + ) |
|
544 | + ); |
|
545 | + } |
|
546 | + |
|
547 | + if ($node !== null) { |
|
548 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
549 | + } |
|
550 | + |
|
551 | + if ($limit !== -1) { |
|
552 | + $qb->setMaxResults($limit); |
|
553 | + } |
|
554 | + |
|
555 | + $qb->setFirstResult($offset); |
|
556 | + $qb->orderBy('id'); |
|
557 | + |
|
558 | + $cursor = $qb->execute(); |
|
559 | + $shares = []; |
|
560 | + while($data = $cursor->fetch()) { |
|
561 | + $shares[] = $this->createShare($data); |
|
562 | + } |
|
563 | + $cursor->closeCursor(); |
|
564 | + |
|
565 | + return $shares; |
|
566 | + } |
|
567 | + |
|
568 | + /** |
|
569 | + * @inheritdoc |
|
570 | + */ |
|
571 | + public function getShareById($id, $recipientId = null) { |
|
572 | + $qb = $this->dbConn->getQueryBuilder(); |
|
573 | + |
|
574 | + $qb->select('*') |
|
575 | + ->from('share') |
|
576 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
577 | + ->andWhere( |
|
578 | + $qb->expr()->in( |
|
579 | + 'share_type', |
|
580 | + $qb->createNamedParameter([ |
|
581 | + \OCP\Share::SHARE_TYPE_USER, |
|
582 | + \OCP\Share::SHARE_TYPE_GROUP, |
|
583 | + \OCP\Share::SHARE_TYPE_LINK, |
|
584 | + ], IQueryBuilder::PARAM_INT_ARRAY) |
|
585 | + ) |
|
586 | + ) |
|
587 | + ->andWhere($qb->expr()->orX( |
|
588 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
589 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
590 | + )); |
|
591 | + |
|
592 | + $cursor = $qb->execute(); |
|
593 | + $data = $cursor->fetch(); |
|
594 | + $cursor->closeCursor(); |
|
595 | + |
|
596 | + if ($data === false) { |
|
597 | + throw new ShareNotFound(); |
|
598 | + } |
|
599 | + |
|
600 | + try { |
|
601 | + $share = $this->createShare($data); |
|
602 | + } catch (InvalidShare $e) { |
|
603 | + throw new ShareNotFound(); |
|
604 | + } |
|
605 | + |
|
606 | + // If the recipient is set for a group share resolve to that user |
|
607 | + if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
608 | + $share = $this->resolveGroupShares([$share], $recipientId)[0]; |
|
609 | + } |
|
610 | + |
|
611 | + return $share; |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * Get shares for a given path |
|
616 | + * |
|
617 | + * @param \OCP\Files\Node $path |
|
618 | + * @return \OCP\Share\IShare[] |
|
619 | + */ |
|
620 | + public function getSharesByPath(Node $path) { |
|
621 | + $qb = $this->dbConn->getQueryBuilder(); |
|
622 | + |
|
623 | + $cursor = $qb->select('*') |
|
624 | + ->from('share') |
|
625 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
626 | + ->andWhere( |
|
627 | + $qb->expr()->orX( |
|
628 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
629 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)) |
|
630 | + ) |
|
631 | + ) |
|
632 | + ->andWhere($qb->expr()->orX( |
|
633 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
634 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
635 | + )) |
|
636 | + ->execute(); |
|
637 | + |
|
638 | + $shares = []; |
|
639 | + while($data = $cursor->fetch()) { |
|
640 | + $shares[] = $this->createShare($data); |
|
641 | + } |
|
642 | + $cursor->closeCursor(); |
|
643 | + |
|
644 | + return $shares; |
|
645 | + } |
|
646 | + |
|
647 | + /** |
|
648 | + * Returns whether the given database result can be interpreted as |
|
649 | + * a share with accessible file (not trashed, not deleted) |
|
650 | + */ |
|
651 | + private function isAccessibleResult($data) { |
|
652 | + // exclude shares leading to deleted file entries |
|
653 | + if ($data['fileid'] === null) { |
|
654 | + return false; |
|
655 | + } |
|
656 | + |
|
657 | + // exclude shares leading to trashbin on home storages |
|
658 | + $pathSections = explode('/', $data['path'], 2); |
|
659 | + // FIXME: would not detect rare md5'd home storage case properly |
|
660 | + if ($pathSections[0] !== 'files' |
|
661 | + && in_array(explode(':', $data['storage_string_id'], 2)[0], array('home', 'object'))) { |
|
662 | + return false; |
|
663 | + } |
|
664 | + return true; |
|
665 | + } |
|
666 | + |
|
667 | + /** |
|
668 | + * @inheritdoc |
|
669 | + */ |
|
670 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
671 | + /** @var Share[] $shares */ |
|
672 | + $shares = []; |
|
673 | + |
|
674 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
675 | + //Get shares directly with this user |
|
676 | + $qb = $this->dbConn->getQueryBuilder(); |
|
677 | + $qb->select('s.*', |
|
678 | + 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
679 | + 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
680 | + 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
681 | + ) |
|
682 | + ->selectAlias('st.id', 'storage_string_id') |
|
683 | + ->from('share', 's') |
|
684 | + ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
685 | + ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')); |
|
686 | + |
|
687 | + // Order by id |
|
688 | + $qb->orderBy('s.id'); |
|
689 | + |
|
690 | + // Set limit and offset |
|
691 | + if ($limit !== -1) { |
|
692 | + $qb->setMaxResults($limit); |
|
693 | + } |
|
694 | + $qb->setFirstResult($offset); |
|
695 | + |
|
696 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))) |
|
697 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
698 | + ->andWhere($qb->expr()->orX( |
|
699 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
700 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
701 | + )); |
|
702 | + |
|
703 | + // Filter by node if provided |
|
704 | + if ($node !== null) { |
|
705 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
706 | + } |
|
707 | + |
|
708 | + $cursor = $qb->execute(); |
|
709 | + |
|
710 | + while($data = $cursor->fetch()) { |
|
711 | + if ($this->isAccessibleResult($data)) { |
|
712 | + $shares[] = $this->createShare($data); |
|
713 | + } |
|
714 | + } |
|
715 | + $cursor->closeCursor(); |
|
716 | + |
|
717 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
718 | + $user = $this->userManager->get($userId); |
|
719 | + $allGroups = $this->groupManager->getUserGroups($user); |
|
720 | + |
|
721 | + /** @var Share[] $shares2 */ |
|
722 | + $shares2 = []; |
|
723 | + |
|
724 | + $start = 0; |
|
725 | + while(true) { |
|
726 | + $groups = array_slice($allGroups, $start, 100); |
|
727 | + $start += 100; |
|
728 | + |
|
729 | + if ($groups === []) { |
|
730 | + break; |
|
731 | + } |
|
732 | + |
|
733 | + $qb = $this->dbConn->getQueryBuilder(); |
|
734 | + $qb->select('s.*', |
|
735 | + 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
736 | + 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
737 | + 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
738 | + ) |
|
739 | + ->selectAlias('st.id', 'storage_string_id') |
|
740 | + ->from('share', 's') |
|
741 | + ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
742 | + ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')) |
|
743 | + ->orderBy('s.id') |
|
744 | + ->setFirstResult(0); |
|
745 | + |
|
746 | + if ($limit !== -1) { |
|
747 | + $qb->setMaxResults($limit - count($shares)); |
|
748 | + } |
|
749 | + |
|
750 | + // Filter by node if provided |
|
751 | + if ($node !== null) { |
|
752 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
753 | + } |
|
754 | + |
|
755 | + |
|
756 | + $groups = array_filter($groups, function($group) { return $group instanceof IGroup; }); |
|
757 | + $groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups); |
|
758 | + |
|
759 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
760 | + ->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter( |
|
761 | + $groups, |
|
762 | + IQueryBuilder::PARAM_STR_ARRAY |
|
763 | + ))) |
|
764 | + ->andWhere($qb->expr()->orX( |
|
765 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
766 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
767 | + )); |
|
768 | + |
|
769 | + $cursor = $qb->execute(); |
|
770 | + while($data = $cursor->fetch()) { |
|
771 | + if ($offset > 0) { |
|
772 | + $offset--; |
|
773 | + continue; |
|
774 | + } |
|
775 | + |
|
776 | + if ($this->isAccessibleResult($data)) { |
|
777 | + $shares2[] = $this->createShare($data); |
|
778 | + } |
|
779 | + } |
|
780 | + $cursor->closeCursor(); |
|
781 | + } |
|
782 | + |
|
783 | + /* |
|
784 | 784 | * Resolve all group shares to user specific shares |
785 | 785 | */ |
786 | - $shares = $this->resolveGroupShares($shares2, $userId); |
|
787 | - } else { |
|
788 | - throw new BackendError('Invalid backend'); |
|
789 | - } |
|
790 | - |
|
791 | - |
|
792 | - return $shares; |
|
793 | - } |
|
794 | - |
|
795 | - /** |
|
796 | - * Get a share by token |
|
797 | - * |
|
798 | - * @param string $token |
|
799 | - * @return \OCP\Share\IShare |
|
800 | - * @throws ShareNotFound |
|
801 | - */ |
|
802 | - public function getShareByToken($token) { |
|
803 | - $qb = $this->dbConn->getQueryBuilder(); |
|
804 | - |
|
805 | - $cursor = $qb->select('*') |
|
806 | - ->from('share') |
|
807 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))) |
|
808 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
809 | - ->andWhere($qb->expr()->orX( |
|
810 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
811 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
812 | - )) |
|
813 | - ->execute(); |
|
814 | - |
|
815 | - $data = $cursor->fetch(); |
|
816 | - |
|
817 | - if ($data === false) { |
|
818 | - throw new ShareNotFound(); |
|
819 | - } |
|
820 | - |
|
821 | - try { |
|
822 | - $share = $this->createShare($data); |
|
823 | - } catch (InvalidShare $e) { |
|
824 | - throw new ShareNotFound(); |
|
825 | - } |
|
826 | - |
|
827 | - return $share; |
|
828 | - } |
|
829 | - |
|
830 | - /** |
|
831 | - * Create a share object from an database row |
|
832 | - * |
|
833 | - * @param mixed[] $data |
|
834 | - * @return \OCP\Share\IShare |
|
835 | - * @throws InvalidShare |
|
836 | - */ |
|
837 | - private function createShare($data) { |
|
838 | - $share = new Share($this->rootFolder, $this->userManager); |
|
839 | - $share->setId((int)$data['id']) |
|
840 | - ->setShareType((int)$data['share_type']) |
|
841 | - ->setPermissions((int)$data['permissions']) |
|
842 | - ->setTarget($data['file_target']) |
|
843 | - ->setMailSend((bool)$data['mail_send']); |
|
844 | - |
|
845 | - $shareTime = new \DateTime(); |
|
846 | - $shareTime->setTimestamp((int)$data['stime']); |
|
847 | - $share->setShareTime($shareTime); |
|
848 | - |
|
849 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
850 | - $share->setSharedWith($data['share_with']); |
|
851 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
852 | - $share->setSharedWith($data['share_with']); |
|
853 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
854 | - $share->setPassword($data['password']); |
|
855 | - $share->setToken($data['token']); |
|
856 | - } |
|
857 | - |
|
858 | - $share->setSharedBy($data['uid_initiator']); |
|
859 | - $share->setShareOwner($data['uid_owner']); |
|
860 | - |
|
861 | - $share->setNodeId((int)$data['file_source']); |
|
862 | - $share->setNodeType($data['item_type']); |
|
863 | - |
|
864 | - if ($data['expiration'] !== null) { |
|
865 | - $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
866 | - $share->setExpirationDate($expiration); |
|
867 | - } |
|
868 | - |
|
869 | - if (isset($data['f_permissions'])) { |
|
870 | - $entryData = $data; |
|
871 | - $entryData['permissions'] = $entryData['f_permissions']; |
|
872 | - $entryData['parent'] = $entryData['f_parent']; |
|
873 | - $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, |
|
874 | - \OC::$server->getMimeTypeLoader())); |
|
875 | - } |
|
876 | - |
|
877 | - $share->setProviderId($this->identifier()); |
|
878 | - |
|
879 | - return $share; |
|
880 | - } |
|
881 | - |
|
882 | - /** |
|
883 | - * @param Share[] $shares |
|
884 | - * @param $userId |
|
885 | - * @return Share[] The updates shares if no update is found for a share return the original |
|
886 | - */ |
|
887 | - private function resolveGroupShares($shares, $userId) { |
|
888 | - $result = []; |
|
889 | - |
|
890 | - $start = 0; |
|
891 | - while(true) { |
|
892 | - /** @var Share[] $shareSlice */ |
|
893 | - $shareSlice = array_slice($shares, $start, 100); |
|
894 | - $start += 100; |
|
895 | - |
|
896 | - if ($shareSlice === []) { |
|
897 | - break; |
|
898 | - } |
|
899 | - |
|
900 | - /** @var int[] $ids */ |
|
901 | - $ids = []; |
|
902 | - /** @var Share[] $shareMap */ |
|
903 | - $shareMap = []; |
|
904 | - |
|
905 | - foreach ($shareSlice as $share) { |
|
906 | - $ids[] = (int)$share->getId(); |
|
907 | - $shareMap[$share->getId()] = $share; |
|
908 | - } |
|
909 | - |
|
910 | - $qb = $this->dbConn->getQueryBuilder(); |
|
911 | - |
|
912 | - $query = $qb->select('*') |
|
913 | - ->from('share') |
|
914 | - ->where($qb->expr()->in('parent', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
915 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
916 | - ->andWhere($qb->expr()->orX( |
|
917 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
918 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
919 | - )); |
|
920 | - |
|
921 | - $stmt = $query->execute(); |
|
922 | - |
|
923 | - while($data = $stmt->fetch()) { |
|
924 | - $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); |
|
925 | - $shareMap[$data['parent']]->setTarget($data['file_target']); |
|
926 | - } |
|
927 | - |
|
928 | - $stmt->closeCursor(); |
|
929 | - |
|
930 | - foreach ($shareMap as $share) { |
|
931 | - $result[] = $share; |
|
932 | - } |
|
933 | - } |
|
934 | - |
|
935 | - return $result; |
|
936 | - } |
|
937 | - |
|
938 | - /** |
|
939 | - * A user is deleted from the system |
|
940 | - * So clean up the relevant shares. |
|
941 | - * |
|
942 | - * @param string $uid |
|
943 | - * @param int $shareType |
|
944 | - */ |
|
945 | - public function userDeleted($uid, $shareType) { |
|
946 | - $qb = $this->dbConn->getQueryBuilder(); |
|
947 | - |
|
948 | - $qb->delete('share'); |
|
949 | - |
|
950 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
951 | - /* |
|
786 | + $shares = $this->resolveGroupShares($shares2, $userId); |
|
787 | + } else { |
|
788 | + throw new BackendError('Invalid backend'); |
|
789 | + } |
|
790 | + |
|
791 | + |
|
792 | + return $shares; |
|
793 | + } |
|
794 | + |
|
795 | + /** |
|
796 | + * Get a share by token |
|
797 | + * |
|
798 | + * @param string $token |
|
799 | + * @return \OCP\Share\IShare |
|
800 | + * @throws ShareNotFound |
|
801 | + */ |
|
802 | + public function getShareByToken($token) { |
|
803 | + $qb = $this->dbConn->getQueryBuilder(); |
|
804 | + |
|
805 | + $cursor = $qb->select('*') |
|
806 | + ->from('share') |
|
807 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))) |
|
808 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
809 | + ->andWhere($qb->expr()->orX( |
|
810 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
811 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
812 | + )) |
|
813 | + ->execute(); |
|
814 | + |
|
815 | + $data = $cursor->fetch(); |
|
816 | + |
|
817 | + if ($data === false) { |
|
818 | + throw new ShareNotFound(); |
|
819 | + } |
|
820 | + |
|
821 | + try { |
|
822 | + $share = $this->createShare($data); |
|
823 | + } catch (InvalidShare $e) { |
|
824 | + throw new ShareNotFound(); |
|
825 | + } |
|
826 | + |
|
827 | + return $share; |
|
828 | + } |
|
829 | + |
|
830 | + /** |
|
831 | + * Create a share object from an database row |
|
832 | + * |
|
833 | + * @param mixed[] $data |
|
834 | + * @return \OCP\Share\IShare |
|
835 | + * @throws InvalidShare |
|
836 | + */ |
|
837 | + private function createShare($data) { |
|
838 | + $share = new Share($this->rootFolder, $this->userManager); |
|
839 | + $share->setId((int)$data['id']) |
|
840 | + ->setShareType((int)$data['share_type']) |
|
841 | + ->setPermissions((int)$data['permissions']) |
|
842 | + ->setTarget($data['file_target']) |
|
843 | + ->setMailSend((bool)$data['mail_send']); |
|
844 | + |
|
845 | + $shareTime = new \DateTime(); |
|
846 | + $shareTime->setTimestamp((int)$data['stime']); |
|
847 | + $share->setShareTime($shareTime); |
|
848 | + |
|
849 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
850 | + $share->setSharedWith($data['share_with']); |
|
851 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
852 | + $share->setSharedWith($data['share_with']); |
|
853 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
854 | + $share->setPassword($data['password']); |
|
855 | + $share->setToken($data['token']); |
|
856 | + } |
|
857 | + |
|
858 | + $share->setSharedBy($data['uid_initiator']); |
|
859 | + $share->setShareOwner($data['uid_owner']); |
|
860 | + |
|
861 | + $share->setNodeId((int)$data['file_source']); |
|
862 | + $share->setNodeType($data['item_type']); |
|
863 | + |
|
864 | + if ($data['expiration'] !== null) { |
|
865 | + $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
866 | + $share->setExpirationDate($expiration); |
|
867 | + } |
|
868 | + |
|
869 | + if (isset($data['f_permissions'])) { |
|
870 | + $entryData = $data; |
|
871 | + $entryData['permissions'] = $entryData['f_permissions']; |
|
872 | + $entryData['parent'] = $entryData['f_parent']; |
|
873 | + $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, |
|
874 | + \OC::$server->getMimeTypeLoader())); |
|
875 | + } |
|
876 | + |
|
877 | + $share->setProviderId($this->identifier()); |
|
878 | + |
|
879 | + return $share; |
|
880 | + } |
|
881 | + |
|
882 | + /** |
|
883 | + * @param Share[] $shares |
|
884 | + * @param $userId |
|
885 | + * @return Share[] The updates shares if no update is found for a share return the original |
|
886 | + */ |
|
887 | + private function resolveGroupShares($shares, $userId) { |
|
888 | + $result = []; |
|
889 | + |
|
890 | + $start = 0; |
|
891 | + while(true) { |
|
892 | + /** @var Share[] $shareSlice */ |
|
893 | + $shareSlice = array_slice($shares, $start, 100); |
|
894 | + $start += 100; |
|
895 | + |
|
896 | + if ($shareSlice === []) { |
|
897 | + break; |
|
898 | + } |
|
899 | + |
|
900 | + /** @var int[] $ids */ |
|
901 | + $ids = []; |
|
902 | + /** @var Share[] $shareMap */ |
|
903 | + $shareMap = []; |
|
904 | + |
|
905 | + foreach ($shareSlice as $share) { |
|
906 | + $ids[] = (int)$share->getId(); |
|
907 | + $shareMap[$share->getId()] = $share; |
|
908 | + } |
|
909 | + |
|
910 | + $qb = $this->dbConn->getQueryBuilder(); |
|
911 | + |
|
912 | + $query = $qb->select('*') |
|
913 | + ->from('share') |
|
914 | + ->where($qb->expr()->in('parent', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
915 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
916 | + ->andWhere($qb->expr()->orX( |
|
917 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
918 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
919 | + )); |
|
920 | + |
|
921 | + $stmt = $query->execute(); |
|
922 | + |
|
923 | + while($data = $stmt->fetch()) { |
|
924 | + $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); |
|
925 | + $shareMap[$data['parent']]->setTarget($data['file_target']); |
|
926 | + } |
|
927 | + |
|
928 | + $stmt->closeCursor(); |
|
929 | + |
|
930 | + foreach ($shareMap as $share) { |
|
931 | + $result[] = $share; |
|
932 | + } |
|
933 | + } |
|
934 | + |
|
935 | + return $result; |
|
936 | + } |
|
937 | + |
|
938 | + /** |
|
939 | + * A user is deleted from the system |
|
940 | + * So clean up the relevant shares. |
|
941 | + * |
|
942 | + * @param string $uid |
|
943 | + * @param int $shareType |
|
944 | + */ |
|
945 | + public function userDeleted($uid, $shareType) { |
|
946 | + $qb = $this->dbConn->getQueryBuilder(); |
|
947 | + |
|
948 | + $qb->delete('share'); |
|
949 | + |
|
950 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
951 | + /* |
|
952 | 952 | * Delete all user shares that are owned by this user |
953 | 953 | * or that are received by this user |
954 | 954 | */ |
955 | 955 | |
956 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))); |
|
956 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))); |
|
957 | 957 | |
958 | - $qb->andWhere( |
|
959 | - $qb->expr()->orX( |
|
960 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
961 | - $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
962 | - ) |
|
963 | - ); |
|
964 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
965 | - /* |
|
958 | + $qb->andWhere( |
|
959 | + $qb->expr()->orX( |
|
960 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
961 | + $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
962 | + ) |
|
963 | + ); |
|
964 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
965 | + /* |
|
966 | 966 | * Delete all group shares that are owned by this user |
967 | 967 | * Or special user group shares that are received by this user |
968 | 968 | */ |
969 | - $qb->where( |
|
970 | - $qb->expr()->andX( |
|
971 | - $qb->expr()->orX( |
|
972 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
973 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)) |
|
974 | - ), |
|
975 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)) |
|
976 | - ) |
|
977 | - ); |
|
978 | - |
|
979 | - $qb->orWhere( |
|
980 | - $qb->expr()->andX( |
|
981 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)), |
|
982 | - $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
983 | - ) |
|
984 | - ); |
|
985 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
986 | - /* |
|
969 | + $qb->where( |
|
970 | + $qb->expr()->andX( |
|
971 | + $qb->expr()->orX( |
|
972 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
973 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)) |
|
974 | + ), |
|
975 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)) |
|
976 | + ) |
|
977 | + ); |
|
978 | + |
|
979 | + $qb->orWhere( |
|
980 | + $qb->expr()->andX( |
|
981 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)), |
|
982 | + $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
983 | + ) |
|
984 | + ); |
|
985 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
986 | + /* |
|
987 | 987 | * Delete all link shares owned by this user. |
988 | 988 | * And all link shares initiated by this user (until #22327 is in) |
989 | 989 | */ |
990 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))); |
|
991 | - |
|
992 | - $qb->andWhere( |
|
993 | - $qb->expr()->orX( |
|
994 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
995 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($uid)) |
|
996 | - ) |
|
997 | - ); |
|
998 | - } |
|
999 | - |
|
1000 | - $qb->execute(); |
|
1001 | - } |
|
1002 | - |
|
1003 | - /** |
|
1004 | - * Delete all shares received by this group. As well as any custom group |
|
1005 | - * shares for group members. |
|
1006 | - * |
|
1007 | - * @param string $gid |
|
1008 | - */ |
|
1009 | - public function groupDeleted($gid) { |
|
1010 | - /* |
|
990 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))); |
|
991 | + |
|
992 | + $qb->andWhere( |
|
993 | + $qb->expr()->orX( |
|
994 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
995 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($uid)) |
|
996 | + ) |
|
997 | + ); |
|
998 | + } |
|
999 | + |
|
1000 | + $qb->execute(); |
|
1001 | + } |
|
1002 | + |
|
1003 | + /** |
|
1004 | + * Delete all shares received by this group. As well as any custom group |
|
1005 | + * shares for group members. |
|
1006 | + * |
|
1007 | + * @param string $gid |
|
1008 | + */ |
|
1009 | + public function groupDeleted($gid) { |
|
1010 | + /* |
|
1011 | 1011 | * First delete all custom group shares for group members |
1012 | 1012 | */ |
1013 | - $qb = $this->dbConn->getQueryBuilder(); |
|
1014 | - $qb->select('id') |
|
1015 | - ->from('share') |
|
1016 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1017 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1018 | - |
|
1019 | - $cursor = $qb->execute(); |
|
1020 | - $ids = []; |
|
1021 | - while($row = $cursor->fetch()) { |
|
1022 | - $ids[] = (int)$row['id']; |
|
1023 | - } |
|
1024 | - $cursor->closeCursor(); |
|
1025 | - |
|
1026 | - if (!empty($ids)) { |
|
1027 | - $chunks = array_chunk($ids, 100); |
|
1028 | - foreach ($chunks as $chunk) { |
|
1029 | - $qb->delete('share') |
|
1030 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
1031 | - ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
1032 | - $qb->execute(); |
|
1033 | - } |
|
1034 | - } |
|
1035 | - |
|
1036 | - /* |
|
1013 | + $qb = $this->dbConn->getQueryBuilder(); |
|
1014 | + $qb->select('id') |
|
1015 | + ->from('share') |
|
1016 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1017 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1018 | + |
|
1019 | + $cursor = $qb->execute(); |
|
1020 | + $ids = []; |
|
1021 | + while($row = $cursor->fetch()) { |
|
1022 | + $ids[] = (int)$row['id']; |
|
1023 | + } |
|
1024 | + $cursor->closeCursor(); |
|
1025 | + |
|
1026 | + if (!empty($ids)) { |
|
1027 | + $chunks = array_chunk($ids, 100); |
|
1028 | + foreach ($chunks as $chunk) { |
|
1029 | + $qb->delete('share') |
|
1030 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
1031 | + ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
1032 | + $qb->execute(); |
|
1033 | + } |
|
1034 | + } |
|
1035 | + |
|
1036 | + /* |
|
1037 | 1037 | * Now delete all the group shares |
1038 | 1038 | */ |
1039 | - $qb = $this->dbConn->getQueryBuilder(); |
|
1040 | - $qb->delete('share') |
|
1041 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1042 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1043 | - $qb->execute(); |
|
1044 | - } |
|
1045 | - |
|
1046 | - /** |
|
1047 | - * Delete custom group shares to this group for this user |
|
1048 | - * |
|
1049 | - * @param string $uid |
|
1050 | - * @param string $gid |
|
1051 | - */ |
|
1052 | - public function userDeletedFromGroup($uid, $gid) { |
|
1053 | - /* |
|
1039 | + $qb = $this->dbConn->getQueryBuilder(); |
|
1040 | + $qb->delete('share') |
|
1041 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1042 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1043 | + $qb->execute(); |
|
1044 | + } |
|
1045 | + |
|
1046 | + /** |
|
1047 | + * Delete custom group shares to this group for this user |
|
1048 | + * |
|
1049 | + * @param string $uid |
|
1050 | + * @param string $gid |
|
1051 | + */ |
|
1052 | + public function userDeletedFromGroup($uid, $gid) { |
|
1053 | + /* |
|
1054 | 1054 | * Get all group shares |
1055 | 1055 | */ |
1056 | - $qb = $this->dbConn->getQueryBuilder(); |
|
1057 | - $qb->select('id') |
|
1058 | - ->from('share') |
|
1059 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1060 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1061 | - |
|
1062 | - $cursor = $qb->execute(); |
|
1063 | - $ids = []; |
|
1064 | - while($row = $cursor->fetch()) { |
|
1065 | - $ids[] = (int)$row['id']; |
|
1066 | - } |
|
1067 | - $cursor->closeCursor(); |
|
1068 | - |
|
1069 | - if (!empty($ids)) { |
|
1070 | - $chunks = array_chunk($ids, 100); |
|
1071 | - foreach ($chunks as $chunk) { |
|
1072 | - /* |
|
1056 | + $qb = $this->dbConn->getQueryBuilder(); |
|
1057 | + $qb->select('id') |
|
1058 | + ->from('share') |
|
1059 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1060 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1061 | + |
|
1062 | + $cursor = $qb->execute(); |
|
1063 | + $ids = []; |
|
1064 | + while($row = $cursor->fetch()) { |
|
1065 | + $ids[] = (int)$row['id']; |
|
1066 | + } |
|
1067 | + $cursor->closeCursor(); |
|
1068 | + |
|
1069 | + if (!empty($ids)) { |
|
1070 | + $chunks = array_chunk($ids, 100); |
|
1071 | + foreach ($chunks as $chunk) { |
|
1072 | + /* |
|
1073 | 1073 | * Delete all special shares wit this users for the found group shares |
1074 | 1074 | */ |
1075 | - $qb->delete('share') |
|
1076 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
1077 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid))) |
|
1078 | - ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
1079 | - $qb->execute(); |
|
1080 | - } |
|
1081 | - } |
|
1082 | - } |
|
1083 | - |
|
1084 | - /** |
|
1085 | - * @inheritdoc |
|
1086 | - */ |
|
1087 | - public function getAccessList($nodes, $currentAccess) { |
|
1088 | - $ids = []; |
|
1089 | - foreach ($nodes as $node) { |
|
1090 | - $ids[] = $node->getId(); |
|
1091 | - } |
|
1092 | - |
|
1093 | - $qb = $this->dbConn->getQueryBuilder(); |
|
1094 | - |
|
1095 | - $or = $qb->expr()->orX( |
|
1096 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
1097 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
1098 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
1099 | - ); |
|
1100 | - |
|
1101 | - if ($currentAccess) { |
|
1102 | - $or->add($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))); |
|
1103 | - } |
|
1104 | - |
|
1105 | - $qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions') |
|
1106 | - ->from('share') |
|
1107 | - ->where( |
|
1108 | - $or |
|
1109 | - ) |
|
1110 | - ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
1111 | - ->andWhere($qb->expr()->orX( |
|
1112 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1113 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1114 | - )); |
|
1115 | - $cursor = $qb->execute(); |
|
1116 | - |
|
1117 | - $users = []; |
|
1118 | - $link = false; |
|
1119 | - while($row = $cursor->fetch()) { |
|
1120 | - $type = (int)$row['share_type']; |
|
1121 | - if ($type === \OCP\Share::SHARE_TYPE_USER) { |
|
1122 | - $uid = $row['share_with']; |
|
1123 | - $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1124 | - $users[$uid][$row['id']] = $row; |
|
1125 | - } else if ($type === \OCP\Share::SHARE_TYPE_GROUP) { |
|
1126 | - $gid = $row['share_with']; |
|
1127 | - $group = $this->groupManager->get($gid); |
|
1128 | - |
|
1129 | - if ($group === null) { |
|
1130 | - continue; |
|
1131 | - } |
|
1132 | - |
|
1133 | - $userList = $group->getUsers(); |
|
1134 | - foreach ($userList as $user) { |
|
1135 | - $uid = $user->getUID(); |
|
1136 | - $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1137 | - $users[$uid][$row['id']] = $row; |
|
1138 | - } |
|
1139 | - } else if ($type === \OCP\Share::SHARE_TYPE_LINK) { |
|
1140 | - $link = true; |
|
1141 | - } else if ($type === self::SHARE_TYPE_USERGROUP && $currentAccess === true) { |
|
1142 | - $uid = $row['share_with']; |
|
1143 | - $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1144 | - $users[$uid][$row['id']] = $row; |
|
1145 | - } |
|
1146 | - } |
|
1147 | - $cursor->closeCursor(); |
|
1148 | - |
|
1149 | - if ($currentAccess === true) { |
|
1150 | - $users = array_map([$this, 'filterSharesOfUser'], $users); |
|
1151 | - $users = array_filter($users); |
|
1152 | - } else { |
|
1153 | - $users = array_keys($users); |
|
1154 | - } |
|
1155 | - |
|
1156 | - return ['users' => $users, 'public' => $link]; |
|
1157 | - } |
|
1158 | - |
|
1159 | - /** |
|
1160 | - * For each user the path with the fewest slashes is returned |
|
1161 | - * @param array $shares |
|
1162 | - * @return array |
|
1163 | - */ |
|
1164 | - protected function filterSharesOfUser(array $shares) { |
|
1165 | - // Group shares when the user has a share exception |
|
1166 | - foreach ($shares as $id => $share) { |
|
1167 | - $type = (int) $share['share_type']; |
|
1168 | - $permissions = (int) $share['permissions']; |
|
1169 | - |
|
1170 | - if ($type === self::SHARE_TYPE_USERGROUP) { |
|
1171 | - unset($shares[$share['parent']]); |
|
1172 | - |
|
1173 | - if ($permissions === 0) { |
|
1174 | - unset($shares[$id]); |
|
1175 | - } |
|
1176 | - } |
|
1177 | - } |
|
1178 | - |
|
1179 | - $best = []; |
|
1180 | - $bestDepth = 0; |
|
1181 | - foreach ($shares as $id => $share) { |
|
1182 | - $depth = substr_count($share['file_target'], '/'); |
|
1183 | - if (empty($best) || $depth < $bestDepth) { |
|
1184 | - $bestDepth = $depth; |
|
1185 | - $best = [ |
|
1186 | - 'node_id' => $share['file_source'], |
|
1187 | - 'node_path' => $share['file_target'], |
|
1188 | - ]; |
|
1189 | - } |
|
1190 | - } |
|
1191 | - |
|
1192 | - return $best; |
|
1193 | - } |
|
1075 | + $qb->delete('share') |
|
1076 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
1077 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid))) |
|
1078 | + ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
1079 | + $qb->execute(); |
|
1080 | + } |
|
1081 | + } |
|
1082 | + } |
|
1083 | + |
|
1084 | + /** |
|
1085 | + * @inheritdoc |
|
1086 | + */ |
|
1087 | + public function getAccessList($nodes, $currentAccess) { |
|
1088 | + $ids = []; |
|
1089 | + foreach ($nodes as $node) { |
|
1090 | + $ids[] = $node->getId(); |
|
1091 | + } |
|
1092 | + |
|
1093 | + $qb = $this->dbConn->getQueryBuilder(); |
|
1094 | + |
|
1095 | + $or = $qb->expr()->orX( |
|
1096 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
1097 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
1098 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
1099 | + ); |
|
1100 | + |
|
1101 | + if ($currentAccess) { |
|
1102 | + $or->add($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))); |
|
1103 | + } |
|
1104 | + |
|
1105 | + $qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions') |
|
1106 | + ->from('share') |
|
1107 | + ->where( |
|
1108 | + $or |
|
1109 | + ) |
|
1110 | + ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
1111 | + ->andWhere($qb->expr()->orX( |
|
1112 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1113 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1114 | + )); |
|
1115 | + $cursor = $qb->execute(); |
|
1116 | + |
|
1117 | + $users = []; |
|
1118 | + $link = false; |
|
1119 | + while($row = $cursor->fetch()) { |
|
1120 | + $type = (int)$row['share_type']; |
|
1121 | + if ($type === \OCP\Share::SHARE_TYPE_USER) { |
|
1122 | + $uid = $row['share_with']; |
|
1123 | + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1124 | + $users[$uid][$row['id']] = $row; |
|
1125 | + } else if ($type === \OCP\Share::SHARE_TYPE_GROUP) { |
|
1126 | + $gid = $row['share_with']; |
|
1127 | + $group = $this->groupManager->get($gid); |
|
1128 | + |
|
1129 | + if ($group === null) { |
|
1130 | + continue; |
|
1131 | + } |
|
1132 | + |
|
1133 | + $userList = $group->getUsers(); |
|
1134 | + foreach ($userList as $user) { |
|
1135 | + $uid = $user->getUID(); |
|
1136 | + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1137 | + $users[$uid][$row['id']] = $row; |
|
1138 | + } |
|
1139 | + } else if ($type === \OCP\Share::SHARE_TYPE_LINK) { |
|
1140 | + $link = true; |
|
1141 | + } else if ($type === self::SHARE_TYPE_USERGROUP && $currentAccess === true) { |
|
1142 | + $uid = $row['share_with']; |
|
1143 | + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1144 | + $users[$uid][$row['id']] = $row; |
|
1145 | + } |
|
1146 | + } |
|
1147 | + $cursor->closeCursor(); |
|
1148 | + |
|
1149 | + if ($currentAccess === true) { |
|
1150 | + $users = array_map([$this, 'filterSharesOfUser'], $users); |
|
1151 | + $users = array_filter($users); |
|
1152 | + } else { |
|
1153 | + $users = array_keys($users); |
|
1154 | + } |
|
1155 | + |
|
1156 | + return ['users' => $users, 'public' => $link]; |
|
1157 | + } |
|
1158 | + |
|
1159 | + /** |
|
1160 | + * For each user the path with the fewest slashes is returned |
|
1161 | + * @param array $shares |
|
1162 | + * @return array |
|
1163 | + */ |
|
1164 | + protected function filterSharesOfUser(array $shares) { |
|
1165 | + // Group shares when the user has a share exception |
|
1166 | + foreach ($shares as $id => $share) { |
|
1167 | + $type = (int) $share['share_type']; |
|
1168 | + $permissions = (int) $share['permissions']; |
|
1169 | + |
|
1170 | + if ($type === self::SHARE_TYPE_USERGROUP) { |
|
1171 | + unset($shares[$share['parent']]); |
|
1172 | + |
|
1173 | + if ($permissions === 0) { |
|
1174 | + unset($shares[$id]); |
|
1175 | + } |
|
1176 | + } |
|
1177 | + } |
|
1178 | + |
|
1179 | + $best = []; |
|
1180 | + $bestDepth = 0; |
|
1181 | + foreach ($shares as $id => $share) { |
|
1182 | + $depth = substr_count($share['file_target'], '/'); |
|
1183 | + if (empty($best) || $depth < $bestDepth) { |
|
1184 | + $bestDepth = $depth; |
|
1185 | + $best = [ |
|
1186 | + 'node_id' => $share['file_source'], |
|
1187 | + 'node_path' => $share['file_target'], |
|
1188 | + ]; |
|
1189 | + } |
|
1190 | + } |
|
1191 | + |
|
1192 | + return $best; |
|
1193 | + } |
|
1194 | 1194 | } |
@@ -61,7 +61,7 @@ |
||
61 | 61 | * The deserialize method is called during xml parsing. |
62 | 62 | * |
63 | 63 | * @param Reader $reader |
64 | - * @return mixed |
|
64 | + * @return null|ShareTypeList |
|
65 | 65 | */ |
66 | 66 | static function xmlDeserialize(Reader $reader) { |
67 | 67 | $shareTypes = []; |
@@ -32,61 +32,61 @@ |
||
32 | 32 | * This property contains multiple "share-type" elements, each containing a share type. |
33 | 33 | */ |
34 | 34 | class ShareTypeList implements Element { |
35 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
35 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Share types |
|
39 | - * |
|
40 | - * @var int[] |
|
41 | - */ |
|
42 | - private $shareTypes; |
|
37 | + /** |
|
38 | + * Share types |
|
39 | + * |
|
40 | + * @var int[] |
|
41 | + */ |
|
42 | + private $shareTypes; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param int[] $shareTypes |
|
46 | - */ |
|
47 | - public function __construct($shareTypes) { |
|
48 | - $this->shareTypes = $shareTypes; |
|
49 | - } |
|
44 | + /** |
|
45 | + * @param int[] $shareTypes |
|
46 | + */ |
|
47 | + public function __construct($shareTypes) { |
|
48 | + $this->shareTypes = $shareTypes; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Returns the share types |
|
53 | - * |
|
54 | - * @return int[] |
|
55 | - */ |
|
56 | - public function getShareTypes() { |
|
57 | - return $this->shareTypes; |
|
58 | - } |
|
51 | + /** |
|
52 | + * Returns the share types |
|
53 | + * |
|
54 | + * @return int[] |
|
55 | + */ |
|
56 | + public function getShareTypes() { |
|
57 | + return $this->shareTypes; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * The deserialize method is called during xml parsing. |
|
62 | - * |
|
63 | - * @param Reader $reader |
|
64 | - * @return mixed |
|
65 | - */ |
|
66 | - static function xmlDeserialize(Reader $reader) { |
|
67 | - $shareTypes = []; |
|
60 | + /** |
|
61 | + * The deserialize method is called during xml parsing. |
|
62 | + * |
|
63 | + * @param Reader $reader |
|
64 | + * @return mixed |
|
65 | + */ |
|
66 | + static function xmlDeserialize(Reader $reader) { |
|
67 | + $shareTypes = []; |
|
68 | 68 | |
69 | - $tree = $reader->parseInnerTree(); |
|
70 | - if ($tree === null) { |
|
71 | - return null; |
|
72 | - } |
|
73 | - foreach ($tree as $elem) { |
|
74 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
75 | - $shareTypes[] = (int)$elem['value']; |
|
76 | - } |
|
77 | - } |
|
78 | - return new self($shareTypes); |
|
79 | - } |
|
69 | + $tree = $reader->parseInnerTree(); |
|
70 | + if ($tree === null) { |
|
71 | + return null; |
|
72 | + } |
|
73 | + foreach ($tree as $elem) { |
|
74 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
75 | + $shareTypes[] = (int)$elem['value']; |
|
76 | + } |
|
77 | + } |
|
78 | + return new self($shareTypes); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * The xmlSerialize metod is called during xml writing. |
|
83 | - * |
|
84 | - * @param Writer $writer |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - function xmlSerialize(Writer $writer) { |
|
88 | - foreach ($this->shareTypes as $shareType) { |
|
89 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
90 | - } |
|
91 | - } |
|
81 | + /** |
|
82 | + * The xmlSerialize metod is called during xml writing. |
|
83 | + * |
|
84 | + * @param Writer $writer |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + function xmlSerialize(Writer $writer) { |
|
88 | + foreach ($this->shareTypes as $shareType) { |
|
89 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
90 | + } |
|
91 | + } |
|
92 | 92 | } |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | return null; |
72 | 72 | } |
73 | 73 | foreach ($tree as $elem) { |
74 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
75 | - $shareTypes[] = (int)$elem['value']; |
|
74 | + if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}share-type') { |
|
75 | + $shareTypes[] = (int) $elem['value']; |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | return new self($shareTypes); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | function xmlSerialize(Writer $writer) { |
88 | 88 | foreach ($this->shareTypes as $shareType) { |
89 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
89 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}share-type', $shareType); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
@@ -80,7 +80,7 @@ |
||
80 | 80 | * the next element. |
81 | 81 | * |
82 | 82 | * @param Reader $reader |
83 | - * @return mixed |
|
83 | + * @return null|TagList |
|
84 | 84 | */ |
85 | 85 | static function xmlDeserialize(Reader $reader) { |
86 | 86 | $tags = []; |
@@ -34,92 +34,92 @@ |
||
34 | 34 | * This property contains multiple "tag" elements, each containing a tag name. |
35 | 35 | */ |
36 | 36 | class TagList implements Element { |
37 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
37 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
38 | 38 | |
39 | - /** |
|
40 | - * tags |
|
41 | - * |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - private $tags; |
|
39 | + /** |
|
40 | + * tags |
|
41 | + * |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + private $tags; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param array $tags |
|
48 | - */ |
|
49 | - public function __construct(array $tags) { |
|
50 | - $this->tags = $tags; |
|
51 | - } |
|
46 | + /** |
|
47 | + * @param array $tags |
|
48 | + */ |
|
49 | + public function __construct(array $tags) { |
|
50 | + $this->tags = $tags; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Returns the tags |
|
55 | - * |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function getTags() { |
|
53 | + /** |
|
54 | + * Returns the tags |
|
55 | + * |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function getTags() { |
|
59 | 59 | |
60 | - return $this->tags; |
|
60 | + return $this->tags; |
|
61 | 61 | |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * The deserialize method is called during xml parsing. |
|
66 | - * |
|
67 | - * This method is called statictly, this is because in theory this method |
|
68 | - * may be used as a type of constructor, or factory method. |
|
69 | - * |
|
70 | - * Often you want to return an instance of the current class, but you are |
|
71 | - * free to return other data as well. |
|
72 | - * |
|
73 | - * You are responsible for advancing the reader to the next element. Not |
|
74 | - * doing anything will result in a never-ending loop. |
|
75 | - * |
|
76 | - * If you just want to skip parsing for this element altogether, you can |
|
77 | - * just call $reader->next(); |
|
78 | - * |
|
79 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
80 | - * the next element. |
|
81 | - * |
|
82 | - * @param Reader $reader |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - static function xmlDeserialize(Reader $reader) { |
|
86 | - $tags = []; |
|
64 | + /** |
|
65 | + * The deserialize method is called during xml parsing. |
|
66 | + * |
|
67 | + * This method is called statictly, this is because in theory this method |
|
68 | + * may be used as a type of constructor, or factory method. |
|
69 | + * |
|
70 | + * Often you want to return an instance of the current class, but you are |
|
71 | + * free to return other data as well. |
|
72 | + * |
|
73 | + * You are responsible for advancing the reader to the next element. Not |
|
74 | + * doing anything will result in a never-ending loop. |
|
75 | + * |
|
76 | + * If you just want to skip parsing for this element altogether, you can |
|
77 | + * just call $reader->next(); |
|
78 | + * |
|
79 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
80 | + * the next element. |
|
81 | + * |
|
82 | + * @param Reader $reader |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + static function xmlDeserialize(Reader $reader) { |
|
86 | + $tags = []; |
|
87 | 87 | |
88 | - $tree = $reader->parseInnerTree(); |
|
89 | - if ($tree === null) { |
|
90 | - return null; |
|
91 | - } |
|
92 | - foreach ($tree as $elem) { |
|
93 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
94 | - $tags[] = $elem['value']; |
|
95 | - } |
|
96 | - } |
|
97 | - return new self($tags); |
|
98 | - } |
|
88 | + $tree = $reader->parseInnerTree(); |
|
89 | + if ($tree === null) { |
|
90 | + return null; |
|
91 | + } |
|
92 | + foreach ($tree as $elem) { |
|
93 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
94 | + $tags[] = $elem['value']; |
|
95 | + } |
|
96 | + } |
|
97 | + return new self($tags); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * The xmlSerialize metod is called during xml writing. |
|
102 | - * |
|
103 | - * Use the $writer argument to write its own xml serialization. |
|
104 | - * |
|
105 | - * An important note: do _not_ create a parent element. Any element |
|
106 | - * implementing XmlSerializble should only ever write what's considered |
|
107 | - * its 'inner xml'. |
|
108 | - * |
|
109 | - * The parent of the current element is responsible for writing a |
|
110 | - * containing element. |
|
111 | - * |
|
112 | - * This allows serializers to be re-used for different element names. |
|
113 | - * |
|
114 | - * If you are opening new elements, you must also close them again. |
|
115 | - * |
|
116 | - * @param Writer $writer |
|
117 | - * @return void |
|
118 | - */ |
|
119 | - function xmlSerialize(Writer $writer) { |
|
100 | + /** |
|
101 | + * The xmlSerialize metod is called during xml writing. |
|
102 | + * |
|
103 | + * Use the $writer argument to write its own xml serialization. |
|
104 | + * |
|
105 | + * An important note: do _not_ create a parent element. Any element |
|
106 | + * implementing XmlSerializble should only ever write what's considered |
|
107 | + * its 'inner xml'. |
|
108 | + * |
|
109 | + * The parent of the current element is responsible for writing a |
|
110 | + * containing element. |
|
111 | + * |
|
112 | + * This allows serializers to be re-used for different element names. |
|
113 | + * |
|
114 | + * If you are opening new elements, you must also close them again. |
|
115 | + * |
|
116 | + * @param Writer $writer |
|
117 | + * @return void |
|
118 | + */ |
|
119 | + function xmlSerialize(Writer $writer) { |
|
120 | 120 | |
121 | - foreach ($this->tags as $tag) { |
|
122 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
123 | - } |
|
124 | - } |
|
121 | + foreach ($this->tags as $tag) { |
|
122 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
123 | + } |
|
124 | + } |
|
125 | 125 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | return null; |
91 | 91 | } |
92 | 92 | foreach ($tree as $elem) { |
93 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
93 | + if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}tag') { |
|
94 | 94 | $tags[] = $elem['value']; |
95 | 95 | } |
96 | 96 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | function xmlSerialize(Writer $writer) { |
120 | 120 | |
121 | 121 | foreach ($this->tags as $tag) { |
122 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
122 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}tag', $tag); |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | } |
@@ -318,6 +318,11 @@ |
||
318 | 318 | */ |
319 | 319 | // FIXME This method is only public, until OC_L10N does not need it anymore, |
320 | 320 | // FIXME This is also the reason, why it is not in the public interface |
321 | + |
|
322 | + /** |
|
323 | + * @param string $app |
|
324 | + * @param string $lang |
|
325 | + */ |
|
321 | 326 | public function getL10nFilesForApp($app, $lang) { |
322 | 327 | $languageFiles = []; |
323 | 328 |
@@ -40,405 +40,405 @@ |
||
40 | 40 | */ |
41 | 41 | class Factory implements IFactory { |
42 | 42 | |
43 | - /** @var string */ |
|
44 | - protected $requestLanguage = ''; |
|
45 | - |
|
46 | - /** |
|
47 | - * cached instances |
|
48 | - * @var array Structure: Lang => App => \OCP\IL10N |
|
49 | - */ |
|
50 | - protected $instances = []; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var array Structure: App => string[] |
|
54 | - */ |
|
55 | - protected $availableLanguages = []; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var array Structure: string => callable |
|
59 | - */ |
|
60 | - protected $pluralFunctions = []; |
|
61 | - |
|
62 | - /** @var IConfig */ |
|
63 | - protected $config; |
|
64 | - |
|
65 | - /** @var IRequest */ |
|
66 | - protected $request; |
|
67 | - |
|
68 | - /** @var IUserSession */ |
|
69 | - protected $userSession; |
|
70 | - |
|
71 | - /** @var string */ |
|
72 | - protected $serverRoot; |
|
73 | - |
|
74 | - /** |
|
75 | - * @param IConfig $config |
|
76 | - * @param IRequest $request |
|
77 | - * @param IUserSession $userSession |
|
78 | - * @param string $serverRoot |
|
79 | - */ |
|
80 | - public function __construct(IConfig $config, |
|
81 | - IRequest $request, |
|
82 | - IUserSession $userSession, |
|
83 | - $serverRoot) { |
|
84 | - $this->config = $config; |
|
85 | - $this->request = $request; |
|
86 | - $this->userSession = $userSession; |
|
87 | - $this->serverRoot = $serverRoot; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Get a language instance |
|
92 | - * |
|
93 | - * @param string $app |
|
94 | - * @param string|null $lang |
|
95 | - * @return \OCP\IL10N |
|
96 | - */ |
|
97 | - public function get($app, $lang = null) { |
|
98 | - $app = \OC_App::cleanAppId($app); |
|
99 | - if ($lang !== null) { |
|
100 | - $lang = str_replace(array('\0', '/', '\\', '..'), '', (string) $lang); |
|
101 | - } |
|
102 | - |
|
103 | - $forceLang = $this->config->getSystemValue('force_language', false); |
|
104 | - if (is_string($forceLang)) { |
|
105 | - $lang = $forceLang; |
|
106 | - } |
|
107 | - |
|
108 | - if ($lang === null || !$this->languageExists($app, $lang)) { |
|
109 | - $lang = $this->findLanguage($app); |
|
110 | - } |
|
111 | - |
|
112 | - if (!isset($this->instances[$lang][$app])) { |
|
113 | - $this->instances[$lang][$app] = new L10N( |
|
114 | - $this, $app, $lang, |
|
115 | - $this->getL10nFilesForApp($app, $lang) |
|
116 | - ); |
|
117 | - } |
|
118 | - |
|
119 | - return $this->instances[$lang][$app]; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Find the best language |
|
124 | - * |
|
125 | - * @param string|null $app App id or null for core |
|
126 | - * @return string language If nothing works it returns 'en' |
|
127 | - */ |
|
128 | - public function findLanguage($app = null) { |
|
129 | - if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) { |
|
130 | - return $this->requestLanguage; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * At this point Nextcloud might not yet be installed and thus the lookup |
|
135 | - * in the preferences table might fail. For this reason we need to check |
|
136 | - * whether the instance has already been installed |
|
137 | - * |
|
138 | - * @link https://github.com/owncloud/core/issues/21955 |
|
139 | - */ |
|
140 | - if($this->config->getSystemValue('installed', false)) { |
|
141 | - $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
142 | - if(!is_null($userId)) { |
|
143 | - $userLang = $this->config->getUserValue($userId, 'core', 'lang', null); |
|
144 | - } else { |
|
145 | - $userLang = null; |
|
146 | - } |
|
147 | - } else { |
|
148 | - $userId = null; |
|
149 | - $userLang = null; |
|
150 | - } |
|
151 | - |
|
152 | - if ($userLang) { |
|
153 | - $this->requestLanguage = $userLang; |
|
154 | - if ($this->languageExists($app, $userLang)) { |
|
155 | - return $userLang; |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - try { |
|
160 | - // Try to get the language from the Request |
|
161 | - $lang = $this->getLanguageFromRequest($app); |
|
162 | - if ($userId !== null && $app === null && !$userLang) { |
|
163 | - $this->config->setUserValue($userId, 'core', 'lang', $lang); |
|
164 | - } |
|
165 | - return $lang; |
|
166 | - } catch (LanguageNotFoundException $e) { |
|
167 | - // Finding language from request failed fall back to default language |
|
168 | - $defaultLanguage = $this->config->getSystemValue('default_language', false); |
|
169 | - if ($defaultLanguage !== false && $this->languageExists($app, $defaultLanguage)) { |
|
170 | - return $defaultLanguage; |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - // We could not find any language so fall back to english |
|
175 | - return 'en'; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Find all available languages for an app |
|
180 | - * |
|
181 | - * @param string|null $app App id or null for core |
|
182 | - * @return array an array of available languages |
|
183 | - */ |
|
184 | - public function findAvailableLanguages($app = null) { |
|
185 | - $key = $app; |
|
186 | - if ($key === null) { |
|
187 | - $key = 'null'; |
|
188 | - } |
|
189 | - |
|
190 | - // also works with null as key |
|
191 | - if (!empty($this->availableLanguages[$key])) { |
|
192 | - return $this->availableLanguages[$key]; |
|
193 | - } |
|
194 | - |
|
195 | - $available = ['en']; //english is always available |
|
196 | - $dir = $this->findL10nDir($app); |
|
197 | - if (is_dir($dir)) { |
|
198 | - $files = scandir($dir); |
|
199 | - if ($files !== false) { |
|
200 | - foreach ($files as $file) { |
|
201 | - if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
202 | - $available[] = substr($file, 0, -5); |
|
203 | - } |
|
204 | - } |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - // merge with translations from theme |
|
209 | - $theme = $this->config->getSystemValue('theme'); |
|
210 | - if (!empty($theme)) { |
|
211 | - $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot)); |
|
212 | - |
|
213 | - if (is_dir($themeDir)) { |
|
214 | - $files = scandir($themeDir); |
|
215 | - if ($files !== false) { |
|
216 | - foreach ($files as $file) { |
|
217 | - if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
218 | - $available[] = substr($file, 0, -5); |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
222 | - } |
|
223 | - } |
|
224 | - |
|
225 | - $this->availableLanguages[$key] = $available; |
|
226 | - return $available; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * @param string|null $app App id or null for core |
|
231 | - * @param string $lang |
|
232 | - * @return bool |
|
233 | - */ |
|
234 | - public function languageExists($app, $lang) { |
|
235 | - if ($lang === 'en') {//english is always available |
|
236 | - return true; |
|
237 | - } |
|
238 | - |
|
239 | - $languages = $this->findAvailableLanguages($app); |
|
240 | - return array_search($lang, $languages) !== false; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * @param string|null $app |
|
245 | - * @return string |
|
246 | - * @throws LanguageNotFoundException |
|
247 | - */ |
|
248 | - private function getLanguageFromRequest($app) { |
|
249 | - $header = $this->request->getHeader('ACCEPT_LANGUAGE'); |
|
250 | - if ($header !== '') { |
|
251 | - $available = $this->findAvailableLanguages($app); |
|
252 | - |
|
253 | - // E.g. make sure that 'de' is before 'de_DE'. |
|
254 | - sort($available); |
|
255 | - |
|
256 | - $preferences = preg_split('/,\s*/', strtolower($header)); |
|
257 | - foreach ($preferences as $preference) { |
|
258 | - list($preferred_language) = explode(';', $preference); |
|
259 | - $preferred_language = str_replace('-', '_', $preferred_language); |
|
260 | - |
|
261 | - foreach ($available as $available_language) { |
|
262 | - if ($preferred_language === strtolower($available_language)) { |
|
263 | - return $this->respectDefaultLanguage($app, $available_language); |
|
264 | - } |
|
265 | - } |
|
266 | - |
|
267 | - // Fallback from de_De to de |
|
268 | - foreach ($available as $available_language) { |
|
269 | - if (substr($preferred_language, 0, 2) === $available_language) { |
|
270 | - return $available_language; |
|
271 | - } |
|
272 | - } |
|
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - throw new LanguageNotFoundException(); |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * if default language is set to de_DE (formal German) this should be |
|
281 | - * preferred to 'de' (non-formal German) if possible |
|
282 | - * |
|
283 | - * @param string|null $app |
|
284 | - * @param string $lang |
|
285 | - * @return string |
|
286 | - */ |
|
287 | - protected function respectDefaultLanguage($app, $lang) { |
|
288 | - $result = $lang; |
|
289 | - $defaultLanguage = $this->config->getSystemValue('default_language', false); |
|
290 | - |
|
291 | - // use formal version of german ("Sie" instead of "Du") if the default |
|
292 | - // language is set to 'de_DE' if possible |
|
293 | - if (is_string($defaultLanguage) && |
|
294 | - strtolower($lang) === 'de' && |
|
295 | - strtolower($defaultLanguage) === 'de_de' && |
|
296 | - $this->languageExists($app, 'de_DE') |
|
297 | - ) { |
|
298 | - $result = 'de_DE'; |
|
299 | - } |
|
300 | - |
|
301 | - return $result; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Checks if $sub is a subdirectory of $parent |
|
306 | - * |
|
307 | - * @param string $sub |
|
308 | - * @param string $parent |
|
309 | - * @return bool |
|
310 | - */ |
|
311 | - private function isSubDirectory($sub, $parent) { |
|
312 | - // Check whether $sub contains no ".." |
|
313 | - if(strpos($sub, '..') !== false) { |
|
314 | - return false; |
|
315 | - } |
|
316 | - |
|
317 | - // Check whether $sub is a subdirectory of $parent |
|
318 | - if (strpos($sub, $parent) === 0) { |
|
319 | - return true; |
|
320 | - } |
|
321 | - |
|
322 | - return false; |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Get a list of language files that should be loaded |
|
327 | - * |
|
328 | - * @param string $app |
|
329 | - * @param string $lang |
|
330 | - * @return string[] |
|
331 | - */ |
|
332 | - // FIXME This method is only public, until OC_L10N does not need it anymore, |
|
333 | - // FIXME This is also the reason, why it is not in the public interface |
|
334 | - public function getL10nFilesForApp($app, $lang) { |
|
335 | - $languageFiles = []; |
|
336 | - |
|
337 | - $i18nDir = $this->findL10nDir($app); |
|
338 | - $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json'; |
|
339 | - |
|
340 | - if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/') |
|
341 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/') |
|
342 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/') |
|
343 | - || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/') |
|
344 | - ) |
|
345 | - && file_exists($transFile)) { |
|
346 | - // load the translations file |
|
347 | - $languageFiles[] = $transFile; |
|
348 | - } |
|
349 | - |
|
350 | - // merge with translations from theme |
|
351 | - $theme = $this->config->getSystemValue('theme'); |
|
352 | - if (!empty($theme)) { |
|
353 | - $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot)); |
|
354 | - if (file_exists($transFile)) { |
|
355 | - $languageFiles[] = $transFile; |
|
356 | - } |
|
357 | - } |
|
358 | - |
|
359 | - return $languageFiles; |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * find the l10n directory |
|
364 | - * |
|
365 | - * @param string $app App id or empty string for core |
|
366 | - * @return string directory |
|
367 | - */ |
|
368 | - protected function findL10nDir($app = null) { |
|
369 | - if (in_array($app, ['core', 'lib', 'settings'])) { |
|
370 | - if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) { |
|
371 | - return $this->serverRoot . '/' . $app . '/l10n/'; |
|
372 | - } |
|
373 | - } else if ($app && \OC_App::getAppPath($app) !== false) { |
|
374 | - // Check if the app is in the app folder |
|
375 | - return \OC_App::getAppPath($app) . '/l10n/'; |
|
376 | - } |
|
377 | - return $this->serverRoot . '/core/l10n/'; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * Creates a function from the plural string |
|
383 | - * |
|
384 | - * Parts of the code is copied from Habari: |
|
385 | - * https://github.com/habari/system/blob/master/classes/locale.php |
|
386 | - * @param string $string |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function createPluralFunction($string) { |
|
390 | - if (isset($this->pluralFunctions[$string])) { |
|
391 | - return $this->pluralFunctions[$string]; |
|
392 | - } |
|
393 | - |
|
394 | - if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
395 | - // sanitize |
|
396 | - $nplurals = preg_replace( '/[^0-9]/', '', $matches[1] ); |
|
397 | - $plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] ); |
|
398 | - |
|
399 | - $body = str_replace( |
|
400 | - array( 'plural', 'n', '$n$plurals', ), |
|
401 | - array( '$plural', '$n', '$nplurals', ), |
|
402 | - 'nplurals='. $nplurals . '; plural=' . $plural |
|
403 | - ); |
|
404 | - |
|
405 | - // add parents |
|
406 | - // important since PHP's ternary evaluates from left to right |
|
407 | - $body .= ';'; |
|
408 | - $res = ''; |
|
409 | - $p = 0; |
|
410 | - $length = strlen($body); |
|
411 | - for($i = 0; $i < $length; $i++) { |
|
412 | - $ch = $body[$i]; |
|
413 | - switch ( $ch ) { |
|
414 | - case '?': |
|
415 | - $res .= ' ? ('; |
|
416 | - $p++; |
|
417 | - break; |
|
418 | - case ':': |
|
419 | - $res .= ') : ('; |
|
420 | - break; |
|
421 | - case ';': |
|
422 | - $res .= str_repeat( ')', $p ) . ';'; |
|
423 | - $p = 0; |
|
424 | - break; |
|
425 | - default: |
|
426 | - $res .= $ch; |
|
427 | - } |
|
428 | - } |
|
429 | - |
|
430 | - $body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
431 | - $function = create_function('$n', $body); |
|
432 | - $this->pluralFunctions[$string] = $function; |
|
433 | - return $function; |
|
434 | - } else { |
|
435 | - // default: one plural form for all cases but n==1 (english) |
|
436 | - $function = create_function( |
|
437 | - '$n', |
|
438 | - '$nplurals=2;$plural=($n==1?0:1);return ($plural>=$nplurals?$nplurals-1:$plural);' |
|
439 | - ); |
|
440 | - $this->pluralFunctions[$string] = $function; |
|
441 | - return $function; |
|
442 | - } |
|
443 | - } |
|
43 | + /** @var string */ |
|
44 | + protected $requestLanguage = ''; |
|
45 | + |
|
46 | + /** |
|
47 | + * cached instances |
|
48 | + * @var array Structure: Lang => App => \OCP\IL10N |
|
49 | + */ |
|
50 | + protected $instances = []; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var array Structure: App => string[] |
|
54 | + */ |
|
55 | + protected $availableLanguages = []; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var array Structure: string => callable |
|
59 | + */ |
|
60 | + protected $pluralFunctions = []; |
|
61 | + |
|
62 | + /** @var IConfig */ |
|
63 | + protected $config; |
|
64 | + |
|
65 | + /** @var IRequest */ |
|
66 | + protected $request; |
|
67 | + |
|
68 | + /** @var IUserSession */ |
|
69 | + protected $userSession; |
|
70 | + |
|
71 | + /** @var string */ |
|
72 | + protected $serverRoot; |
|
73 | + |
|
74 | + /** |
|
75 | + * @param IConfig $config |
|
76 | + * @param IRequest $request |
|
77 | + * @param IUserSession $userSession |
|
78 | + * @param string $serverRoot |
|
79 | + */ |
|
80 | + public function __construct(IConfig $config, |
|
81 | + IRequest $request, |
|
82 | + IUserSession $userSession, |
|
83 | + $serverRoot) { |
|
84 | + $this->config = $config; |
|
85 | + $this->request = $request; |
|
86 | + $this->userSession = $userSession; |
|
87 | + $this->serverRoot = $serverRoot; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Get a language instance |
|
92 | + * |
|
93 | + * @param string $app |
|
94 | + * @param string|null $lang |
|
95 | + * @return \OCP\IL10N |
|
96 | + */ |
|
97 | + public function get($app, $lang = null) { |
|
98 | + $app = \OC_App::cleanAppId($app); |
|
99 | + if ($lang !== null) { |
|
100 | + $lang = str_replace(array('\0', '/', '\\', '..'), '', (string) $lang); |
|
101 | + } |
|
102 | + |
|
103 | + $forceLang = $this->config->getSystemValue('force_language', false); |
|
104 | + if (is_string($forceLang)) { |
|
105 | + $lang = $forceLang; |
|
106 | + } |
|
107 | + |
|
108 | + if ($lang === null || !$this->languageExists($app, $lang)) { |
|
109 | + $lang = $this->findLanguage($app); |
|
110 | + } |
|
111 | + |
|
112 | + if (!isset($this->instances[$lang][$app])) { |
|
113 | + $this->instances[$lang][$app] = new L10N( |
|
114 | + $this, $app, $lang, |
|
115 | + $this->getL10nFilesForApp($app, $lang) |
|
116 | + ); |
|
117 | + } |
|
118 | + |
|
119 | + return $this->instances[$lang][$app]; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Find the best language |
|
124 | + * |
|
125 | + * @param string|null $app App id or null for core |
|
126 | + * @return string language If nothing works it returns 'en' |
|
127 | + */ |
|
128 | + public function findLanguage($app = null) { |
|
129 | + if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) { |
|
130 | + return $this->requestLanguage; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * At this point Nextcloud might not yet be installed and thus the lookup |
|
135 | + * in the preferences table might fail. For this reason we need to check |
|
136 | + * whether the instance has already been installed |
|
137 | + * |
|
138 | + * @link https://github.com/owncloud/core/issues/21955 |
|
139 | + */ |
|
140 | + if($this->config->getSystemValue('installed', false)) { |
|
141 | + $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
142 | + if(!is_null($userId)) { |
|
143 | + $userLang = $this->config->getUserValue($userId, 'core', 'lang', null); |
|
144 | + } else { |
|
145 | + $userLang = null; |
|
146 | + } |
|
147 | + } else { |
|
148 | + $userId = null; |
|
149 | + $userLang = null; |
|
150 | + } |
|
151 | + |
|
152 | + if ($userLang) { |
|
153 | + $this->requestLanguage = $userLang; |
|
154 | + if ($this->languageExists($app, $userLang)) { |
|
155 | + return $userLang; |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + try { |
|
160 | + // Try to get the language from the Request |
|
161 | + $lang = $this->getLanguageFromRequest($app); |
|
162 | + if ($userId !== null && $app === null && !$userLang) { |
|
163 | + $this->config->setUserValue($userId, 'core', 'lang', $lang); |
|
164 | + } |
|
165 | + return $lang; |
|
166 | + } catch (LanguageNotFoundException $e) { |
|
167 | + // Finding language from request failed fall back to default language |
|
168 | + $defaultLanguage = $this->config->getSystemValue('default_language', false); |
|
169 | + if ($defaultLanguage !== false && $this->languageExists($app, $defaultLanguage)) { |
|
170 | + return $defaultLanguage; |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + // We could not find any language so fall back to english |
|
175 | + return 'en'; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Find all available languages for an app |
|
180 | + * |
|
181 | + * @param string|null $app App id or null for core |
|
182 | + * @return array an array of available languages |
|
183 | + */ |
|
184 | + public function findAvailableLanguages($app = null) { |
|
185 | + $key = $app; |
|
186 | + if ($key === null) { |
|
187 | + $key = 'null'; |
|
188 | + } |
|
189 | + |
|
190 | + // also works with null as key |
|
191 | + if (!empty($this->availableLanguages[$key])) { |
|
192 | + return $this->availableLanguages[$key]; |
|
193 | + } |
|
194 | + |
|
195 | + $available = ['en']; //english is always available |
|
196 | + $dir = $this->findL10nDir($app); |
|
197 | + if (is_dir($dir)) { |
|
198 | + $files = scandir($dir); |
|
199 | + if ($files !== false) { |
|
200 | + foreach ($files as $file) { |
|
201 | + if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
202 | + $available[] = substr($file, 0, -5); |
|
203 | + } |
|
204 | + } |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + // merge with translations from theme |
|
209 | + $theme = $this->config->getSystemValue('theme'); |
|
210 | + if (!empty($theme)) { |
|
211 | + $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot)); |
|
212 | + |
|
213 | + if (is_dir($themeDir)) { |
|
214 | + $files = scandir($themeDir); |
|
215 | + if ($files !== false) { |
|
216 | + foreach ($files as $file) { |
|
217 | + if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
218 | + $available[] = substr($file, 0, -5); |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | + } |
|
223 | + } |
|
224 | + |
|
225 | + $this->availableLanguages[$key] = $available; |
|
226 | + return $available; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * @param string|null $app App id or null for core |
|
231 | + * @param string $lang |
|
232 | + * @return bool |
|
233 | + */ |
|
234 | + public function languageExists($app, $lang) { |
|
235 | + if ($lang === 'en') {//english is always available |
|
236 | + return true; |
|
237 | + } |
|
238 | + |
|
239 | + $languages = $this->findAvailableLanguages($app); |
|
240 | + return array_search($lang, $languages) !== false; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * @param string|null $app |
|
245 | + * @return string |
|
246 | + * @throws LanguageNotFoundException |
|
247 | + */ |
|
248 | + private function getLanguageFromRequest($app) { |
|
249 | + $header = $this->request->getHeader('ACCEPT_LANGUAGE'); |
|
250 | + if ($header !== '') { |
|
251 | + $available = $this->findAvailableLanguages($app); |
|
252 | + |
|
253 | + // E.g. make sure that 'de' is before 'de_DE'. |
|
254 | + sort($available); |
|
255 | + |
|
256 | + $preferences = preg_split('/,\s*/', strtolower($header)); |
|
257 | + foreach ($preferences as $preference) { |
|
258 | + list($preferred_language) = explode(';', $preference); |
|
259 | + $preferred_language = str_replace('-', '_', $preferred_language); |
|
260 | + |
|
261 | + foreach ($available as $available_language) { |
|
262 | + if ($preferred_language === strtolower($available_language)) { |
|
263 | + return $this->respectDefaultLanguage($app, $available_language); |
|
264 | + } |
|
265 | + } |
|
266 | + |
|
267 | + // Fallback from de_De to de |
|
268 | + foreach ($available as $available_language) { |
|
269 | + if (substr($preferred_language, 0, 2) === $available_language) { |
|
270 | + return $available_language; |
|
271 | + } |
|
272 | + } |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + throw new LanguageNotFoundException(); |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * if default language is set to de_DE (formal German) this should be |
|
281 | + * preferred to 'de' (non-formal German) if possible |
|
282 | + * |
|
283 | + * @param string|null $app |
|
284 | + * @param string $lang |
|
285 | + * @return string |
|
286 | + */ |
|
287 | + protected function respectDefaultLanguage($app, $lang) { |
|
288 | + $result = $lang; |
|
289 | + $defaultLanguage = $this->config->getSystemValue('default_language', false); |
|
290 | + |
|
291 | + // use formal version of german ("Sie" instead of "Du") if the default |
|
292 | + // language is set to 'de_DE' if possible |
|
293 | + if (is_string($defaultLanguage) && |
|
294 | + strtolower($lang) === 'de' && |
|
295 | + strtolower($defaultLanguage) === 'de_de' && |
|
296 | + $this->languageExists($app, 'de_DE') |
|
297 | + ) { |
|
298 | + $result = 'de_DE'; |
|
299 | + } |
|
300 | + |
|
301 | + return $result; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Checks if $sub is a subdirectory of $parent |
|
306 | + * |
|
307 | + * @param string $sub |
|
308 | + * @param string $parent |
|
309 | + * @return bool |
|
310 | + */ |
|
311 | + private function isSubDirectory($sub, $parent) { |
|
312 | + // Check whether $sub contains no ".." |
|
313 | + if(strpos($sub, '..') !== false) { |
|
314 | + return false; |
|
315 | + } |
|
316 | + |
|
317 | + // Check whether $sub is a subdirectory of $parent |
|
318 | + if (strpos($sub, $parent) === 0) { |
|
319 | + return true; |
|
320 | + } |
|
321 | + |
|
322 | + return false; |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Get a list of language files that should be loaded |
|
327 | + * |
|
328 | + * @param string $app |
|
329 | + * @param string $lang |
|
330 | + * @return string[] |
|
331 | + */ |
|
332 | + // FIXME This method is only public, until OC_L10N does not need it anymore, |
|
333 | + // FIXME This is also the reason, why it is not in the public interface |
|
334 | + public function getL10nFilesForApp($app, $lang) { |
|
335 | + $languageFiles = []; |
|
336 | + |
|
337 | + $i18nDir = $this->findL10nDir($app); |
|
338 | + $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json'; |
|
339 | + |
|
340 | + if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/') |
|
341 | + || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/') |
|
342 | + || $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/') |
|
343 | + || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/') |
|
344 | + ) |
|
345 | + && file_exists($transFile)) { |
|
346 | + // load the translations file |
|
347 | + $languageFiles[] = $transFile; |
|
348 | + } |
|
349 | + |
|
350 | + // merge with translations from theme |
|
351 | + $theme = $this->config->getSystemValue('theme'); |
|
352 | + if (!empty($theme)) { |
|
353 | + $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot)); |
|
354 | + if (file_exists($transFile)) { |
|
355 | + $languageFiles[] = $transFile; |
|
356 | + } |
|
357 | + } |
|
358 | + |
|
359 | + return $languageFiles; |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * find the l10n directory |
|
364 | + * |
|
365 | + * @param string $app App id or empty string for core |
|
366 | + * @return string directory |
|
367 | + */ |
|
368 | + protected function findL10nDir($app = null) { |
|
369 | + if (in_array($app, ['core', 'lib', 'settings'])) { |
|
370 | + if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) { |
|
371 | + return $this->serverRoot . '/' . $app . '/l10n/'; |
|
372 | + } |
|
373 | + } else if ($app && \OC_App::getAppPath($app) !== false) { |
|
374 | + // Check if the app is in the app folder |
|
375 | + return \OC_App::getAppPath($app) . '/l10n/'; |
|
376 | + } |
|
377 | + return $this->serverRoot . '/core/l10n/'; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * Creates a function from the plural string |
|
383 | + * |
|
384 | + * Parts of the code is copied from Habari: |
|
385 | + * https://github.com/habari/system/blob/master/classes/locale.php |
|
386 | + * @param string $string |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function createPluralFunction($string) { |
|
390 | + if (isset($this->pluralFunctions[$string])) { |
|
391 | + return $this->pluralFunctions[$string]; |
|
392 | + } |
|
393 | + |
|
394 | + if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
395 | + // sanitize |
|
396 | + $nplurals = preg_replace( '/[^0-9]/', '', $matches[1] ); |
|
397 | + $plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] ); |
|
398 | + |
|
399 | + $body = str_replace( |
|
400 | + array( 'plural', 'n', '$n$plurals', ), |
|
401 | + array( '$plural', '$n', '$nplurals', ), |
|
402 | + 'nplurals='. $nplurals . '; plural=' . $plural |
|
403 | + ); |
|
404 | + |
|
405 | + // add parents |
|
406 | + // important since PHP's ternary evaluates from left to right |
|
407 | + $body .= ';'; |
|
408 | + $res = ''; |
|
409 | + $p = 0; |
|
410 | + $length = strlen($body); |
|
411 | + for($i = 0; $i < $length; $i++) { |
|
412 | + $ch = $body[$i]; |
|
413 | + switch ( $ch ) { |
|
414 | + case '?': |
|
415 | + $res .= ' ? ('; |
|
416 | + $p++; |
|
417 | + break; |
|
418 | + case ':': |
|
419 | + $res .= ') : ('; |
|
420 | + break; |
|
421 | + case ';': |
|
422 | + $res .= str_repeat( ')', $p ) . ';'; |
|
423 | + $p = 0; |
|
424 | + break; |
|
425 | + default: |
|
426 | + $res .= $ch; |
|
427 | + } |
|
428 | + } |
|
429 | + |
|
430 | + $body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
431 | + $function = create_function('$n', $body); |
|
432 | + $this->pluralFunctions[$string] = $function; |
|
433 | + return $function; |
|
434 | + } else { |
|
435 | + // default: one plural form for all cases but n==1 (english) |
|
436 | + $function = create_function( |
|
437 | + '$n', |
|
438 | + '$nplurals=2;$plural=($n==1?0:1);return ($plural>=$nplurals?$nplurals-1:$plural);' |
|
439 | + ); |
|
440 | + $this->pluralFunctions[$string] = $function; |
|
441 | + return $function; |
|
442 | + } |
|
443 | + } |
|
444 | 444 | } |
@@ -137,9 +137,9 @@ discard block |
||
137 | 137 | * |
138 | 138 | * @link https://github.com/owncloud/core/issues/21955 |
139 | 139 | */ |
140 | - if($this->config->getSystemValue('installed', false)) { |
|
141 | - $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
142 | - if(!is_null($userId)) { |
|
140 | + if ($this->config->getSystemValue('installed', false)) { |
|
141 | + $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
142 | + if (!is_null($userId)) { |
|
143 | 143 | $userLang = $this->config->getUserValue($userId, 'core', 'lang', null); |
144 | 144 | } else { |
145 | 145 | $userLang = null; |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | // merge with translations from theme |
209 | 209 | $theme = $this->config->getSystemValue('theme'); |
210 | 210 | if (!empty($theme)) { |
211 | - $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot)); |
|
211 | + $themeDir = $this->serverRoot.'/themes/'.$theme.substr($dir, strlen($this->serverRoot)); |
|
212 | 212 | |
213 | 213 | if (is_dir($themeDir)) { |
214 | 214 | $files = scandir($themeDir); |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | */ |
311 | 311 | private function isSubDirectory($sub, $parent) { |
312 | 312 | // Check whether $sub contains no ".." |
313 | - if(strpos($sub, '..') !== false) { |
|
313 | + if (strpos($sub, '..') !== false) { |
|
314 | 314 | return false; |
315 | 315 | } |
316 | 316 | |
@@ -335,12 +335,12 @@ discard block |
||
335 | 335 | $languageFiles = []; |
336 | 336 | |
337 | 337 | $i18nDir = $this->findL10nDir($app); |
338 | - $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json'; |
|
338 | + $transFile = strip_tags($i18nDir).strip_tags($lang).'.json'; |
|
339 | 339 | |
340 | - if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/') |
|
341 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/') |
|
342 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/') |
|
343 | - || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/') |
|
340 | + if (($this->isSubDirectory($transFile, $this->serverRoot.'/core/l10n/') |
|
341 | + || $this->isSubDirectory($transFile, $this->serverRoot.'/lib/l10n/') |
|
342 | + || $this->isSubDirectory($transFile, $this->serverRoot.'/settings/l10n/') |
|
343 | + || $this->isSubDirectory($transFile, \OC_App::getAppPath($app).'/l10n/') |
|
344 | 344 | ) |
345 | 345 | && file_exists($transFile)) { |
346 | 346 | // load the translations file |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | // merge with translations from theme |
351 | 351 | $theme = $this->config->getSystemValue('theme'); |
352 | 352 | if (!empty($theme)) { |
353 | - $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot)); |
|
353 | + $transFile = $this->serverRoot.'/themes/'.$theme.substr($transFile, strlen($this->serverRoot)); |
|
354 | 354 | if (file_exists($transFile)) { |
355 | 355 | $languageFiles[] = $transFile; |
356 | 356 | } |
@@ -367,14 +367,14 @@ discard block |
||
367 | 367 | */ |
368 | 368 | protected function findL10nDir($app = null) { |
369 | 369 | if (in_array($app, ['core', 'lib', 'settings'])) { |
370 | - if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) { |
|
371 | - return $this->serverRoot . '/' . $app . '/l10n/'; |
|
370 | + if (file_exists($this->serverRoot.'/'.$app.'/l10n/')) { |
|
371 | + return $this->serverRoot.'/'.$app.'/l10n/'; |
|
372 | 372 | } |
373 | 373 | } else if ($app && \OC_App::getAppPath($app) !== false) { |
374 | 374 | // Check if the app is in the app folder |
375 | - return \OC_App::getAppPath($app) . '/l10n/'; |
|
375 | + return \OC_App::getAppPath($app).'/l10n/'; |
|
376 | 376 | } |
377 | - return $this->serverRoot . '/core/l10n/'; |
|
377 | + return $this->serverRoot.'/core/l10n/'; |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | |
@@ -391,15 +391,15 @@ discard block |
||
391 | 391 | return $this->pluralFunctions[$string]; |
392 | 392 | } |
393 | 393 | |
394 | - if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
394 | + if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
395 | 395 | // sanitize |
396 | - $nplurals = preg_replace( '/[^0-9]/', '', $matches[1] ); |
|
397 | - $plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] ); |
|
396 | + $nplurals = preg_replace('/[^0-9]/', '', $matches[1]); |
|
397 | + $plural = preg_replace('#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2]); |
|
398 | 398 | |
399 | 399 | $body = str_replace( |
400 | - array( 'plural', 'n', '$n$plurals', ), |
|
401 | - array( '$plural', '$n', '$nplurals', ), |
|
402 | - 'nplurals='. $nplurals . '; plural=' . $plural |
|
400 | + array('plural', 'n', '$n$plurals',), |
|
401 | + array('$plural', '$n', '$nplurals',), |
|
402 | + 'nplurals='.$nplurals.'; plural='.$plural |
|
403 | 403 | ); |
404 | 404 | |
405 | 405 | // add parents |
@@ -408,9 +408,9 @@ discard block |
||
408 | 408 | $res = ''; |
409 | 409 | $p = 0; |
410 | 410 | $length = strlen($body); |
411 | - for($i = 0; $i < $length; $i++) { |
|
411 | + for ($i = 0; $i < $length; $i++) { |
|
412 | 412 | $ch = $body[$i]; |
413 | - switch ( $ch ) { |
|
413 | + switch ($ch) { |
|
414 | 414 | case '?': |
415 | 415 | $res .= ' ? ('; |
416 | 416 | $p++; |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | $res .= ') : ('; |
420 | 420 | break; |
421 | 421 | case ';': |
422 | - $res .= str_repeat( ')', $p ) . ';'; |
|
422 | + $res .= str_repeat(')', $p).';'; |
|
423 | 423 | $p = 0; |
424 | 424 | break; |
425 | 425 | default: |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | } |
428 | 428 | } |
429 | 429 | |
430 | - $body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
430 | + $body = $res.'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
431 | 431 | $function = create_function('$n', $body); |
432 | 432 | $this->pluralFunctions[$string] = $function; |
433 | 433 | return $function; |
@@ -101,7 +101,7 @@ |
||
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
104 | - * @param $username |
|
104 | + * @param string $username |
|
105 | 105 | * @param IDBConnection $connection |
106 | 106 | * @return array |
107 | 107 | */ |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | $this->createDatabase($connection); |
53 | 53 | |
54 | 54 | //fill the database if needed |
55 | - $query='select count(*) from information_schema.tables where table_schema=? AND table_name = ?'; |
|
55 | + $query = 'select count(*) from information_schema.tables where table_schema=? AND table_name = ?'; |
|
56 | 56 | $connection->executeQuery($query, [$this->dbName, $this->tablePrefix.'users']); |
57 | 57 | } |
58 | 58 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @param \OC\DB\Connection $connection |
61 | 61 | */ |
62 | 62 | private function createDatabase($connection) { |
63 | - try{ |
|
63 | + try { |
|
64 | 64 | $name = $this->dbName; |
65 | 65 | $user = $this->dbUser; |
66 | 66 | //we can't use OC_DB functions here because we need to connect as the administrative user. |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | try { |
80 | 80 | //this query will fail if there aren't the right permissions, ignore the error |
81 | - $query="GRANT ALL PRIVILEGES ON `$name` . * TO '$user'"; |
|
81 | + $query = "GRANT ALL PRIVILEGES ON `$name` . * TO '$user'"; |
|
82 | 82 | $connection->executeUpdate($query); |
83 | 83 | } catch (\Exception $ex) { |
84 | 84 | $this->logger->logException($ex, [ |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @throws \OC\DatabaseSetupException |
95 | 95 | */ |
96 | 96 | private function createDBUser($connection) { |
97 | - try{ |
|
97 | + try { |
|
98 | 98 | $name = $this->dbUser; |
99 | 99 | $password = $this->dbPassword; |
100 | 100 | // we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one, |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'"; |
105 | 105 | $connection->executeUpdate($query); |
106 | 106 | } |
107 | - catch (\Exception $ex){ |
|
107 | + catch (\Exception $ex) { |
|
108 | 108 | $this->logger->logException($ex, [ |
109 | 109 | 'message' => 'Database user creation failed.', |
110 | 110 | 'level' => \OCP\Util::ERROR, |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | //we don't have a dbuser specified in config |
127 | 127 | if ($this->dbUser !== $oldUser) { |
128 | 128 | //add prefix to the admin username to prevent collisions |
129 | - $adminUser = substr('oc_' . $username, 0, 16); |
|
129 | + $adminUser = substr('oc_'.$username, 0, 16); |
|
130 | 130 | |
131 | 131 | $i = 1; |
132 | 132 | while (true) { |
@@ -143,15 +143,15 @@ discard block |
||
143 | 143 | $this->dbUser = $adminUser; |
144 | 144 | |
145 | 145 | //create a random password so we don't need to store the admin password in the config file |
146 | - $this->dbPassword = $this->random->generate(30); |
|
146 | + $this->dbPassword = $this->random->generate(30); |
|
147 | 147 | |
148 | 148 | $this->createDBUser($connection); |
149 | 149 | |
150 | 150 | break; |
151 | 151 | } else { |
152 | 152 | //repeat with different username |
153 | - $length = strlen((string)$i); |
|
154 | - $adminUser = substr('oc_' . $username, 0, 16 - $length) . $i; |
|
153 | + $length = strlen((string) $i); |
|
154 | + $adminUser = substr('oc_'.$username, 0, 16 - $length).$i; |
|
155 | 155 | $i++; |
156 | 156 | } |
157 | 157 | } else { |
@@ -103,8 +103,7 @@ |
||
103 | 103 | $connection->executeUpdate($query); |
104 | 104 | $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'"; |
105 | 105 | $connection->executeUpdate($query); |
106 | - } |
|
107 | - catch (\Exception $ex){ |
|
106 | + } catch (\Exception $ex){ |
|
108 | 107 | $this->logger->logException($ex, [ |
109 | 108 | 'message' => 'Database user creation failed.', |
110 | 109 | 'level' => \OCP\Util::ERROR, |
@@ -33,143 +33,143 @@ |
||
33 | 33 | use OCP\IDBConnection; |
34 | 34 | |
35 | 35 | class MySQL extends AbstractDatabase { |
36 | - public $dbprettyname = 'MySQL/MariaDB'; |
|
37 | - |
|
38 | - public function setupDatabase($username) { |
|
39 | - //check if the database user has admin right |
|
40 | - $connection = $this->connect(['dbname' => null]); |
|
41 | - |
|
42 | - // detect mb4 |
|
43 | - $tools = new MySqlTools(); |
|
44 | - if ($tools->supports4ByteCharset($connection)) { |
|
45 | - $this->config->setValue('mysql.utf8mb4', true); |
|
46 | - $connection = $this->connect(['dbname' => null]); |
|
47 | - } |
|
48 | - |
|
49 | - $this->createSpecificUser($username, $connection); |
|
50 | - |
|
51 | - //create the database |
|
52 | - $this->createDatabase($connection); |
|
53 | - |
|
54 | - //fill the database if needed |
|
55 | - $query='select count(*) from information_schema.tables where table_schema=? AND table_name = ?'; |
|
56 | - $connection->executeQuery($query, [$this->dbName, $this->tablePrefix.'users']); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @param \OC\DB\Connection $connection |
|
61 | - */ |
|
62 | - private function createDatabase($connection) { |
|
63 | - try{ |
|
64 | - $name = $this->dbName; |
|
65 | - $user = $this->dbUser; |
|
66 | - //we can't use OC_DB functions here because we need to connect as the administrative user. |
|
67 | - $characterSet = $this->config->getValue('mysql.utf8mb4', false) ? 'utf8mb4' : 'utf8'; |
|
68 | - $query = "CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET $characterSet COLLATE ${characterSet}_bin;"; |
|
69 | - $connection->executeUpdate($query); |
|
70 | - } catch (\Exception $ex) { |
|
71 | - $this->logger->logException($ex, [ |
|
72 | - 'message' => 'Database creation failed.', |
|
73 | - 'level' => \OCP\Util::ERROR, |
|
74 | - 'app' => 'mysql.setup', |
|
75 | - ]); |
|
76 | - return; |
|
77 | - } |
|
78 | - |
|
79 | - try { |
|
80 | - //this query will fail if there aren't the right permissions, ignore the error |
|
81 | - $query="GRANT ALL PRIVILEGES ON `$name` . * TO '$user'"; |
|
82 | - $connection->executeUpdate($query); |
|
83 | - } catch (\Exception $ex) { |
|
84 | - $this->logger->logException($ex, [ |
|
85 | - 'message' => 'Could not automatically grant privileges, this can be ignored if database user already had privileges.', |
|
86 | - 'level' => \OCP\Util::DEBUG, |
|
87 | - 'app' => 'mysql.setup', |
|
88 | - ]); |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @param IDBConnection $connection |
|
94 | - * @throws \OC\DatabaseSetupException |
|
95 | - */ |
|
96 | - private function createDBUser($connection) { |
|
97 | - try{ |
|
98 | - $name = $this->dbUser; |
|
99 | - $password = $this->dbPassword; |
|
100 | - // we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one, |
|
101 | - // the anonymous user would take precedence when there is one. |
|
102 | - $query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'"; |
|
103 | - $connection->executeUpdate($query); |
|
104 | - $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'"; |
|
105 | - $connection->executeUpdate($query); |
|
106 | - } |
|
107 | - catch (\Exception $ex){ |
|
108 | - $this->logger->logException($ex, [ |
|
109 | - 'message' => 'Database user creation failed.', |
|
110 | - 'level' => \OCP\Util::ERROR, |
|
111 | - 'app' => 'mysql.setup', |
|
112 | - ]); |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * @param $username |
|
118 | - * @param IDBConnection $connection |
|
119 | - * @return array |
|
120 | - */ |
|
121 | - private function createSpecificUser($username, $connection) { |
|
122 | - try { |
|
123 | - //user already specified in config |
|
124 | - $oldUser = $this->config->getValue('dbuser', false); |
|
125 | - |
|
126 | - //we don't have a dbuser specified in config |
|
127 | - if ($this->dbUser !== $oldUser) { |
|
128 | - //add prefix to the admin username to prevent collisions |
|
129 | - $adminUser = substr('oc_' . $username, 0, 16); |
|
130 | - |
|
131 | - $i = 1; |
|
132 | - while (true) { |
|
133 | - //this should be enough to check for admin rights in mysql |
|
134 | - $query = 'SELECT user FROM mysql.user WHERE user=?'; |
|
135 | - $result = $connection->executeQuery($query, [$adminUser]); |
|
136 | - |
|
137 | - //current dbuser has admin rights |
|
138 | - if ($result) { |
|
139 | - $data = $result->fetchAll(); |
|
140 | - //new dbuser does not exist |
|
141 | - if (count($data) === 0) { |
|
142 | - //use the admin login data for the new database user |
|
143 | - $this->dbUser = $adminUser; |
|
144 | - |
|
145 | - //create a random password so we don't need to store the admin password in the config file |
|
146 | - $this->dbPassword = $this->random->generate(30); |
|
147 | - |
|
148 | - $this->createDBUser($connection); |
|
149 | - |
|
150 | - break; |
|
151 | - } else { |
|
152 | - //repeat with different username |
|
153 | - $length = strlen((string)$i); |
|
154 | - $adminUser = substr('oc_' . $username, 0, 16 - $length) . $i; |
|
155 | - $i++; |
|
156 | - } |
|
157 | - } else { |
|
158 | - break; |
|
159 | - } |
|
160 | - } |
|
161 | - } |
|
162 | - } catch (\Exception $ex) { |
|
163 | - $this->logger->logException($ex, [ |
|
164 | - 'message' => 'Can not create a new MySQL user, will continue with the provided user.', |
|
165 | - 'level' => \OCP\Util::INFO, |
|
166 | - 'app' => 'mysql.setup', |
|
167 | - ]); |
|
168 | - } |
|
169 | - |
|
170 | - $this->config->setValues([ |
|
171 | - 'dbuser' => $this->dbUser, |
|
172 | - 'dbpassword' => $this->dbPassword, |
|
173 | - ]); |
|
174 | - } |
|
36 | + public $dbprettyname = 'MySQL/MariaDB'; |
|
37 | + |
|
38 | + public function setupDatabase($username) { |
|
39 | + //check if the database user has admin right |
|
40 | + $connection = $this->connect(['dbname' => null]); |
|
41 | + |
|
42 | + // detect mb4 |
|
43 | + $tools = new MySqlTools(); |
|
44 | + if ($tools->supports4ByteCharset($connection)) { |
|
45 | + $this->config->setValue('mysql.utf8mb4', true); |
|
46 | + $connection = $this->connect(['dbname' => null]); |
|
47 | + } |
|
48 | + |
|
49 | + $this->createSpecificUser($username, $connection); |
|
50 | + |
|
51 | + //create the database |
|
52 | + $this->createDatabase($connection); |
|
53 | + |
|
54 | + //fill the database if needed |
|
55 | + $query='select count(*) from information_schema.tables where table_schema=? AND table_name = ?'; |
|
56 | + $connection->executeQuery($query, [$this->dbName, $this->tablePrefix.'users']); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @param \OC\DB\Connection $connection |
|
61 | + */ |
|
62 | + private function createDatabase($connection) { |
|
63 | + try{ |
|
64 | + $name = $this->dbName; |
|
65 | + $user = $this->dbUser; |
|
66 | + //we can't use OC_DB functions here because we need to connect as the administrative user. |
|
67 | + $characterSet = $this->config->getValue('mysql.utf8mb4', false) ? 'utf8mb4' : 'utf8'; |
|
68 | + $query = "CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET $characterSet COLLATE ${characterSet}_bin;"; |
|
69 | + $connection->executeUpdate($query); |
|
70 | + } catch (\Exception $ex) { |
|
71 | + $this->logger->logException($ex, [ |
|
72 | + 'message' => 'Database creation failed.', |
|
73 | + 'level' => \OCP\Util::ERROR, |
|
74 | + 'app' => 'mysql.setup', |
|
75 | + ]); |
|
76 | + return; |
|
77 | + } |
|
78 | + |
|
79 | + try { |
|
80 | + //this query will fail if there aren't the right permissions, ignore the error |
|
81 | + $query="GRANT ALL PRIVILEGES ON `$name` . * TO '$user'"; |
|
82 | + $connection->executeUpdate($query); |
|
83 | + } catch (\Exception $ex) { |
|
84 | + $this->logger->logException($ex, [ |
|
85 | + 'message' => 'Could not automatically grant privileges, this can be ignored if database user already had privileges.', |
|
86 | + 'level' => \OCP\Util::DEBUG, |
|
87 | + 'app' => 'mysql.setup', |
|
88 | + ]); |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @param IDBConnection $connection |
|
94 | + * @throws \OC\DatabaseSetupException |
|
95 | + */ |
|
96 | + private function createDBUser($connection) { |
|
97 | + try{ |
|
98 | + $name = $this->dbUser; |
|
99 | + $password = $this->dbPassword; |
|
100 | + // we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one, |
|
101 | + // the anonymous user would take precedence when there is one. |
|
102 | + $query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'"; |
|
103 | + $connection->executeUpdate($query); |
|
104 | + $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'"; |
|
105 | + $connection->executeUpdate($query); |
|
106 | + } |
|
107 | + catch (\Exception $ex){ |
|
108 | + $this->logger->logException($ex, [ |
|
109 | + 'message' => 'Database user creation failed.', |
|
110 | + 'level' => \OCP\Util::ERROR, |
|
111 | + 'app' => 'mysql.setup', |
|
112 | + ]); |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * @param $username |
|
118 | + * @param IDBConnection $connection |
|
119 | + * @return array |
|
120 | + */ |
|
121 | + private function createSpecificUser($username, $connection) { |
|
122 | + try { |
|
123 | + //user already specified in config |
|
124 | + $oldUser = $this->config->getValue('dbuser', false); |
|
125 | + |
|
126 | + //we don't have a dbuser specified in config |
|
127 | + if ($this->dbUser !== $oldUser) { |
|
128 | + //add prefix to the admin username to prevent collisions |
|
129 | + $adminUser = substr('oc_' . $username, 0, 16); |
|
130 | + |
|
131 | + $i = 1; |
|
132 | + while (true) { |
|
133 | + //this should be enough to check for admin rights in mysql |
|
134 | + $query = 'SELECT user FROM mysql.user WHERE user=?'; |
|
135 | + $result = $connection->executeQuery($query, [$adminUser]); |
|
136 | + |
|
137 | + //current dbuser has admin rights |
|
138 | + if ($result) { |
|
139 | + $data = $result->fetchAll(); |
|
140 | + //new dbuser does not exist |
|
141 | + if (count($data) === 0) { |
|
142 | + //use the admin login data for the new database user |
|
143 | + $this->dbUser = $adminUser; |
|
144 | + |
|
145 | + //create a random password so we don't need to store the admin password in the config file |
|
146 | + $this->dbPassword = $this->random->generate(30); |
|
147 | + |
|
148 | + $this->createDBUser($connection); |
|
149 | + |
|
150 | + break; |
|
151 | + } else { |
|
152 | + //repeat with different username |
|
153 | + $length = strlen((string)$i); |
|
154 | + $adminUser = substr('oc_' . $username, 0, 16 - $length) . $i; |
|
155 | + $i++; |
|
156 | + } |
|
157 | + } else { |
|
158 | + break; |
|
159 | + } |
|
160 | + } |
|
161 | + } |
|
162 | + } catch (\Exception $ex) { |
|
163 | + $this->logger->logException($ex, [ |
|
164 | + 'message' => 'Can not create a new MySQL user, will continue with the provided user.', |
|
165 | + 'level' => \OCP\Util::INFO, |
|
166 | + 'app' => 'mysql.setup', |
|
167 | + ]); |
|
168 | + } |
|
169 | + |
|
170 | + $this->config->setValues([ |
|
171 | + 'dbuser' => $this->dbUser, |
|
172 | + 'dbpassword' => $this->dbPassword, |
|
173 | + ]); |
|
174 | + } |
|
175 | 175 | } |
@@ -360,6 +360,9 @@ discard block |
||
360 | 360 | } |
361 | 361 | } |
362 | 362 | |
363 | + /** |
|
364 | + * @param string $root |
|
365 | + */ |
|
363 | 366 | static public function init($user, $root) { |
364 | 367 | if (self::$defaultInstance) { |
365 | 368 | return false; |
@@ -528,7 +531,7 @@ discard block |
||
528 | 531 | /** |
529 | 532 | * mount an \OC\Files\Storage\Storage in our virtual filesystem |
530 | 533 | * |
531 | - * @param \OC\Files\Storage\Storage|string $class |
|
534 | + * @param string $class |
|
532 | 535 | * @param array $arguments |
533 | 536 | * @param string $mountpoint |
534 | 537 | */ |
@@ -660,6 +663,9 @@ discard block |
||
660 | 663 | return self::$defaultInstance->is_dir($path); |
661 | 664 | } |
662 | 665 | |
666 | + /** |
|
667 | + * @param string $path |
|
668 | + */ |
|
663 | 669 | static public function is_file($path) { |
664 | 670 | return self::$defaultInstance->is_file($path); |
665 | 671 | } |
@@ -672,6 +678,9 @@ discard block |
||
672 | 678 | return self::$defaultInstance->filetype($path); |
673 | 679 | } |
674 | 680 | |
681 | + /** |
|
682 | + * @param string $path |
|
683 | + */ |
|
675 | 684 | static public function filesize($path) { |
676 | 685 | return self::$defaultInstance->filesize($path); |
677 | 686 | } |
@@ -684,6 +693,9 @@ discard block |
||
684 | 693 | return self::$defaultInstance->isCreatable($path); |
685 | 694 | } |
686 | 695 | |
696 | + /** |
|
697 | + * @param string $path |
|
698 | + */ |
|
687 | 699 | static public function isReadable($path) { |
688 | 700 | return self::$defaultInstance->isReadable($path); |
689 | 701 | } |
@@ -696,6 +708,9 @@ discard block |
||
696 | 708 | return self::$defaultInstance->isDeletable($path); |
697 | 709 | } |
698 | 710 | |
711 | + /** |
|
712 | + * @param string $path |
|
713 | + */ |
|
699 | 714 | static public function isSharable($path) { |
700 | 715 | return self::$defaultInstance->isSharable($path); |
701 | 716 | } |
@@ -704,6 +719,9 @@ discard block |
||
704 | 719 | return self::$defaultInstance->file_exists($path); |
705 | 720 | } |
706 | 721 | |
722 | + /** |
|
723 | + * @param string $path |
|
724 | + */ |
|
707 | 725 | static public function filemtime($path) { |
708 | 726 | return self::$defaultInstance->filemtime($path); |
709 | 727 | } |
@@ -713,6 +731,7 @@ discard block |
||
713 | 731 | } |
714 | 732 | |
715 | 733 | /** |
734 | + * @param string $path |
|
716 | 735 | * @return string |
717 | 736 | */ |
718 | 737 | static public function file_get_contents($path) { |
@@ -735,6 +754,10 @@ discard block |
||
735 | 754 | return self::$defaultInstance->copy($path1, $path2); |
736 | 755 | } |
737 | 756 | |
757 | + /** |
|
758 | + * @param string $path |
|
759 | + * @param string $mode |
|
760 | + */ |
|
738 | 761 | static public function fopen($path, $mode) { |
739 | 762 | return self::$defaultInstance->fopen($path, $mode); |
740 | 763 | } |
@@ -750,6 +773,9 @@ discard block |
||
750 | 773 | return self::$defaultInstance->fromTmpFile($tmpFile, $path); |
751 | 774 | } |
752 | 775 | |
776 | + /** |
|
777 | + * @param string $path |
|
778 | + */ |
|
753 | 779 | static public function getMimeType($path) { |
754 | 780 | return self::$defaultInstance->getMimeType($path); |
755 | 781 | } |
@@ -762,6 +788,9 @@ discard block |
||
762 | 788 | return self::$defaultInstance->free_space($path); |
763 | 789 | } |
764 | 790 | |
791 | + /** |
|
792 | + * @param string $query |
|
793 | + */ |
|
765 | 794 | static public function search($query) { |
766 | 795 | return self::$defaultInstance->search($query); |
767 | 796 | } |
@@ -870,7 +899,7 @@ discard block |
||
870 | 899 | * @param string $path |
871 | 900 | * @param boolean $includeMountPoints whether to add mountpoint sizes, |
872 | 901 | * defaults to true |
873 | - * @return \OC\Files\FileInfo|bool False if file does not exist |
|
902 | + * @return \OCP\Files\FileInfo|null False if file does not exist |
|
874 | 903 | */ |
875 | 904 | public static function getFileInfo($path, $includeMountPoints = true) { |
876 | 905 | return self::$defaultInstance->getFileInfo($path, $includeMountPoints); |
@@ -409,17 +409,17 @@ discard block |
||
409 | 409 | $userObject = $userManager->get($user); |
410 | 410 | |
411 | 411 | if (is_null($userObject)) { |
412 | - \OCP\Util::writeLog('files', ' Backends provided no user object for ' . $user, \OCP\Util::ERROR); |
|
412 | + \OCP\Util::writeLog('files', ' Backends provided no user object for '.$user, \OCP\Util::ERROR); |
|
413 | 413 | // reset flag, this will make it possible to rethrow the exception if called again |
414 | 414 | unset(self::$usersSetup[$user]); |
415 | - throw new \OC\User\NoUserException('Backends provided no user object for ' . $user); |
|
415 | + throw new \OC\User\NoUserException('Backends provided no user object for '.$user); |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | $realUid = $userObject->getUID(); |
419 | 419 | // workaround in case of different casings |
420 | 420 | if ($user !== $realUid) { |
421 | 421 | $stack = json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 50)); |
422 | - \OCP\Util::writeLog('files', 'initMountPoints() called with wrong user casing. This could be a bug. Expected: "' . $realUid . '" got "' . $user . '". Stack: ' . $stack, \OCP\Util::WARN); |
|
422 | + \OCP\Util::writeLog('files', 'initMountPoints() called with wrong user casing. This could be a bug. Expected: "'.$realUid.'" got "'.$user.'". Stack: '.$stack, \OCP\Util::WARN); |
|
423 | 423 | $user = $realUid; |
424 | 424 | |
425 | 425 | // again with the correct casing |
@@ -453,11 +453,11 @@ discard block |
||
453 | 453 | } else { |
454 | 454 | self::getMountManager()->addMount(new MountPoint( |
455 | 455 | new NullStorage([]), |
456 | - '/' . $user |
|
456 | + '/'.$user |
|
457 | 457 | )); |
458 | 458 | self::getMountManager()->addMount(new MountPoint( |
459 | 459 | new NullStorage([]), |
460 | - '/' . $user . '/files' |
|
460 | + '/'.$user.'/files' |
|
461 | 461 | )); |
462 | 462 | } |
463 | 463 | \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', array('user' => $user)); |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | private static function listenForNewMountProviders(MountProviderCollection $mountConfigManager, IUserManager $userManager) { |
473 | 473 | if (!self::$listeningForProviders) { |
474 | 474 | self::$listeningForProviders = true; |
475 | - $mountConfigManager->listen('\OC\Files\Config', 'registerMountProvider', function (IMountProvider $provider) use ($userManager) { |
|
475 | + $mountConfigManager->listen('\OC\Files\Config', 'registerMountProvider', function(IMountProvider $provider) use ($userManager) { |
|
476 | 476 | foreach (Filesystem::$usersSetup as $user => $setup) { |
477 | 477 | $userObject = $userManager->get($user); |
478 | 478 | if ($userObject) { |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | * @return string |
568 | 568 | */ |
569 | 569 | static public function getLocalPath($path) { |
570 | - $datadir = \OC_User::getHome(\OC_User::getUser()) . '/files'; |
|
570 | + $datadir = \OC_User::getHome(\OC_User::getUser()).'/files'; |
|
571 | 571 | $newpath = $path; |
572 | 572 | if (strncmp($newpath, $datadir, strlen($datadir)) == 0) { |
573 | 573 | $newpath = substr($path, strlen($datadir)); |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | static public function isValidPath($path) { |
585 | 585 | $path = self::normalizePath($path); |
586 | 586 | if (!$path || $path[0] !== '/') { |
587 | - $path = '/' . $path; |
|
587 | + $path = '/'.$path; |
|
588 | 588 | } |
589 | 589 | if (strpos($path, '/../') !== false || strrchr($path, '/') === '/..') { |
590 | 590 | return false; |
@@ -813,7 +813,7 @@ discard block |
||
813 | 813 | * conversion should get removed as soon as all existing |
814 | 814 | * function calls have been fixed. |
815 | 815 | */ |
816 | - $path = (string)$path; |
|
816 | + $path = (string) $path; |
|
817 | 817 | |
818 | 818 | $cacheKey = json_encode([$path, $stripTrailingSlash, $isAbsolutePath, $keepUnicode]); |
819 | 819 | |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | |
836 | 836 | //add leading slash |
837 | 837 | if ($path[0] !== '/') { |
838 | - $path = '/' . $path; |
|
838 | + $path = '/'.$path; |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | // remove '/./' |
@@ -69,857 +69,857 @@ |
||
69 | 69 | |
70 | 70 | class Filesystem { |
71 | 71 | |
72 | - /** |
|
73 | - * @var Mount\Manager $mounts |
|
74 | - */ |
|
75 | - private static $mounts; |
|
76 | - |
|
77 | - public static $loaded = false; |
|
78 | - /** |
|
79 | - * @var \OC\Files\View $defaultInstance |
|
80 | - */ |
|
81 | - static private $defaultInstance; |
|
82 | - |
|
83 | - static private $usersSetup = array(); |
|
84 | - |
|
85 | - static private $normalizedPathCache = null; |
|
86 | - |
|
87 | - static private $listeningForProviders = false; |
|
88 | - |
|
89 | - /** |
|
90 | - * classname which used for hooks handling |
|
91 | - * used as signalclass in OC_Hooks::emit() |
|
92 | - */ |
|
93 | - const CLASSNAME = 'OC_Filesystem'; |
|
94 | - |
|
95 | - /** |
|
96 | - * signalname emitted before file renaming |
|
97 | - * |
|
98 | - * @param string $oldpath |
|
99 | - * @param string $newpath |
|
100 | - */ |
|
101 | - const signal_rename = 'rename'; |
|
102 | - |
|
103 | - /** |
|
104 | - * signal emitted after file renaming |
|
105 | - * |
|
106 | - * @param string $oldpath |
|
107 | - * @param string $newpath |
|
108 | - */ |
|
109 | - const signal_post_rename = 'post_rename'; |
|
110 | - |
|
111 | - /** |
|
112 | - * signal emitted before file/dir creation |
|
113 | - * |
|
114 | - * @param string $path |
|
115 | - * @param bool $run changing this flag to false in hook handler will cancel event |
|
116 | - */ |
|
117 | - const signal_create = 'create'; |
|
118 | - |
|
119 | - /** |
|
120 | - * signal emitted after file/dir creation |
|
121 | - * |
|
122 | - * @param string $path |
|
123 | - * @param bool $run changing this flag to false in hook handler will cancel event |
|
124 | - */ |
|
125 | - const signal_post_create = 'post_create'; |
|
126 | - |
|
127 | - /** |
|
128 | - * signal emits before file/dir copy |
|
129 | - * |
|
130 | - * @param string $oldpath |
|
131 | - * @param string $newpath |
|
132 | - * @param bool $run changing this flag to false in hook handler will cancel event |
|
133 | - */ |
|
134 | - const signal_copy = 'copy'; |
|
135 | - |
|
136 | - /** |
|
137 | - * signal emits after file/dir copy |
|
138 | - * |
|
139 | - * @param string $oldpath |
|
140 | - * @param string $newpath |
|
141 | - */ |
|
142 | - const signal_post_copy = 'post_copy'; |
|
143 | - |
|
144 | - /** |
|
145 | - * signal emits before file/dir save |
|
146 | - * |
|
147 | - * @param string $path |
|
148 | - * @param bool $run changing this flag to false in hook handler will cancel event |
|
149 | - */ |
|
150 | - const signal_write = 'write'; |
|
151 | - |
|
152 | - /** |
|
153 | - * signal emits after file/dir save |
|
154 | - * |
|
155 | - * @param string $path |
|
156 | - */ |
|
157 | - const signal_post_write = 'post_write'; |
|
158 | - |
|
159 | - /** |
|
160 | - * signal emitted before file/dir update |
|
161 | - * |
|
162 | - * @param string $path |
|
163 | - * @param bool $run changing this flag to false in hook handler will cancel event |
|
164 | - */ |
|
165 | - const signal_update = 'update'; |
|
166 | - |
|
167 | - /** |
|
168 | - * signal emitted after file/dir update |
|
169 | - * |
|
170 | - * @param string $path |
|
171 | - * @param bool $run changing this flag to false in hook handler will cancel event |
|
172 | - */ |
|
173 | - const signal_post_update = 'post_update'; |
|
174 | - |
|
175 | - /** |
|
176 | - * signal emits when reading file/dir |
|
177 | - * |
|
178 | - * @param string $path |
|
179 | - */ |
|
180 | - const signal_read = 'read'; |
|
181 | - |
|
182 | - /** |
|
183 | - * signal emits when removing file/dir |
|
184 | - * |
|
185 | - * @param string $path |
|
186 | - */ |
|
187 | - const signal_delete = 'delete'; |
|
188 | - |
|
189 | - /** |
|
190 | - * parameters definitions for signals |
|
191 | - */ |
|
192 | - const signal_param_path = 'path'; |
|
193 | - const signal_param_oldpath = 'oldpath'; |
|
194 | - const signal_param_newpath = 'newpath'; |
|
195 | - |
|
196 | - /** |
|
197 | - * run - changing this flag to false in hook handler will cancel event |
|
198 | - */ |
|
199 | - const signal_param_run = 'run'; |
|
200 | - |
|
201 | - const signal_create_mount = 'create_mount'; |
|
202 | - const signal_delete_mount = 'delete_mount'; |
|
203 | - const signal_param_mount_type = 'mounttype'; |
|
204 | - const signal_param_users = 'users'; |
|
205 | - |
|
206 | - /** |
|
207 | - * @var \OC\Files\Storage\StorageFactory $loader |
|
208 | - */ |
|
209 | - private static $loader; |
|
210 | - |
|
211 | - /** @var bool */ |
|
212 | - private static $logWarningWhenAddingStorageWrapper = true; |
|
213 | - |
|
214 | - /** |
|
215 | - * @param bool $shouldLog |
|
216 | - * @return bool previous value |
|
217 | - * @internal |
|
218 | - */ |
|
219 | - public static function logWarningWhenAddingStorageWrapper($shouldLog) { |
|
220 | - $previousValue = self::$logWarningWhenAddingStorageWrapper; |
|
221 | - self::$logWarningWhenAddingStorageWrapper = (bool) $shouldLog; |
|
222 | - return $previousValue; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * @param string $wrapperName |
|
227 | - * @param callable $wrapper |
|
228 | - * @param int $priority |
|
229 | - */ |
|
230 | - public static function addStorageWrapper($wrapperName, $wrapper, $priority = 50) { |
|
231 | - if (self::$logWarningWhenAddingStorageWrapper) { |
|
232 | - \OC::$server->getLogger()->warning("Storage wrapper '{wrapper}' was not registered via the 'OC_Filesystem - preSetup' hook which could cause potential problems.", [ |
|
233 | - 'wrapper' => $wrapperName, |
|
234 | - 'app' => 'filesystem', |
|
235 | - ]); |
|
236 | - } |
|
237 | - |
|
238 | - $mounts = self::getMountManager()->getAll(); |
|
239 | - if (!self::getLoader()->addStorageWrapper($wrapperName, $wrapper, $priority, $mounts)) { |
|
240 | - // do not re-wrap if storage with this name already existed |
|
241 | - return; |
|
242 | - } |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * Returns the storage factory |
|
247 | - * |
|
248 | - * @return \OCP\Files\Storage\IStorageFactory |
|
249 | - */ |
|
250 | - public static function getLoader() { |
|
251 | - if (!self::$loader) { |
|
252 | - self::$loader = new StorageFactory(); |
|
253 | - } |
|
254 | - return self::$loader; |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Returns the mount manager |
|
259 | - * |
|
260 | - * @return \OC\Files\Mount\Manager |
|
261 | - */ |
|
262 | - public static function getMountManager($user = '') { |
|
263 | - if (!self::$mounts) { |
|
264 | - \OC_Util::setupFS($user); |
|
265 | - } |
|
266 | - return self::$mounts; |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * get the mountpoint of the storage object for a path |
|
271 | - * ( note: because a storage is not always mounted inside the fakeroot, the |
|
272 | - * returned mountpoint is relative to the absolute root of the filesystem |
|
273 | - * and doesn't take the chroot into account ) |
|
274 | - * |
|
275 | - * @param string $path |
|
276 | - * @return string |
|
277 | - */ |
|
278 | - static public function getMountPoint($path) { |
|
279 | - if (!self::$mounts) { |
|
280 | - \OC_Util::setupFS(); |
|
281 | - } |
|
282 | - $mount = self::$mounts->find($path); |
|
283 | - if ($mount) { |
|
284 | - return $mount->getMountPoint(); |
|
285 | - } else { |
|
286 | - return ''; |
|
287 | - } |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * get a list of all mount points in a directory |
|
292 | - * |
|
293 | - * @param string $path |
|
294 | - * @return string[] |
|
295 | - */ |
|
296 | - static public function getMountPoints($path) { |
|
297 | - if (!self::$mounts) { |
|
298 | - \OC_Util::setupFS(); |
|
299 | - } |
|
300 | - $result = array(); |
|
301 | - $mounts = self::$mounts->findIn($path); |
|
302 | - foreach ($mounts as $mount) { |
|
303 | - $result[] = $mount->getMountPoint(); |
|
304 | - } |
|
305 | - return $result; |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * get the storage mounted at $mountPoint |
|
310 | - * |
|
311 | - * @param string $mountPoint |
|
312 | - * @return \OC\Files\Storage\Storage |
|
313 | - */ |
|
314 | - public static function getStorage($mountPoint) { |
|
315 | - if (!self::$mounts) { |
|
316 | - \OC_Util::setupFS(); |
|
317 | - } |
|
318 | - $mount = self::$mounts->find($mountPoint); |
|
319 | - return $mount->getStorage(); |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * @param string $id |
|
324 | - * @return Mount\MountPoint[] |
|
325 | - */ |
|
326 | - public static function getMountByStorageId($id) { |
|
327 | - if (!self::$mounts) { |
|
328 | - \OC_Util::setupFS(); |
|
329 | - } |
|
330 | - return self::$mounts->findByStorageId($id); |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * @param int $id |
|
335 | - * @return Mount\MountPoint[] |
|
336 | - */ |
|
337 | - public static function getMountByNumericId($id) { |
|
338 | - if (!self::$mounts) { |
|
339 | - \OC_Util::setupFS(); |
|
340 | - } |
|
341 | - return self::$mounts->findByNumericId($id); |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * resolve a path to a storage and internal path |
|
346 | - * |
|
347 | - * @param string $path |
|
348 | - * @return array an array consisting of the storage and the internal path |
|
349 | - */ |
|
350 | - static public function resolvePath($path) { |
|
351 | - if (!self::$mounts) { |
|
352 | - \OC_Util::setupFS(); |
|
353 | - } |
|
354 | - $mount = self::$mounts->find($path); |
|
355 | - if ($mount) { |
|
356 | - return array($mount->getStorage(), rtrim($mount->getInternalPath($path), '/')); |
|
357 | - } else { |
|
358 | - return array(null, null); |
|
359 | - } |
|
360 | - } |
|
361 | - |
|
362 | - static public function init($user, $root) { |
|
363 | - if (self::$defaultInstance) { |
|
364 | - return false; |
|
365 | - } |
|
366 | - self::getLoader(); |
|
367 | - self::$defaultInstance = new View($root); |
|
368 | - |
|
369 | - if (!self::$mounts) { |
|
370 | - self::$mounts = \OC::$server->getMountManager(); |
|
371 | - } |
|
372 | - |
|
373 | - //load custom mount config |
|
374 | - self::initMountPoints($user); |
|
375 | - |
|
376 | - self::$loaded = true; |
|
377 | - |
|
378 | - return true; |
|
379 | - } |
|
380 | - |
|
381 | - static public function initMountManager() { |
|
382 | - if (!self::$mounts) { |
|
383 | - self::$mounts = \OC::$server->getMountManager(); |
|
384 | - } |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * Initialize system and personal mount points for a user |
|
389 | - * |
|
390 | - * @param string $user |
|
391 | - * @throws \OC\User\NoUserException if the user is not available |
|
392 | - */ |
|
393 | - public static function initMountPoints($user = '') { |
|
394 | - if ($user == '') { |
|
395 | - $user = \OC_User::getUser(); |
|
396 | - } |
|
397 | - if ($user === null || $user === false || $user === '') { |
|
398 | - throw new \OC\User\NoUserException('Attempted to initialize mount points for null user and no user in session'); |
|
399 | - } |
|
400 | - |
|
401 | - if (isset(self::$usersSetup[$user])) { |
|
402 | - return; |
|
403 | - } |
|
404 | - |
|
405 | - self::$usersSetup[$user] = true; |
|
406 | - |
|
407 | - $userManager = \OC::$server->getUserManager(); |
|
408 | - $userObject = $userManager->get($user); |
|
409 | - |
|
410 | - if (is_null($userObject)) { |
|
411 | - \OCP\Util::writeLog('files', ' Backends provided no user object for ' . $user, \OCP\Util::ERROR); |
|
412 | - // reset flag, this will make it possible to rethrow the exception if called again |
|
413 | - unset(self::$usersSetup[$user]); |
|
414 | - throw new \OC\User\NoUserException('Backends provided no user object for ' . $user); |
|
415 | - } |
|
416 | - |
|
417 | - $realUid = $userObject->getUID(); |
|
418 | - // workaround in case of different casings |
|
419 | - if ($user !== $realUid) { |
|
420 | - $stack = json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 50)); |
|
421 | - \OCP\Util::writeLog('files', 'initMountPoints() called with wrong user casing. This could be a bug. Expected: "' . $realUid . '" got "' . $user . '". Stack: ' . $stack, \OCP\Util::WARN); |
|
422 | - $user = $realUid; |
|
423 | - |
|
424 | - // again with the correct casing |
|
425 | - if (isset(self::$usersSetup[$user])) { |
|
426 | - return; |
|
427 | - } |
|
428 | - |
|
429 | - self::$usersSetup[$user] = true; |
|
430 | - } |
|
431 | - |
|
432 | - if (\OC::$server->getLockdownManager()->canAccessFilesystem()) { |
|
433 | - /** @var \OC\Files\Config\MountProviderCollection $mountConfigManager */ |
|
434 | - $mountConfigManager = \OC::$server->getMountProviderCollection(); |
|
435 | - |
|
436 | - // home mounts are handled seperate since we need to ensure this is mounted before we call the other mount providers |
|
437 | - $homeMount = $mountConfigManager->getHomeMountForUser($userObject); |
|
438 | - |
|
439 | - self::getMountManager()->addMount($homeMount); |
|
440 | - |
|
441 | - \OC\Files\Filesystem::getStorage($user); |
|
442 | - |
|
443 | - // Chance to mount for other storages |
|
444 | - if ($userObject) { |
|
445 | - $mounts = $mountConfigManager->addMountForUser($userObject, self::getMountManager()); |
|
446 | - $mounts[] = $homeMount; |
|
447 | - $mountConfigManager->registerMounts($userObject, $mounts); |
|
448 | - } |
|
449 | - |
|
450 | - self::listenForNewMountProviders($mountConfigManager, $userManager); |
|
451 | - } else { |
|
452 | - self::getMountManager()->addMount(new MountPoint( |
|
453 | - new NullStorage([]), |
|
454 | - '/' . $user |
|
455 | - )); |
|
456 | - self::getMountManager()->addMount(new MountPoint( |
|
457 | - new NullStorage([]), |
|
458 | - '/' . $user . '/files' |
|
459 | - )); |
|
460 | - } |
|
461 | - \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', array('user' => $user)); |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Get mounts from mount providers that are registered after setup |
|
466 | - * |
|
467 | - * @param MountProviderCollection $mountConfigManager |
|
468 | - * @param IUserManager $userManager |
|
469 | - */ |
|
470 | - private static function listenForNewMountProviders(MountProviderCollection $mountConfigManager, IUserManager $userManager) { |
|
471 | - if (!self::$listeningForProviders) { |
|
472 | - self::$listeningForProviders = true; |
|
473 | - $mountConfigManager->listen('\OC\Files\Config', 'registerMountProvider', function (IMountProvider $provider) use ($userManager) { |
|
474 | - foreach (Filesystem::$usersSetup as $user => $setup) { |
|
475 | - $userObject = $userManager->get($user); |
|
476 | - if ($userObject) { |
|
477 | - $mounts = $provider->getMountsForUser($userObject, Filesystem::getLoader()); |
|
478 | - array_walk($mounts, array(self::$mounts, 'addMount')); |
|
479 | - } |
|
480 | - } |
|
481 | - }); |
|
482 | - } |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * get the default filesystem view |
|
487 | - * |
|
488 | - * @return View |
|
489 | - */ |
|
490 | - static public function getView() { |
|
491 | - return self::$defaultInstance; |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * tear down the filesystem, removing all storage providers |
|
496 | - */ |
|
497 | - static public function tearDown() { |
|
498 | - self::clearMounts(); |
|
499 | - self::$defaultInstance = null; |
|
500 | - } |
|
501 | - |
|
502 | - /** |
|
503 | - * get the relative path of the root data directory for the current user |
|
504 | - * |
|
505 | - * @return string |
|
506 | - * |
|
507 | - * Returns path like /admin/files |
|
508 | - */ |
|
509 | - static public function getRoot() { |
|
510 | - if (!self::$defaultInstance) { |
|
511 | - return null; |
|
512 | - } |
|
513 | - return self::$defaultInstance->getRoot(); |
|
514 | - } |
|
515 | - |
|
516 | - /** |
|
517 | - * clear all mounts and storage backends |
|
518 | - */ |
|
519 | - public static function clearMounts() { |
|
520 | - if (self::$mounts) { |
|
521 | - self::$usersSetup = array(); |
|
522 | - self::$mounts->clear(); |
|
523 | - } |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * mount an \OC\Files\Storage\Storage in our virtual filesystem |
|
528 | - * |
|
529 | - * @param \OC\Files\Storage\Storage|string $class |
|
530 | - * @param array $arguments |
|
531 | - * @param string $mountpoint |
|
532 | - */ |
|
533 | - static public function mount($class, $arguments, $mountpoint) { |
|
534 | - if (!self::$mounts) { |
|
535 | - \OC_Util::setupFS(); |
|
536 | - } |
|
537 | - $mount = new Mount\MountPoint($class, $mountpoint, $arguments, self::getLoader()); |
|
538 | - self::$mounts->addMount($mount); |
|
539 | - } |
|
540 | - |
|
541 | - /** |
|
542 | - * return the path to a local version of the file |
|
543 | - * we need this because we can't know if a file is stored local or not from |
|
544 | - * outside the filestorage and for some purposes a local file is needed |
|
545 | - * |
|
546 | - * @param string $path |
|
547 | - * @return string |
|
548 | - */ |
|
549 | - static public function getLocalFile($path) { |
|
550 | - return self::$defaultInstance->getLocalFile($path); |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * @param string $path |
|
555 | - * @return string |
|
556 | - */ |
|
557 | - static public function getLocalFolder($path) { |
|
558 | - return self::$defaultInstance->getLocalFolder($path); |
|
559 | - } |
|
560 | - |
|
561 | - /** |
|
562 | - * return path to file which reflects one visible in browser |
|
563 | - * |
|
564 | - * @param string $path |
|
565 | - * @return string |
|
566 | - */ |
|
567 | - static public function getLocalPath($path) { |
|
568 | - $datadir = \OC_User::getHome(\OC_User::getUser()) . '/files'; |
|
569 | - $newpath = $path; |
|
570 | - if (strncmp($newpath, $datadir, strlen($datadir)) == 0) { |
|
571 | - $newpath = substr($path, strlen($datadir)); |
|
572 | - } |
|
573 | - return $newpath; |
|
574 | - } |
|
575 | - |
|
576 | - /** |
|
577 | - * check if the requested path is valid |
|
578 | - * |
|
579 | - * @param string $path |
|
580 | - * @return bool |
|
581 | - */ |
|
582 | - static public function isValidPath($path) { |
|
583 | - $path = self::normalizePath($path); |
|
584 | - if (!$path || $path[0] !== '/') { |
|
585 | - $path = '/' . $path; |
|
586 | - } |
|
587 | - if (strpos($path, '/../') !== false || strrchr($path, '/') === '/..') { |
|
588 | - return false; |
|
589 | - } |
|
590 | - return true; |
|
591 | - } |
|
592 | - |
|
593 | - /** |
|
594 | - * checks if a file is blacklisted for storage in the filesystem |
|
595 | - * Listens to write and rename hooks |
|
596 | - * |
|
597 | - * @param array $data from hook |
|
598 | - */ |
|
599 | - static public function isBlacklisted($data) { |
|
600 | - if (isset($data['path'])) { |
|
601 | - $path = $data['path']; |
|
602 | - } else if (isset($data['newpath'])) { |
|
603 | - $path = $data['newpath']; |
|
604 | - } |
|
605 | - if (isset($path)) { |
|
606 | - if (self::isFileBlacklisted($path)) { |
|
607 | - $data['run'] = false; |
|
608 | - } |
|
609 | - } |
|
610 | - } |
|
611 | - |
|
612 | - /** |
|
613 | - * @param string $filename |
|
614 | - * @return bool |
|
615 | - */ |
|
616 | - static public function isFileBlacklisted($filename) { |
|
617 | - $filename = self::normalizePath($filename); |
|
618 | - |
|
619 | - $blacklist = \OC::$server->getConfig()->getSystemValue('blacklisted_files', array('.htaccess')); |
|
620 | - $filename = strtolower(basename($filename)); |
|
621 | - return in_array($filename, $blacklist); |
|
622 | - } |
|
623 | - |
|
624 | - /** |
|
625 | - * check if the directory should be ignored when scanning |
|
626 | - * NOTE: the special directories . and .. would cause never ending recursion |
|
627 | - * |
|
628 | - * @param String $dir |
|
629 | - * @return boolean |
|
630 | - */ |
|
631 | - static public function isIgnoredDir($dir) { |
|
632 | - if ($dir === '.' || $dir === '..') { |
|
633 | - return true; |
|
634 | - } |
|
635 | - return false; |
|
636 | - } |
|
637 | - |
|
638 | - /** |
|
639 | - * following functions are equivalent to their php builtin equivalents for arguments/return values. |
|
640 | - */ |
|
641 | - static public function mkdir($path) { |
|
642 | - return self::$defaultInstance->mkdir($path); |
|
643 | - } |
|
644 | - |
|
645 | - static public function rmdir($path) { |
|
646 | - return self::$defaultInstance->rmdir($path); |
|
647 | - } |
|
648 | - |
|
649 | - static public function is_dir($path) { |
|
650 | - return self::$defaultInstance->is_dir($path); |
|
651 | - } |
|
652 | - |
|
653 | - static public function is_file($path) { |
|
654 | - return self::$defaultInstance->is_file($path); |
|
655 | - } |
|
656 | - |
|
657 | - static public function stat($path) { |
|
658 | - return self::$defaultInstance->stat($path); |
|
659 | - } |
|
660 | - |
|
661 | - static public function filetype($path) { |
|
662 | - return self::$defaultInstance->filetype($path); |
|
663 | - } |
|
664 | - |
|
665 | - static public function filesize($path) { |
|
666 | - return self::$defaultInstance->filesize($path); |
|
667 | - } |
|
668 | - |
|
669 | - static public function readfile($path) { |
|
670 | - return self::$defaultInstance->readfile($path); |
|
671 | - } |
|
672 | - |
|
673 | - static public function isCreatable($path) { |
|
674 | - return self::$defaultInstance->isCreatable($path); |
|
675 | - } |
|
676 | - |
|
677 | - static public function isReadable($path) { |
|
678 | - return self::$defaultInstance->isReadable($path); |
|
679 | - } |
|
680 | - |
|
681 | - static public function isUpdatable($path) { |
|
682 | - return self::$defaultInstance->isUpdatable($path); |
|
683 | - } |
|
684 | - |
|
685 | - static public function isDeletable($path) { |
|
686 | - return self::$defaultInstance->isDeletable($path); |
|
687 | - } |
|
688 | - |
|
689 | - static public function isSharable($path) { |
|
690 | - return self::$defaultInstance->isSharable($path); |
|
691 | - } |
|
692 | - |
|
693 | - static public function file_exists($path) { |
|
694 | - return self::$defaultInstance->file_exists($path); |
|
695 | - } |
|
696 | - |
|
697 | - static public function filemtime($path) { |
|
698 | - return self::$defaultInstance->filemtime($path); |
|
699 | - } |
|
700 | - |
|
701 | - static public function touch($path, $mtime = null) { |
|
702 | - return self::$defaultInstance->touch($path, $mtime); |
|
703 | - } |
|
704 | - |
|
705 | - /** |
|
706 | - * @return string |
|
707 | - */ |
|
708 | - static public function file_get_contents($path) { |
|
709 | - return self::$defaultInstance->file_get_contents($path); |
|
710 | - } |
|
711 | - |
|
712 | - static public function file_put_contents($path, $data) { |
|
713 | - return self::$defaultInstance->file_put_contents($path, $data); |
|
714 | - } |
|
715 | - |
|
716 | - static public function unlink($path) { |
|
717 | - return self::$defaultInstance->unlink($path); |
|
718 | - } |
|
719 | - |
|
720 | - static public function rename($path1, $path2) { |
|
721 | - return self::$defaultInstance->rename($path1, $path2); |
|
722 | - } |
|
723 | - |
|
724 | - static public function copy($path1, $path2) { |
|
725 | - return self::$defaultInstance->copy($path1, $path2); |
|
726 | - } |
|
727 | - |
|
728 | - static public function fopen($path, $mode) { |
|
729 | - return self::$defaultInstance->fopen($path, $mode); |
|
730 | - } |
|
731 | - |
|
732 | - /** |
|
733 | - * @return string |
|
734 | - */ |
|
735 | - static public function toTmpFile($path) { |
|
736 | - return self::$defaultInstance->toTmpFile($path); |
|
737 | - } |
|
738 | - |
|
739 | - static public function fromTmpFile($tmpFile, $path) { |
|
740 | - return self::$defaultInstance->fromTmpFile($tmpFile, $path); |
|
741 | - } |
|
742 | - |
|
743 | - static public function getMimeType($path) { |
|
744 | - return self::$defaultInstance->getMimeType($path); |
|
745 | - } |
|
746 | - |
|
747 | - static public function hash($type, $path, $raw = false) { |
|
748 | - return self::$defaultInstance->hash($type, $path, $raw); |
|
749 | - } |
|
750 | - |
|
751 | - static public function free_space($path = '/') { |
|
752 | - return self::$defaultInstance->free_space($path); |
|
753 | - } |
|
754 | - |
|
755 | - static public function search($query) { |
|
756 | - return self::$defaultInstance->search($query); |
|
757 | - } |
|
758 | - |
|
759 | - /** |
|
760 | - * @param string $query |
|
761 | - */ |
|
762 | - static public function searchByMime($query) { |
|
763 | - return self::$defaultInstance->searchByMime($query); |
|
764 | - } |
|
765 | - |
|
766 | - /** |
|
767 | - * @param string|int $tag name or tag id |
|
768 | - * @param string $userId owner of the tags |
|
769 | - * @return FileInfo[] array or file info |
|
770 | - */ |
|
771 | - static public function searchByTag($tag, $userId) { |
|
772 | - return self::$defaultInstance->searchByTag($tag, $userId); |
|
773 | - } |
|
774 | - |
|
775 | - /** |
|
776 | - * check if a file or folder has been updated since $time |
|
777 | - * |
|
778 | - * @param string $path |
|
779 | - * @param int $time |
|
780 | - * @return bool |
|
781 | - */ |
|
782 | - static public function hasUpdated($path, $time) { |
|
783 | - return self::$defaultInstance->hasUpdated($path, $time); |
|
784 | - } |
|
785 | - |
|
786 | - /** |
|
787 | - * Fix common problems with a file path |
|
788 | - * |
|
789 | - * @param string $path |
|
790 | - * @param bool $stripTrailingSlash whether to strip the trailing slash |
|
791 | - * @param bool $isAbsolutePath whether the given path is absolute |
|
792 | - * @param bool $keepUnicode true to disable unicode normalization |
|
793 | - * @return string |
|
794 | - */ |
|
795 | - public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false, $keepUnicode = false) { |
|
796 | - if (is_null(self::$normalizedPathCache)) { |
|
797 | - self::$normalizedPathCache = new CappedMemoryCache(); |
|
798 | - } |
|
799 | - |
|
800 | - /** |
|
801 | - * FIXME: This is a workaround for existing classes and files which call |
|
802 | - * this function with another type than a valid string. This |
|
803 | - * conversion should get removed as soon as all existing |
|
804 | - * function calls have been fixed. |
|
805 | - */ |
|
806 | - $path = (string)$path; |
|
807 | - |
|
808 | - $cacheKey = json_encode([$path, $stripTrailingSlash, $isAbsolutePath, $keepUnicode]); |
|
809 | - |
|
810 | - if (isset(self::$normalizedPathCache[$cacheKey])) { |
|
811 | - return self::$normalizedPathCache[$cacheKey]; |
|
812 | - } |
|
813 | - |
|
814 | - if ($path == '') { |
|
815 | - return '/'; |
|
816 | - } |
|
817 | - |
|
818 | - //normalize unicode if possible |
|
819 | - if (!$keepUnicode) { |
|
820 | - $path = \OC_Util::normalizeUnicode($path); |
|
821 | - } |
|
822 | - |
|
823 | - //no windows style slashes |
|
824 | - $path = str_replace('\\', '/', $path); |
|
825 | - |
|
826 | - //add leading slash |
|
827 | - if ($path[0] !== '/') { |
|
828 | - $path = '/' . $path; |
|
829 | - } |
|
830 | - |
|
831 | - // remove '/./' |
|
832 | - // ugly, but str_replace() can't replace them all in one go |
|
833 | - // as the replacement itself is part of the search string |
|
834 | - // which will only be found during the next iteration |
|
835 | - while (strpos($path, '/./') !== false) { |
|
836 | - $path = str_replace('/./', '/', $path); |
|
837 | - } |
|
838 | - // remove sequences of slashes |
|
839 | - $path = preg_replace('#/{2,}#', '/', $path); |
|
840 | - |
|
841 | - //remove trailing slash |
|
842 | - if ($stripTrailingSlash and strlen($path) > 1) { |
|
843 | - $path = rtrim($path, '/'); |
|
844 | - } |
|
845 | - |
|
846 | - // remove trailing '/.' |
|
847 | - if (substr($path, -2) == '/.') { |
|
848 | - $path = substr($path, 0, -2); |
|
849 | - } |
|
850 | - |
|
851 | - $normalizedPath = $path; |
|
852 | - self::$normalizedPathCache[$cacheKey] = $normalizedPath; |
|
853 | - |
|
854 | - return $normalizedPath; |
|
855 | - } |
|
856 | - |
|
857 | - /** |
|
858 | - * get the filesystem info |
|
859 | - * |
|
860 | - * @param string $path |
|
861 | - * @param boolean $includeMountPoints whether to add mountpoint sizes, |
|
862 | - * defaults to true |
|
863 | - * @return \OC\Files\FileInfo|bool False if file does not exist |
|
864 | - */ |
|
865 | - public static function getFileInfo($path, $includeMountPoints = true) { |
|
866 | - return self::$defaultInstance->getFileInfo($path, $includeMountPoints); |
|
867 | - } |
|
868 | - |
|
869 | - /** |
|
870 | - * change file metadata |
|
871 | - * |
|
872 | - * @param string $path |
|
873 | - * @param array $data |
|
874 | - * @return int |
|
875 | - * |
|
876 | - * returns the fileid of the updated file |
|
877 | - */ |
|
878 | - public static function putFileInfo($path, $data) { |
|
879 | - return self::$defaultInstance->putFileInfo($path, $data); |
|
880 | - } |
|
881 | - |
|
882 | - /** |
|
883 | - * get the content of a directory |
|
884 | - * |
|
885 | - * @param string $directory path under datadirectory |
|
886 | - * @param string $mimetype_filter limit returned content to this mimetype or mimepart |
|
887 | - * @return \OC\Files\FileInfo[] |
|
888 | - */ |
|
889 | - public static function getDirectoryContent($directory, $mimetype_filter = '') { |
|
890 | - return self::$defaultInstance->getDirectoryContent($directory, $mimetype_filter); |
|
891 | - } |
|
892 | - |
|
893 | - /** |
|
894 | - * Get the path of a file by id |
|
895 | - * |
|
896 | - * Note that the resulting path is not guaranteed to be unique for the id, multiple paths can point to the same file |
|
897 | - * |
|
898 | - * @param int $id |
|
899 | - * @throws NotFoundException |
|
900 | - * @return string |
|
901 | - */ |
|
902 | - public static function getPath($id) { |
|
903 | - return self::$defaultInstance->getPath($id); |
|
904 | - } |
|
905 | - |
|
906 | - /** |
|
907 | - * Get the owner for a file or folder |
|
908 | - * |
|
909 | - * @param string $path |
|
910 | - * @return string |
|
911 | - */ |
|
912 | - public static function getOwner($path) { |
|
913 | - return self::$defaultInstance->getOwner($path); |
|
914 | - } |
|
915 | - |
|
916 | - /** |
|
917 | - * get the ETag for a file or folder |
|
918 | - * |
|
919 | - * @param string $path |
|
920 | - * @return string |
|
921 | - */ |
|
922 | - static public function getETag($path) { |
|
923 | - return self::$defaultInstance->getETag($path); |
|
924 | - } |
|
72 | + /** |
|
73 | + * @var Mount\Manager $mounts |
|
74 | + */ |
|
75 | + private static $mounts; |
|
76 | + |
|
77 | + public static $loaded = false; |
|
78 | + /** |
|
79 | + * @var \OC\Files\View $defaultInstance |
|
80 | + */ |
|
81 | + static private $defaultInstance; |
|
82 | + |
|
83 | + static private $usersSetup = array(); |
|
84 | + |
|
85 | + static private $normalizedPathCache = null; |
|
86 | + |
|
87 | + static private $listeningForProviders = false; |
|
88 | + |
|
89 | + /** |
|
90 | + * classname which used for hooks handling |
|
91 | + * used as signalclass in OC_Hooks::emit() |
|
92 | + */ |
|
93 | + const CLASSNAME = 'OC_Filesystem'; |
|
94 | + |
|
95 | + /** |
|
96 | + * signalname emitted before file renaming |
|
97 | + * |
|
98 | + * @param string $oldpath |
|
99 | + * @param string $newpath |
|
100 | + */ |
|
101 | + const signal_rename = 'rename'; |
|
102 | + |
|
103 | + /** |
|
104 | + * signal emitted after file renaming |
|
105 | + * |
|
106 | + * @param string $oldpath |
|
107 | + * @param string $newpath |
|
108 | + */ |
|
109 | + const signal_post_rename = 'post_rename'; |
|
110 | + |
|
111 | + /** |
|
112 | + * signal emitted before file/dir creation |
|
113 | + * |
|
114 | + * @param string $path |
|
115 | + * @param bool $run changing this flag to false in hook handler will cancel event |
|
116 | + */ |
|
117 | + const signal_create = 'create'; |
|
118 | + |
|
119 | + /** |
|
120 | + * signal emitted after file/dir creation |
|
121 | + * |
|
122 | + * @param string $path |
|
123 | + * @param bool $run changing this flag to false in hook handler will cancel event |
|
124 | + */ |
|
125 | + const signal_post_create = 'post_create'; |
|
126 | + |
|
127 | + /** |
|
128 | + * signal emits before file/dir copy |
|
129 | + * |
|
130 | + * @param string $oldpath |
|
131 | + * @param string $newpath |
|
132 | + * @param bool $run changing this flag to false in hook handler will cancel event |
|
133 | + */ |
|
134 | + const signal_copy = 'copy'; |
|
135 | + |
|
136 | + /** |
|
137 | + * signal emits after file/dir copy |
|
138 | + * |
|
139 | + * @param string $oldpath |
|
140 | + * @param string $newpath |
|
141 | + */ |
|
142 | + const signal_post_copy = 'post_copy'; |
|
143 | + |
|
144 | + /** |
|
145 | + * signal emits before file/dir save |
|
146 | + * |
|
147 | + * @param string $path |
|
148 | + * @param bool $run changing this flag to false in hook handler will cancel event |
|
149 | + */ |
|
150 | + const signal_write = 'write'; |
|
151 | + |
|
152 | + /** |
|
153 | + * signal emits after file/dir save |
|
154 | + * |
|
155 | + * @param string $path |
|
156 | + */ |
|
157 | + const signal_post_write = 'post_write'; |
|
158 | + |
|
159 | + /** |
|
160 | + * signal emitted before file/dir update |
|
161 | + * |
|
162 | + * @param string $path |
|
163 | + * @param bool $run changing this flag to false in hook handler will cancel event |
|
164 | + */ |
|
165 | + const signal_update = 'update'; |
|
166 | + |
|
167 | + /** |
|
168 | + * signal emitted after file/dir update |
|
169 | + * |
|
170 | + * @param string $path |
|
171 | + * @param bool $run changing this flag to false in hook handler will cancel event |
|
172 | + */ |
|
173 | + const signal_post_update = 'post_update'; |
|
174 | + |
|
175 | + /** |
|
176 | + * signal emits when reading file/dir |
|
177 | + * |
|
178 | + * @param string $path |
|
179 | + */ |
|
180 | + const signal_read = 'read'; |
|
181 | + |
|
182 | + /** |
|
183 | + * signal emits when removing file/dir |
|
184 | + * |
|
185 | + * @param string $path |
|
186 | + */ |
|
187 | + const signal_delete = 'delete'; |
|
188 | + |
|
189 | + /** |
|
190 | + * parameters definitions for signals |
|
191 | + */ |
|
192 | + const signal_param_path = 'path'; |
|
193 | + const signal_param_oldpath = 'oldpath'; |
|
194 | + const signal_param_newpath = 'newpath'; |
|
195 | + |
|
196 | + /** |
|
197 | + * run - changing this flag to false in hook handler will cancel event |
|
198 | + */ |
|
199 | + const signal_param_run = 'run'; |
|
200 | + |
|
201 | + const signal_create_mount = 'create_mount'; |
|
202 | + const signal_delete_mount = 'delete_mount'; |
|
203 | + const signal_param_mount_type = 'mounttype'; |
|
204 | + const signal_param_users = 'users'; |
|
205 | + |
|
206 | + /** |
|
207 | + * @var \OC\Files\Storage\StorageFactory $loader |
|
208 | + */ |
|
209 | + private static $loader; |
|
210 | + |
|
211 | + /** @var bool */ |
|
212 | + private static $logWarningWhenAddingStorageWrapper = true; |
|
213 | + |
|
214 | + /** |
|
215 | + * @param bool $shouldLog |
|
216 | + * @return bool previous value |
|
217 | + * @internal |
|
218 | + */ |
|
219 | + public static function logWarningWhenAddingStorageWrapper($shouldLog) { |
|
220 | + $previousValue = self::$logWarningWhenAddingStorageWrapper; |
|
221 | + self::$logWarningWhenAddingStorageWrapper = (bool) $shouldLog; |
|
222 | + return $previousValue; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * @param string $wrapperName |
|
227 | + * @param callable $wrapper |
|
228 | + * @param int $priority |
|
229 | + */ |
|
230 | + public static function addStorageWrapper($wrapperName, $wrapper, $priority = 50) { |
|
231 | + if (self::$logWarningWhenAddingStorageWrapper) { |
|
232 | + \OC::$server->getLogger()->warning("Storage wrapper '{wrapper}' was not registered via the 'OC_Filesystem - preSetup' hook which could cause potential problems.", [ |
|
233 | + 'wrapper' => $wrapperName, |
|
234 | + 'app' => 'filesystem', |
|
235 | + ]); |
|
236 | + } |
|
237 | + |
|
238 | + $mounts = self::getMountManager()->getAll(); |
|
239 | + if (!self::getLoader()->addStorageWrapper($wrapperName, $wrapper, $priority, $mounts)) { |
|
240 | + // do not re-wrap if storage with this name already existed |
|
241 | + return; |
|
242 | + } |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * Returns the storage factory |
|
247 | + * |
|
248 | + * @return \OCP\Files\Storage\IStorageFactory |
|
249 | + */ |
|
250 | + public static function getLoader() { |
|
251 | + if (!self::$loader) { |
|
252 | + self::$loader = new StorageFactory(); |
|
253 | + } |
|
254 | + return self::$loader; |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Returns the mount manager |
|
259 | + * |
|
260 | + * @return \OC\Files\Mount\Manager |
|
261 | + */ |
|
262 | + public static function getMountManager($user = '') { |
|
263 | + if (!self::$mounts) { |
|
264 | + \OC_Util::setupFS($user); |
|
265 | + } |
|
266 | + return self::$mounts; |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * get the mountpoint of the storage object for a path |
|
271 | + * ( note: because a storage is not always mounted inside the fakeroot, the |
|
272 | + * returned mountpoint is relative to the absolute root of the filesystem |
|
273 | + * and doesn't take the chroot into account ) |
|
274 | + * |
|
275 | + * @param string $path |
|
276 | + * @return string |
|
277 | + */ |
|
278 | + static public function getMountPoint($path) { |
|
279 | + if (!self::$mounts) { |
|
280 | + \OC_Util::setupFS(); |
|
281 | + } |
|
282 | + $mount = self::$mounts->find($path); |
|
283 | + if ($mount) { |
|
284 | + return $mount->getMountPoint(); |
|
285 | + } else { |
|
286 | + return ''; |
|
287 | + } |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * get a list of all mount points in a directory |
|
292 | + * |
|
293 | + * @param string $path |
|
294 | + * @return string[] |
|
295 | + */ |
|
296 | + static public function getMountPoints($path) { |
|
297 | + if (!self::$mounts) { |
|
298 | + \OC_Util::setupFS(); |
|
299 | + } |
|
300 | + $result = array(); |
|
301 | + $mounts = self::$mounts->findIn($path); |
|
302 | + foreach ($mounts as $mount) { |
|
303 | + $result[] = $mount->getMountPoint(); |
|
304 | + } |
|
305 | + return $result; |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * get the storage mounted at $mountPoint |
|
310 | + * |
|
311 | + * @param string $mountPoint |
|
312 | + * @return \OC\Files\Storage\Storage |
|
313 | + */ |
|
314 | + public static function getStorage($mountPoint) { |
|
315 | + if (!self::$mounts) { |
|
316 | + \OC_Util::setupFS(); |
|
317 | + } |
|
318 | + $mount = self::$mounts->find($mountPoint); |
|
319 | + return $mount->getStorage(); |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * @param string $id |
|
324 | + * @return Mount\MountPoint[] |
|
325 | + */ |
|
326 | + public static function getMountByStorageId($id) { |
|
327 | + if (!self::$mounts) { |
|
328 | + \OC_Util::setupFS(); |
|
329 | + } |
|
330 | + return self::$mounts->findByStorageId($id); |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * @param int $id |
|
335 | + * @return Mount\MountPoint[] |
|
336 | + */ |
|
337 | + public static function getMountByNumericId($id) { |
|
338 | + if (!self::$mounts) { |
|
339 | + \OC_Util::setupFS(); |
|
340 | + } |
|
341 | + return self::$mounts->findByNumericId($id); |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * resolve a path to a storage and internal path |
|
346 | + * |
|
347 | + * @param string $path |
|
348 | + * @return array an array consisting of the storage and the internal path |
|
349 | + */ |
|
350 | + static public function resolvePath($path) { |
|
351 | + if (!self::$mounts) { |
|
352 | + \OC_Util::setupFS(); |
|
353 | + } |
|
354 | + $mount = self::$mounts->find($path); |
|
355 | + if ($mount) { |
|
356 | + return array($mount->getStorage(), rtrim($mount->getInternalPath($path), '/')); |
|
357 | + } else { |
|
358 | + return array(null, null); |
|
359 | + } |
|
360 | + } |
|
361 | + |
|
362 | + static public function init($user, $root) { |
|
363 | + if (self::$defaultInstance) { |
|
364 | + return false; |
|
365 | + } |
|
366 | + self::getLoader(); |
|
367 | + self::$defaultInstance = new View($root); |
|
368 | + |
|
369 | + if (!self::$mounts) { |
|
370 | + self::$mounts = \OC::$server->getMountManager(); |
|
371 | + } |
|
372 | + |
|
373 | + //load custom mount config |
|
374 | + self::initMountPoints($user); |
|
375 | + |
|
376 | + self::$loaded = true; |
|
377 | + |
|
378 | + return true; |
|
379 | + } |
|
380 | + |
|
381 | + static public function initMountManager() { |
|
382 | + if (!self::$mounts) { |
|
383 | + self::$mounts = \OC::$server->getMountManager(); |
|
384 | + } |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * Initialize system and personal mount points for a user |
|
389 | + * |
|
390 | + * @param string $user |
|
391 | + * @throws \OC\User\NoUserException if the user is not available |
|
392 | + */ |
|
393 | + public static function initMountPoints($user = '') { |
|
394 | + if ($user == '') { |
|
395 | + $user = \OC_User::getUser(); |
|
396 | + } |
|
397 | + if ($user === null || $user === false || $user === '') { |
|
398 | + throw new \OC\User\NoUserException('Attempted to initialize mount points for null user and no user in session'); |
|
399 | + } |
|
400 | + |
|
401 | + if (isset(self::$usersSetup[$user])) { |
|
402 | + return; |
|
403 | + } |
|
404 | + |
|
405 | + self::$usersSetup[$user] = true; |
|
406 | + |
|
407 | + $userManager = \OC::$server->getUserManager(); |
|
408 | + $userObject = $userManager->get($user); |
|
409 | + |
|
410 | + if (is_null($userObject)) { |
|
411 | + \OCP\Util::writeLog('files', ' Backends provided no user object for ' . $user, \OCP\Util::ERROR); |
|
412 | + // reset flag, this will make it possible to rethrow the exception if called again |
|
413 | + unset(self::$usersSetup[$user]); |
|
414 | + throw new \OC\User\NoUserException('Backends provided no user object for ' . $user); |
|
415 | + } |
|
416 | + |
|
417 | + $realUid = $userObject->getUID(); |
|
418 | + // workaround in case of different casings |
|
419 | + if ($user !== $realUid) { |
|
420 | + $stack = json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 50)); |
|
421 | + \OCP\Util::writeLog('files', 'initMountPoints() called with wrong user casing. This could be a bug. Expected: "' . $realUid . '" got "' . $user . '". Stack: ' . $stack, \OCP\Util::WARN); |
|
422 | + $user = $realUid; |
|
423 | + |
|
424 | + // again with the correct casing |
|
425 | + if (isset(self::$usersSetup[$user])) { |
|
426 | + return; |
|
427 | + } |
|
428 | + |
|
429 | + self::$usersSetup[$user] = true; |
|
430 | + } |
|
431 | + |
|
432 | + if (\OC::$server->getLockdownManager()->canAccessFilesystem()) { |
|
433 | + /** @var \OC\Files\Config\MountProviderCollection $mountConfigManager */ |
|
434 | + $mountConfigManager = \OC::$server->getMountProviderCollection(); |
|
435 | + |
|
436 | + // home mounts are handled seperate since we need to ensure this is mounted before we call the other mount providers |
|
437 | + $homeMount = $mountConfigManager->getHomeMountForUser($userObject); |
|
438 | + |
|
439 | + self::getMountManager()->addMount($homeMount); |
|
440 | + |
|
441 | + \OC\Files\Filesystem::getStorage($user); |
|
442 | + |
|
443 | + // Chance to mount for other storages |
|
444 | + if ($userObject) { |
|
445 | + $mounts = $mountConfigManager->addMountForUser($userObject, self::getMountManager()); |
|
446 | + $mounts[] = $homeMount; |
|
447 | + $mountConfigManager->registerMounts($userObject, $mounts); |
|
448 | + } |
|
449 | + |
|
450 | + self::listenForNewMountProviders($mountConfigManager, $userManager); |
|
451 | + } else { |
|
452 | + self::getMountManager()->addMount(new MountPoint( |
|
453 | + new NullStorage([]), |
|
454 | + '/' . $user |
|
455 | + )); |
|
456 | + self::getMountManager()->addMount(new MountPoint( |
|
457 | + new NullStorage([]), |
|
458 | + '/' . $user . '/files' |
|
459 | + )); |
|
460 | + } |
|
461 | + \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', array('user' => $user)); |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Get mounts from mount providers that are registered after setup |
|
466 | + * |
|
467 | + * @param MountProviderCollection $mountConfigManager |
|
468 | + * @param IUserManager $userManager |
|
469 | + */ |
|
470 | + private static function listenForNewMountProviders(MountProviderCollection $mountConfigManager, IUserManager $userManager) { |
|
471 | + if (!self::$listeningForProviders) { |
|
472 | + self::$listeningForProviders = true; |
|
473 | + $mountConfigManager->listen('\OC\Files\Config', 'registerMountProvider', function (IMountProvider $provider) use ($userManager) { |
|
474 | + foreach (Filesystem::$usersSetup as $user => $setup) { |
|
475 | + $userObject = $userManager->get($user); |
|
476 | + if ($userObject) { |
|
477 | + $mounts = $provider->getMountsForUser($userObject, Filesystem::getLoader()); |
|
478 | + array_walk($mounts, array(self::$mounts, 'addMount')); |
|
479 | + } |
|
480 | + } |
|
481 | + }); |
|
482 | + } |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * get the default filesystem view |
|
487 | + * |
|
488 | + * @return View |
|
489 | + */ |
|
490 | + static public function getView() { |
|
491 | + return self::$defaultInstance; |
|
492 | + } |
|
493 | + |
|
494 | + /** |
|
495 | + * tear down the filesystem, removing all storage providers |
|
496 | + */ |
|
497 | + static public function tearDown() { |
|
498 | + self::clearMounts(); |
|
499 | + self::$defaultInstance = null; |
|
500 | + } |
|
501 | + |
|
502 | + /** |
|
503 | + * get the relative path of the root data directory for the current user |
|
504 | + * |
|
505 | + * @return string |
|
506 | + * |
|
507 | + * Returns path like /admin/files |
|
508 | + */ |
|
509 | + static public function getRoot() { |
|
510 | + if (!self::$defaultInstance) { |
|
511 | + return null; |
|
512 | + } |
|
513 | + return self::$defaultInstance->getRoot(); |
|
514 | + } |
|
515 | + |
|
516 | + /** |
|
517 | + * clear all mounts and storage backends |
|
518 | + */ |
|
519 | + public static function clearMounts() { |
|
520 | + if (self::$mounts) { |
|
521 | + self::$usersSetup = array(); |
|
522 | + self::$mounts->clear(); |
|
523 | + } |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * mount an \OC\Files\Storage\Storage in our virtual filesystem |
|
528 | + * |
|
529 | + * @param \OC\Files\Storage\Storage|string $class |
|
530 | + * @param array $arguments |
|
531 | + * @param string $mountpoint |
|
532 | + */ |
|
533 | + static public function mount($class, $arguments, $mountpoint) { |
|
534 | + if (!self::$mounts) { |
|
535 | + \OC_Util::setupFS(); |
|
536 | + } |
|
537 | + $mount = new Mount\MountPoint($class, $mountpoint, $arguments, self::getLoader()); |
|
538 | + self::$mounts->addMount($mount); |
|
539 | + } |
|
540 | + |
|
541 | + /** |
|
542 | + * return the path to a local version of the file |
|
543 | + * we need this because we can't know if a file is stored local or not from |
|
544 | + * outside the filestorage and for some purposes a local file is needed |
|
545 | + * |
|
546 | + * @param string $path |
|
547 | + * @return string |
|
548 | + */ |
|
549 | + static public function getLocalFile($path) { |
|
550 | + return self::$defaultInstance->getLocalFile($path); |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * @param string $path |
|
555 | + * @return string |
|
556 | + */ |
|
557 | + static public function getLocalFolder($path) { |
|
558 | + return self::$defaultInstance->getLocalFolder($path); |
|
559 | + } |
|
560 | + |
|
561 | + /** |
|
562 | + * return path to file which reflects one visible in browser |
|
563 | + * |
|
564 | + * @param string $path |
|
565 | + * @return string |
|
566 | + */ |
|
567 | + static public function getLocalPath($path) { |
|
568 | + $datadir = \OC_User::getHome(\OC_User::getUser()) . '/files'; |
|
569 | + $newpath = $path; |
|
570 | + if (strncmp($newpath, $datadir, strlen($datadir)) == 0) { |
|
571 | + $newpath = substr($path, strlen($datadir)); |
|
572 | + } |
|
573 | + return $newpath; |
|
574 | + } |
|
575 | + |
|
576 | + /** |
|
577 | + * check if the requested path is valid |
|
578 | + * |
|
579 | + * @param string $path |
|
580 | + * @return bool |
|
581 | + */ |
|
582 | + static public function isValidPath($path) { |
|
583 | + $path = self::normalizePath($path); |
|
584 | + if (!$path || $path[0] !== '/') { |
|
585 | + $path = '/' . $path; |
|
586 | + } |
|
587 | + if (strpos($path, '/../') !== false || strrchr($path, '/') === '/..') { |
|
588 | + return false; |
|
589 | + } |
|
590 | + return true; |
|
591 | + } |
|
592 | + |
|
593 | + /** |
|
594 | + * checks if a file is blacklisted for storage in the filesystem |
|
595 | + * Listens to write and rename hooks |
|
596 | + * |
|
597 | + * @param array $data from hook |
|
598 | + */ |
|
599 | + static public function isBlacklisted($data) { |
|
600 | + if (isset($data['path'])) { |
|
601 | + $path = $data['path']; |
|
602 | + } else if (isset($data['newpath'])) { |
|
603 | + $path = $data['newpath']; |
|
604 | + } |
|
605 | + if (isset($path)) { |
|
606 | + if (self::isFileBlacklisted($path)) { |
|
607 | + $data['run'] = false; |
|
608 | + } |
|
609 | + } |
|
610 | + } |
|
611 | + |
|
612 | + /** |
|
613 | + * @param string $filename |
|
614 | + * @return bool |
|
615 | + */ |
|
616 | + static public function isFileBlacklisted($filename) { |
|
617 | + $filename = self::normalizePath($filename); |
|
618 | + |
|
619 | + $blacklist = \OC::$server->getConfig()->getSystemValue('blacklisted_files', array('.htaccess')); |
|
620 | + $filename = strtolower(basename($filename)); |
|
621 | + return in_array($filename, $blacklist); |
|
622 | + } |
|
623 | + |
|
624 | + /** |
|
625 | + * check if the directory should be ignored when scanning |
|
626 | + * NOTE: the special directories . and .. would cause never ending recursion |
|
627 | + * |
|
628 | + * @param String $dir |
|
629 | + * @return boolean |
|
630 | + */ |
|
631 | + static public function isIgnoredDir($dir) { |
|
632 | + if ($dir === '.' || $dir === '..') { |
|
633 | + return true; |
|
634 | + } |
|
635 | + return false; |
|
636 | + } |
|
637 | + |
|
638 | + /** |
|
639 | + * following functions are equivalent to their php builtin equivalents for arguments/return values. |
|
640 | + */ |
|
641 | + static public function mkdir($path) { |
|
642 | + return self::$defaultInstance->mkdir($path); |
|
643 | + } |
|
644 | + |
|
645 | + static public function rmdir($path) { |
|
646 | + return self::$defaultInstance->rmdir($path); |
|
647 | + } |
|
648 | + |
|
649 | + static public function is_dir($path) { |
|
650 | + return self::$defaultInstance->is_dir($path); |
|
651 | + } |
|
652 | + |
|
653 | + static public function is_file($path) { |
|
654 | + return self::$defaultInstance->is_file($path); |
|
655 | + } |
|
656 | + |
|
657 | + static public function stat($path) { |
|
658 | + return self::$defaultInstance->stat($path); |
|
659 | + } |
|
660 | + |
|
661 | + static public function filetype($path) { |
|
662 | + return self::$defaultInstance->filetype($path); |
|
663 | + } |
|
664 | + |
|
665 | + static public function filesize($path) { |
|
666 | + return self::$defaultInstance->filesize($path); |
|
667 | + } |
|
668 | + |
|
669 | + static public function readfile($path) { |
|
670 | + return self::$defaultInstance->readfile($path); |
|
671 | + } |
|
672 | + |
|
673 | + static public function isCreatable($path) { |
|
674 | + return self::$defaultInstance->isCreatable($path); |
|
675 | + } |
|
676 | + |
|
677 | + static public function isReadable($path) { |
|
678 | + return self::$defaultInstance->isReadable($path); |
|
679 | + } |
|
680 | + |
|
681 | + static public function isUpdatable($path) { |
|
682 | + return self::$defaultInstance->isUpdatable($path); |
|
683 | + } |
|
684 | + |
|
685 | + static public function isDeletable($path) { |
|
686 | + return self::$defaultInstance->isDeletable($path); |
|
687 | + } |
|
688 | + |
|
689 | + static public function isSharable($path) { |
|
690 | + return self::$defaultInstance->isSharable($path); |
|
691 | + } |
|
692 | + |
|
693 | + static public function file_exists($path) { |
|
694 | + return self::$defaultInstance->file_exists($path); |
|
695 | + } |
|
696 | + |
|
697 | + static public function filemtime($path) { |
|
698 | + return self::$defaultInstance->filemtime($path); |
|
699 | + } |
|
700 | + |
|
701 | + static public function touch($path, $mtime = null) { |
|
702 | + return self::$defaultInstance->touch($path, $mtime); |
|
703 | + } |
|
704 | + |
|
705 | + /** |
|
706 | + * @return string |
|
707 | + */ |
|
708 | + static public function file_get_contents($path) { |
|
709 | + return self::$defaultInstance->file_get_contents($path); |
|
710 | + } |
|
711 | + |
|
712 | + static public function file_put_contents($path, $data) { |
|
713 | + return self::$defaultInstance->file_put_contents($path, $data); |
|
714 | + } |
|
715 | + |
|
716 | + static public function unlink($path) { |
|
717 | + return self::$defaultInstance->unlink($path); |
|
718 | + } |
|
719 | + |
|
720 | + static public function rename($path1, $path2) { |
|
721 | + return self::$defaultInstance->rename($path1, $path2); |
|
722 | + } |
|
723 | + |
|
724 | + static public function copy($path1, $path2) { |
|
725 | + return self::$defaultInstance->copy($path1, $path2); |
|
726 | + } |
|
727 | + |
|
728 | + static public function fopen($path, $mode) { |
|
729 | + return self::$defaultInstance->fopen($path, $mode); |
|
730 | + } |
|
731 | + |
|
732 | + /** |
|
733 | + * @return string |
|
734 | + */ |
|
735 | + static public function toTmpFile($path) { |
|
736 | + return self::$defaultInstance->toTmpFile($path); |
|
737 | + } |
|
738 | + |
|
739 | + static public function fromTmpFile($tmpFile, $path) { |
|
740 | + return self::$defaultInstance->fromTmpFile($tmpFile, $path); |
|
741 | + } |
|
742 | + |
|
743 | + static public function getMimeType($path) { |
|
744 | + return self::$defaultInstance->getMimeType($path); |
|
745 | + } |
|
746 | + |
|
747 | + static public function hash($type, $path, $raw = false) { |
|
748 | + return self::$defaultInstance->hash($type, $path, $raw); |
|
749 | + } |
|
750 | + |
|
751 | + static public function free_space($path = '/') { |
|
752 | + return self::$defaultInstance->free_space($path); |
|
753 | + } |
|
754 | + |
|
755 | + static public function search($query) { |
|
756 | + return self::$defaultInstance->search($query); |
|
757 | + } |
|
758 | + |
|
759 | + /** |
|
760 | + * @param string $query |
|
761 | + */ |
|
762 | + static public function searchByMime($query) { |
|
763 | + return self::$defaultInstance->searchByMime($query); |
|
764 | + } |
|
765 | + |
|
766 | + /** |
|
767 | + * @param string|int $tag name or tag id |
|
768 | + * @param string $userId owner of the tags |
|
769 | + * @return FileInfo[] array or file info |
|
770 | + */ |
|
771 | + static public function searchByTag($tag, $userId) { |
|
772 | + return self::$defaultInstance->searchByTag($tag, $userId); |
|
773 | + } |
|
774 | + |
|
775 | + /** |
|
776 | + * check if a file or folder has been updated since $time |
|
777 | + * |
|
778 | + * @param string $path |
|
779 | + * @param int $time |
|
780 | + * @return bool |
|
781 | + */ |
|
782 | + static public function hasUpdated($path, $time) { |
|
783 | + return self::$defaultInstance->hasUpdated($path, $time); |
|
784 | + } |
|
785 | + |
|
786 | + /** |
|
787 | + * Fix common problems with a file path |
|
788 | + * |
|
789 | + * @param string $path |
|
790 | + * @param bool $stripTrailingSlash whether to strip the trailing slash |
|
791 | + * @param bool $isAbsolutePath whether the given path is absolute |
|
792 | + * @param bool $keepUnicode true to disable unicode normalization |
|
793 | + * @return string |
|
794 | + */ |
|
795 | + public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false, $keepUnicode = false) { |
|
796 | + if (is_null(self::$normalizedPathCache)) { |
|
797 | + self::$normalizedPathCache = new CappedMemoryCache(); |
|
798 | + } |
|
799 | + |
|
800 | + /** |
|
801 | + * FIXME: This is a workaround for existing classes and files which call |
|
802 | + * this function with another type than a valid string. This |
|
803 | + * conversion should get removed as soon as all existing |
|
804 | + * function calls have been fixed. |
|
805 | + */ |
|
806 | + $path = (string)$path; |
|
807 | + |
|
808 | + $cacheKey = json_encode([$path, $stripTrailingSlash, $isAbsolutePath, $keepUnicode]); |
|
809 | + |
|
810 | + if (isset(self::$normalizedPathCache[$cacheKey])) { |
|
811 | + return self::$normalizedPathCache[$cacheKey]; |
|
812 | + } |
|
813 | + |
|
814 | + if ($path == '') { |
|
815 | + return '/'; |
|
816 | + } |
|
817 | + |
|
818 | + //normalize unicode if possible |
|
819 | + if (!$keepUnicode) { |
|
820 | + $path = \OC_Util::normalizeUnicode($path); |
|
821 | + } |
|
822 | + |
|
823 | + //no windows style slashes |
|
824 | + $path = str_replace('\\', '/', $path); |
|
825 | + |
|
826 | + //add leading slash |
|
827 | + if ($path[0] !== '/') { |
|
828 | + $path = '/' . $path; |
|
829 | + } |
|
830 | + |
|
831 | + // remove '/./' |
|
832 | + // ugly, but str_replace() can't replace them all in one go |
|
833 | + // as the replacement itself is part of the search string |
|
834 | + // which will only be found during the next iteration |
|
835 | + while (strpos($path, '/./') !== false) { |
|
836 | + $path = str_replace('/./', '/', $path); |
|
837 | + } |
|
838 | + // remove sequences of slashes |
|
839 | + $path = preg_replace('#/{2,}#', '/', $path); |
|
840 | + |
|
841 | + //remove trailing slash |
|
842 | + if ($stripTrailingSlash and strlen($path) > 1) { |
|
843 | + $path = rtrim($path, '/'); |
|
844 | + } |
|
845 | + |
|
846 | + // remove trailing '/.' |
|
847 | + if (substr($path, -2) == '/.') { |
|
848 | + $path = substr($path, 0, -2); |
|
849 | + } |
|
850 | + |
|
851 | + $normalizedPath = $path; |
|
852 | + self::$normalizedPathCache[$cacheKey] = $normalizedPath; |
|
853 | + |
|
854 | + return $normalizedPath; |
|
855 | + } |
|
856 | + |
|
857 | + /** |
|
858 | + * get the filesystem info |
|
859 | + * |
|
860 | + * @param string $path |
|
861 | + * @param boolean $includeMountPoints whether to add mountpoint sizes, |
|
862 | + * defaults to true |
|
863 | + * @return \OC\Files\FileInfo|bool False if file does not exist |
|
864 | + */ |
|
865 | + public static function getFileInfo($path, $includeMountPoints = true) { |
|
866 | + return self::$defaultInstance->getFileInfo($path, $includeMountPoints); |
|
867 | + } |
|
868 | + |
|
869 | + /** |
|
870 | + * change file metadata |
|
871 | + * |
|
872 | + * @param string $path |
|
873 | + * @param array $data |
|
874 | + * @return int |
|
875 | + * |
|
876 | + * returns the fileid of the updated file |
|
877 | + */ |
|
878 | + public static function putFileInfo($path, $data) { |
|
879 | + return self::$defaultInstance->putFileInfo($path, $data); |
|
880 | + } |
|
881 | + |
|
882 | + /** |
|
883 | + * get the content of a directory |
|
884 | + * |
|
885 | + * @param string $directory path under datadirectory |
|
886 | + * @param string $mimetype_filter limit returned content to this mimetype or mimepart |
|
887 | + * @return \OC\Files\FileInfo[] |
|
888 | + */ |
|
889 | + public static function getDirectoryContent($directory, $mimetype_filter = '') { |
|
890 | + return self::$defaultInstance->getDirectoryContent($directory, $mimetype_filter); |
|
891 | + } |
|
892 | + |
|
893 | + /** |
|
894 | + * Get the path of a file by id |
|
895 | + * |
|
896 | + * Note that the resulting path is not guaranteed to be unique for the id, multiple paths can point to the same file |
|
897 | + * |
|
898 | + * @param int $id |
|
899 | + * @throws NotFoundException |
|
900 | + * @return string |
|
901 | + */ |
|
902 | + public static function getPath($id) { |
|
903 | + return self::$defaultInstance->getPath($id); |
|
904 | + } |
|
905 | + |
|
906 | + /** |
|
907 | + * Get the owner for a file or folder |
|
908 | + * |
|
909 | + * @param string $path |
|
910 | + * @return string |
|
911 | + */ |
|
912 | + public static function getOwner($path) { |
|
913 | + return self::$defaultInstance->getOwner($path); |
|
914 | + } |
|
915 | + |
|
916 | + /** |
|
917 | + * get the ETag for a file or folder |
|
918 | + * |
|
919 | + * @param string $path |
|
920 | + * @return string |
|
921 | + */ |
|
922 | + static public function getETag($path) { |
|
923 | + return self::$defaultInstance->getETag($path); |
|
924 | + } |
|
925 | 925 | } |