@@ -153,1834 +153,1834 @@ |
||
153 | 153 | * TODO: hookup all manager classes |
154 | 154 | */ |
155 | 155 | class Server extends ServerContainer implements IServerContainer { |
156 | - /** @var string */ |
|
157 | - private $webRoot; |
|
158 | - |
|
159 | - /** |
|
160 | - * @param string $webRoot |
|
161 | - * @param \OC\Config $config |
|
162 | - */ |
|
163 | - public function __construct($webRoot, \OC\Config $config) { |
|
164 | - parent::__construct(); |
|
165 | - $this->webRoot = $webRoot; |
|
166 | - |
|
167 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
168 | - return $c; |
|
169 | - }); |
|
170 | - |
|
171 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
172 | - $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
173 | - |
|
174 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
175 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
176 | - |
|
177 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
178 | - |
|
179 | - |
|
180 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
181 | - return new PreviewManager( |
|
182 | - $c->getConfig(), |
|
183 | - $c->getRootFolder(), |
|
184 | - $c->getAppDataDir('preview'), |
|
185 | - $c->getEventDispatcher(), |
|
186 | - $c->getSession()->get('user_id') |
|
187 | - ); |
|
188 | - }); |
|
189 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
190 | - |
|
191 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
192 | - return new \OC\Preview\Watcher( |
|
193 | - $c->getAppDataDir('preview') |
|
194 | - ); |
|
195 | - }); |
|
196 | - |
|
197 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
198 | - $view = new View(); |
|
199 | - $util = new Encryption\Util( |
|
200 | - $view, |
|
201 | - $c->getUserManager(), |
|
202 | - $c->getGroupManager(), |
|
203 | - $c->getConfig() |
|
204 | - ); |
|
205 | - return new Encryption\Manager( |
|
206 | - $c->getConfig(), |
|
207 | - $c->getLogger(), |
|
208 | - $c->getL10N('core'), |
|
209 | - new View(), |
|
210 | - $util, |
|
211 | - new ArrayCache() |
|
212 | - ); |
|
213 | - }); |
|
214 | - |
|
215 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
216 | - $util = new Encryption\Util( |
|
217 | - new View(), |
|
218 | - $c->getUserManager(), |
|
219 | - $c->getGroupManager(), |
|
220 | - $c->getConfig() |
|
221 | - ); |
|
222 | - return new Encryption\File( |
|
223 | - $util, |
|
224 | - $c->getRootFolder(), |
|
225 | - $c->getShareManager() |
|
226 | - ); |
|
227 | - }); |
|
228 | - |
|
229 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
230 | - $view = new View(); |
|
231 | - $util = new Encryption\Util( |
|
232 | - $view, |
|
233 | - $c->getUserManager(), |
|
234 | - $c->getGroupManager(), |
|
235 | - $c->getConfig() |
|
236 | - ); |
|
237 | - |
|
238 | - return new Encryption\Keys\Storage($view, $util); |
|
239 | - }); |
|
240 | - $this->registerService('TagMapper', function (Server $c) { |
|
241 | - return new TagMapper($c->getDatabaseConnection()); |
|
242 | - }); |
|
243 | - |
|
244 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
245 | - $tagMapper = $c->query('TagMapper'); |
|
246 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
247 | - }); |
|
248 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
249 | - |
|
250 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
251 | - $config = $c->getConfig(); |
|
252 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
253 | - return new $factoryClass($this); |
|
254 | - }); |
|
255 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
256 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
257 | - }); |
|
258 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
259 | - |
|
260 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
261 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
262 | - }); |
|
263 | - $this->registerService('RootFolder', function (Server $c) { |
|
264 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
265 | - $view = new View(); |
|
266 | - $root = new Root( |
|
267 | - $manager, |
|
268 | - $view, |
|
269 | - null, |
|
270 | - $c->getUserMountCache(), |
|
271 | - $this->getLogger(), |
|
272 | - $this->getUserManager() |
|
273 | - ); |
|
274 | - $connector = new HookConnector($root, $view); |
|
275 | - $connector->viewToNode(); |
|
276 | - |
|
277 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
278 | - $previewConnector->connectWatcher(); |
|
279 | - |
|
280 | - return $root; |
|
281 | - }); |
|
282 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
283 | - |
|
284 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
285 | - return new LazyRoot(function () use ($c) { |
|
286 | - return $c->query('RootFolder'); |
|
287 | - }); |
|
288 | - }); |
|
289 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
290 | - |
|
291 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
292 | - $config = $c->getConfig(); |
|
293 | - return new \OC\User\Manager($config); |
|
294 | - }); |
|
295 | - $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
296 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
297 | - |
|
298 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
299 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
300 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
301 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
302 | - }); |
|
303 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
304 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
305 | - }); |
|
306 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
307 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
308 | - }); |
|
309 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
310 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
311 | - }); |
|
312 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
313 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
314 | - }); |
|
315 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
316 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
317 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
318 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
319 | - }); |
|
320 | - return $groupManager; |
|
321 | - }); |
|
322 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
323 | - |
|
324 | - $this->registerService(Store::class, function (Server $c) { |
|
325 | - $session = $c->getSession(); |
|
326 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
327 | - $tokenProvider = $c->query(IProvider::class); |
|
328 | - } else { |
|
329 | - $tokenProvider = null; |
|
330 | - } |
|
331 | - $logger = $c->getLogger(); |
|
332 | - return new Store($session, $logger, $tokenProvider); |
|
333 | - }); |
|
334 | - $this->registerAlias(IStore::class, Store::class); |
|
335 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
336 | - $dbConnection = $c->getDatabaseConnection(); |
|
337 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
338 | - }); |
|
339 | - $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
|
340 | - $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
|
341 | - $crypto = $c->getCrypto(); |
|
342 | - $config = $c->getConfig(); |
|
343 | - $logger = $c->getLogger(); |
|
344 | - $timeFactory = new TimeFactory(); |
|
345 | - return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
346 | - }); |
|
347 | - $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
|
348 | - |
|
349 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
350 | - $manager = $c->getUserManager(); |
|
351 | - $session = new \OC\Session\Memory(''); |
|
352 | - $timeFactory = new TimeFactory(); |
|
353 | - // Token providers might require a working database. This code |
|
354 | - // might however be called when ownCloud is not yet setup. |
|
355 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
356 | - $defaultTokenProvider = $c->query(IProvider::class); |
|
357 | - } else { |
|
358 | - $defaultTokenProvider = null; |
|
359 | - } |
|
360 | - |
|
361 | - $dispatcher = $c->getEventDispatcher(); |
|
362 | - |
|
363 | - $userSession = new \OC\User\Session( |
|
364 | - $manager, |
|
365 | - $session, |
|
366 | - $timeFactory, |
|
367 | - $defaultTokenProvider, |
|
368 | - $c->getConfig(), |
|
369 | - $c->getSecureRandom(), |
|
370 | - $c->getLockdownManager(), |
|
371 | - $c->getLogger() |
|
372 | - ); |
|
373 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
374 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
375 | - }); |
|
376 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
377 | - /** @var $user \OC\User\User */ |
|
378 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
379 | - }); |
|
380 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
381 | - /** @var $user \OC\User\User */ |
|
382 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
383 | - $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
384 | - }); |
|
385 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
386 | - /** @var $user \OC\User\User */ |
|
387 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
388 | - }); |
|
389 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
390 | - /** @var $user \OC\User\User */ |
|
391 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
392 | - }); |
|
393 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
394 | - /** @var $user \OC\User\User */ |
|
395 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
396 | - }); |
|
397 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
398 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
399 | - }); |
|
400 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
401 | - /** @var $user \OC\User\User */ |
|
402 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
403 | - }); |
|
404 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
405 | - /** @var $user \OC\User\User */ |
|
406 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
407 | - }); |
|
408 | - $userSession->listen('\OC\User', 'logout', function () { |
|
409 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
410 | - }); |
|
411 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
412 | - /** @var $user \OC\User\User */ |
|
413 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
414 | - $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
415 | - }); |
|
416 | - return $userSession; |
|
417 | - }); |
|
418 | - $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
419 | - |
|
420 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
421 | - return new \OC\Authentication\TwoFactorAuth\Manager( |
|
422 | - $c->getAppManager(), |
|
423 | - $c->getSession(), |
|
424 | - $c->getConfig(), |
|
425 | - $c->getActivityManager(), |
|
426 | - $c->getLogger(), |
|
427 | - $c->query(IProvider::class), |
|
428 | - $c->query(ITimeFactory::class), |
|
429 | - $c->query(EventDispatcherInterface::class) |
|
430 | - ); |
|
431 | - }); |
|
432 | - |
|
433 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
434 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
435 | - |
|
436 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
437 | - return new \OC\AllConfig( |
|
438 | - $c->getSystemConfig() |
|
439 | - ); |
|
440 | - }); |
|
441 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
442 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
443 | - |
|
444 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
445 | - return new \OC\SystemConfig($config); |
|
446 | - }); |
|
447 | - |
|
448 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
449 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
450 | - }); |
|
451 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
452 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
453 | - |
|
454 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
455 | - return new \OC\L10N\Factory( |
|
456 | - $c->getConfig(), |
|
457 | - $c->getRequest(), |
|
458 | - $c->getUserSession(), |
|
459 | - \OC::$SERVERROOT |
|
460 | - ); |
|
461 | - }); |
|
462 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
463 | - |
|
464 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
465 | - $config = $c->getConfig(); |
|
466 | - $cacheFactory = $c->getMemCacheFactory(); |
|
467 | - $request = $c->getRequest(); |
|
468 | - return new \OC\URLGenerator( |
|
469 | - $config, |
|
470 | - $cacheFactory, |
|
471 | - $request |
|
472 | - ); |
|
473 | - }); |
|
474 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
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); |
|
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 | - $factory = new LogFactory($c); |
|
552 | - $logger = $factory->get($logType); |
|
553 | - $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
554 | - |
|
555 | - return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
556 | - }); |
|
557 | - $this->registerAlias('Logger', \OCP\ILogger::class); |
|
558 | - |
|
559 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
560 | - return new LogFactory($c); |
|
561 | - }); |
|
562 | - $this->registerAlias('LogFactory', ILogFactory::class); |
|
563 | - |
|
564 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
565 | - $config = $c->getConfig(); |
|
566 | - return new \OC\BackgroundJob\JobList( |
|
567 | - $c->getDatabaseConnection(), |
|
568 | - $config, |
|
569 | - new TimeFactory() |
|
570 | - ); |
|
571 | - }); |
|
572 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
573 | - |
|
574 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
575 | - $cacheFactory = $c->getMemCacheFactory(); |
|
576 | - $logger = $c->getLogger(); |
|
577 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
578 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
579 | - } else { |
|
580 | - $router = new \OC\Route\Router($logger); |
|
581 | - } |
|
582 | - return $router; |
|
583 | - }); |
|
584 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
585 | - |
|
586 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
587 | - return new Search(); |
|
588 | - }); |
|
589 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
590 | - |
|
591 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
592 | - return new \OC\Security\RateLimiting\Limiter( |
|
593 | - $this->getUserSession(), |
|
594 | - $this->getRequest(), |
|
595 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
596 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
597 | - ); |
|
598 | - }); |
|
599 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
600 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
601 | - $this->getMemCacheFactory(), |
|
602 | - new \OC\AppFramework\Utility\TimeFactory() |
|
603 | - ); |
|
604 | - }); |
|
605 | - |
|
606 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
607 | - return new SecureRandom(); |
|
608 | - }); |
|
609 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
610 | - |
|
611 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
612 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
613 | - }); |
|
614 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
615 | - |
|
616 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
617 | - return new Hasher($c->getConfig()); |
|
618 | - }); |
|
619 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
620 | - |
|
621 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
622 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
623 | - }); |
|
624 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
625 | - |
|
626 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
627 | - $systemConfig = $c->getSystemConfig(); |
|
628 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
629 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
630 | - if (!$factory->isValidType($type)) { |
|
631 | - throw new \OC\DatabaseException('Invalid database type'); |
|
632 | - } |
|
633 | - $connectionParams = $factory->createConnectionParams(); |
|
634 | - $connection = $factory->getConnection($type, $connectionParams); |
|
635 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
636 | - return $connection; |
|
637 | - }); |
|
638 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
639 | - |
|
640 | - |
|
641 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
642 | - $user = \OC_User::getUser(); |
|
643 | - $uid = $user ? $user : null; |
|
644 | - return new ClientService( |
|
645 | - $c->getConfig(), |
|
646 | - new \OC\Security\CertificateManager( |
|
647 | - $uid, |
|
648 | - new View(), |
|
649 | - $c->getConfig(), |
|
650 | - $c->getLogger(), |
|
651 | - $c->getSecureRandom() |
|
652 | - ) |
|
653 | - ); |
|
654 | - }); |
|
655 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
656 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
657 | - $eventLogger = new EventLogger(); |
|
658 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
659 | - // In debug mode, module is being activated by default |
|
660 | - $eventLogger->activate(); |
|
661 | - } |
|
662 | - return $eventLogger; |
|
663 | - }); |
|
664 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
665 | - |
|
666 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
667 | - $queryLogger = new QueryLogger(); |
|
668 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
669 | - // In debug mode, module is being activated by default |
|
670 | - $queryLogger->activate(); |
|
671 | - } |
|
672 | - return $queryLogger; |
|
673 | - }); |
|
674 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
675 | - |
|
676 | - $this->registerService(TempManager::class, function (Server $c) { |
|
677 | - return new TempManager( |
|
678 | - $c->getLogger(), |
|
679 | - $c->getConfig() |
|
680 | - ); |
|
681 | - }); |
|
682 | - $this->registerAlias('TempManager', TempManager::class); |
|
683 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
684 | - |
|
685 | - $this->registerService(AppManager::class, function (Server $c) { |
|
686 | - return new \OC\App\AppManager( |
|
687 | - $c->getUserSession(), |
|
688 | - $c->query(\OC\AppConfig::class), |
|
689 | - $c->getGroupManager(), |
|
690 | - $c->getMemCacheFactory(), |
|
691 | - $c->getEventDispatcher() |
|
692 | - ); |
|
693 | - }); |
|
694 | - $this->registerAlias('AppManager', AppManager::class); |
|
695 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
696 | - |
|
697 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
698 | - return new DateTimeZone( |
|
699 | - $c->getConfig(), |
|
700 | - $c->getSession() |
|
701 | - ); |
|
702 | - }); |
|
703 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
704 | - |
|
705 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
706 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
707 | - |
|
708 | - return new DateTimeFormatter( |
|
709 | - $c->getDateTimeZone()->getTimeZone(), |
|
710 | - $c->getL10N('lib', $language) |
|
711 | - ); |
|
712 | - }); |
|
713 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
714 | - |
|
715 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
716 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
717 | - $listener = new UserMountCacheListener($mountCache); |
|
718 | - $listener->listen($c->getUserManager()); |
|
719 | - return $mountCache; |
|
720 | - }); |
|
721 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
722 | - |
|
723 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
724 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
725 | - $mountCache = $c->query('UserMountCache'); |
|
726 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
727 | - |
|
728 | - // builtin providers |
|
729 | - |
|
730 | - $config = $c->getConfig(); |
|
731 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
732 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
733 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
734 | - |
|
735 | - return $manager; |
|
736 | - }); |
|
737 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
738 | - |
|
739 | - $this->registerService('IniWrapper', function ($c) { |
|
740 | - return new IniGetWrapper(); |
|
741 | - }); |
|
742 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
743 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
744 | - if ($busClass) { |
|
745 | - list($app, $class) = explode('::', $busClass, 2); |
|
746 | - if ($c->getAppManager()->isInstalled($app)) { |
|
747 | - \OC_App::loadApp($app); |
|
748 | - return $c->query($class); |
|
749 | - } else { |
|
750 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
751 | - } |
|
752 | - } else { |
|
753 | - $jobList = $c->getJobList(); |
|
754 | - return new CronBus($jobList); |
|
755 | - } |
|
756 | - }); |
|
757 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
758 | - return new TrustedDomainHelper($this->getConfig()); |
|
759 | - }); |
|
760 | - $this->registerService('Throttler', function (Server $c) { |
|
761 | - return new Throttler( |
|
762 | - $c->getDatabaseConnection(), |
|
763 | - new TimeFactory(), |
|
764 | - $c->getLogger(), |
|
765 | - $c->getConfig() |
|
766 | - ); |
|
767 | - }); |
|
768 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
769 | - // IConfig and IAppManager requires a working database. This code |
|
770 | - // might however be called when ownCloud is not yet setup. |
|
771 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
772 | - $config = $c->getConfig(); |
|
773 | - $appManager = $c->getAppManager(); |
|
774 | - } else { |
|
775 | - $config = null; |
|
776 | - $appManager = null; |
|
777 | - } |
|
778 | - |
|
779 | - return new Checker( |
|
780 | - new EnvironmentHelper(), |
|
781 | - new FileAccessHelper(), |
|
782 | - new AppLocator(), |
|
783 | - $config, |
|
784 | - $c->getMemCacheFactory(), |
|
785 | - $appManager, |
|
786 | - $c->getTempManager() |
|
787 | - ); |
|
788 | - }); |
|
789 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
790 | - if (isset($this['urlParams'])) { |
|
791 | - $urlParams = $this['urlParams']; |
|
792 | - } else { |
|
793 | - $urlParams = []; |
|
794 | - } |
|
795 | - |
|
796 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
797 | - && in_array('fakeinput', stream_get_wrappers()) |
|
798 | - ) { |
|
799 | - $stream = 'fakeinput://data'; |
|
800 | - } else { |
|
801 | - $stream = 'php://input'; |
|
802 | - } |
|
803 | - |
|
804 | - return new Request( |
|
805 | - [ |
|
806 | - 'get' => $_GET, |
|
807 | - 'post' => $_POST, |
|
808 | - 'files' => $_FILES, |
|
809 | - 'server' => $_SERVER, |
|
810 | - 'env' => $_ENV, |
|
811 | - 'cookies' => $_COOKIE, |
|
812 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
813 | - ? $_SERVER['REQUEST_METHOD'] |
|
814 | - : '', |
|
815 | - 'urlParams' => $urlParams, |
|
816 | - ], |
|
817 | - $this->getSecureRandom(), |
|
818 | - $this->getConfig(), |
|
819 | - $this->getCsrfTokenManager(), |
|
820 | - $stream |
|
821 | - ); |
|
822 | - }); |
|
823 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
824 | - |
|
825 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
826 | - return new Mailer( |
|
827 | - $c->getConfig(), |
|
828 | - $c->getLogger(), |
|
829 | - $c->query(Defaults::class), |
|
830 | - $c->getURLGenerator(), |
|
831 | - $c->getL10N('lib') |
|
832 | - ); |
|
833 | - }); |
|
834 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
835 | - |
|
836 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
837 | - $config = $c->getConfig(); |
|
838 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
839 | - if (is_null($factoryClass)) { |
|
840 | - throw new \Exception('ldapProviderFactory not set'); |
|
841 | - } |
|
842 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
843 | - $factory = new $factoryClass($this); |
|
844 | - return $factory->getLDAPProvider(); |
|
845 | - }); |
|
846 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
847 | - $ini = $c->getIniWrapper(); |
|
848 | - $config = $c->getConfig(); |
|
849 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
850 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
851 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
852 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
853 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
854 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
855 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
856 | - } |
|
857 | - return new DBLockingProvider( |
|
858 | - $c->getDatabaseConnection(), |
|
859 | - $c->getLogger(), |
|
860 | - new TimeFactory(), |
|
861 | - $ttl, |
|
862 | - !\OC::$CLI |
|
863 | - ); |
|
864 | - } |
|
865 | - return new NoopLockingProvider(); |
|
866 | - }); |
|
867 | - $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
868 | - |
|
869 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
870 | - return new \OC\Files\Mount\Manager(); |
|
871 | - }); |
|
872 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
873 | - |
|
874 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
875 | - return new \OC\Files\Type\Detection( |
|
876 | - $c->getURLGenerator(), |
|
877 | - \OC::$configDir, |
|
878 | - \OC::$SERVERROOT . '/resources/config/' |
|
879 | - ); |
|
880 | - }); |
|
881 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
882 | - |
|
883 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
884 | - return new \OC\Files\Type\Loader( |
|
885 | - $c->getDatabaseConnection() |
|
886 | - ); |
|
887 | - }); |
|
888 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
889 | - $this->registerService(BundleFetcher::class, function () { |
|
890 | - return new BundleFetcher($this->getL10N('lib')); |
|
891 | - }); |
|
892 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
893 | - return new Manager( |
|
894 | - $c->query(IValidator::class) |
|
895 | - ); |
|
896 | - }); |
|
897 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
898 | - |
|
899 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
900 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
901 | - $manager->registerCapability(function () use ($c) { |
|
902 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
903 | - }); |
|
904 | - $manager->registerCapability(function () use ($c) { |
|
905 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
906 | - }); |
|
907 | - return $manager; |
|
908 | - }); |
|
909 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
910 | - |
|
911 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
912 | - $config = $c->getConfig(); |
|
913 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
914 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
915 | - $factory = new $factoryClass($this); |
|
916 | - $manager = $factory->getManager(); |
|
917 | - |
|
918 | - $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
919 | - $manager = $c->getUserManager(); |
|
920 | - $user = $manager->get($id); |
|
921 | - if(is_null($user)) { |
|
922 | - $l = $c->getL10N('core'); |
|
923 | - $displayName = $l->t('Unknown user'); |
|
924 | - } else { |
|
925 | - $displayName = $user->getDisplayName(); |
|
926 | - } |
|
927 | - return $displayName; |
|
928 | - }); |
|
929 | - |
|
930 | - return $manager; |
|
931 | - }); |
|
932 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
933 | - |
|
934 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
935 | - /* |
|
156 | + /** @var string */ |
|
157 | + private $webRoot; |
|
158 | + |
|
159 | + /** |
|
160 | + * @param string $webRoot |
|
161 | + * @param \OC\Config $config |
|
162 | + */ |
|
163 | + public function __construct($webRoot, \OC\Config $config) { |
|
164 | + parent::__construct(); |
|
165 | + $this->webRoot = $webRoot; |
|
166 | + |
|
167 | + $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
168 | + return $c; |
|
169 | + }); |
|
170 | + |
|
171 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
172 | + $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
173 | + |
|
174 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
175 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
176 | + |
|
177 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
178 | + |
|
179 | + |
|
180 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
181 | + return new PreviewManager( |
|
182 | + $c->getConfig(), |
|
183 | + $c->getRootFolder(), |
|
184 | + $c->getAppDataDir('preview'), |
|
185 | + $c->getEventDispatcher(), |
|
186 | + $c->getSession()->get('user_id') |
|
187 | + ); |
|
188 | + }); |
|
189 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
190 | + |
|
191 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
192 | + return new \OC\Preview\Watcher( |
|
193 | + $c->getAppDataDir('preview') |
|
194 | + ); |
|
195 | + }); |
|
196 | + |
|
197 | + $this->registerService('EncryptionManager', function (Server $c) { |
|
198 | + $view = new View(); |
|
199 | + $util = new Encryption\Util( |
|
200 | + $view, |
|
201 | + $c->getUserManager(), |
|
202 | + $c->getGroupManager(), |
|
203 | + $c->getConfig() |
|
204 | + ); |
|
205 | + return new Encryption\Manager( |
|
206 | + $c->getConfig(), |
|
207 | + $c->getLogger(), |
|
208 | + $c->getL10N('core'), |
|
209 | + new View(), |
|
210 | + $util, |
|
211 | + new ArrayCache() |
|
212 | + ); |
|
213 | + }); |
|
214 | + |
|
215 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
216 | + $util = new Encryption\Util( |
|
217 | + new View(), |
|
218 | + $c->getUserManager(), |
|
219 | + $c->getGroupManager(), |
|
220 | + $c->getConfig() |
|
221 | + ); |
|
222 | + return new Encryption\File( |
|
223 | + $util, |
|
224 | + $c->getRootFolder(), |
|
225 | + $c->getShareManager() |
|
226 | + ); |
|
227 | + }); |
|
228 | + |
|
229 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
230 | + $view = new View(); |
|
231 | + $util = new Encryption\Util( |
|
232 | + $view, |
|
233 | + $c->getUserManager(), |
|
234 | + $c->getGroupManager(), |
|
235 | + $c->getConfig() |
|
236 | + ); |
|
237 | + |
|
238 | + return new Encryption\Keys\Storage($view, $util); |
|
239 | + }); |
|
240 | + $this->registerService('TagMapper', function (Server $c) { |
|
241 | + return new TagMapper($c->getDatabaseConnection()); |
|
242 | + }); |
|
243 | + |
|
244 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
245 | + $tagMapper = $c->query('TagMapper'); |
|
246 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
247 | + }); |
|
248 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
249 | + |
|
250 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
251 | + $config = $c->getConfig(); |
|
252 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
253 | + return new $factoryClass($this); |
|
254 | + }); |
|
255 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
256 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
257 | + }); |
|
258 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
259 | + |
|
260 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
261 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
262 | + }); |
|
263 | + $this->registerService('RootFolder', function (Server $c) { |
|
264 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
265 | + $view = new View(); |
|
266 | + $root = new Root( |
|
267 | + $manager, |
|
268 | + $view, |
|
269 | + null, |
|
270 | + $c->getUserMountCache(), |
|
271 | + $this->getLogger(), |
|
272 | + $this->getUserManager() |
|
273 | + ); |
|
274 | + $connector = new HookConnector($root, $view); |
|
275 | + $connector->viewToNode(); |
|
276 | + |
|
277 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
278 | + $previewConnector->connectWatcher(); |
|
279 | + |
|
280 | + return $root; |
|
281 | + }); |
|
282 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
283 | + |
|
284 | + $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
285 | + return new LazyRoot(function () use ($c) { |
|
286 | + return $c->query('RootFolder'); |
|
287 | + }); |
|
288 | + }); |
|
289 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
290 | + |
|
291 | + $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
292 | + $config = $c->getConfig(); |
|
293 | + return new \OC\User\Manager($config); |
|
294 | + }); |
|
295 | + $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
296 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
297 | + |
|
298 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
299 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
300 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
301 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
302 | + }); |
|
303 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
304 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
305 | + }); |
|
306 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
307 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
308 | + }); |
|
309 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
310 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
311 | + }); |
|
312 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
313 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
314 | + }); |
|
315 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
316 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
317 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
318 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
319 | + }); |
|
320 | + return $groupManager; |
|
321 | + }); |
|
322 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
323 | + |
|
324 | + $this->registerService(Store::class, function (Server $c) { |
|
325 | + $session = $c->getSession(); |
|
326 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
327 | + $tokenProvider = $c->query(IProvider::class); |
|
328 | + } else { |
|
329 | + $tokenProvider = null; |
|
330 | + } |
|
331 | + $logger = $c->getLogger(); |
|
332 | + return new Store($session, $logger, $tokenProvider); |
|
333 | + }); |
|
334 | + $this->registerAlias(IStore::class, Store::class); |
|
335 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
336 | + $dbConnection = $c->getDatabaseConnection(); |
|
337 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
338 | + }); |
|
339 | + $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
|
340 | + $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
|
341 | + $crypto = $c->getCrypto(); |
|
342 | + $config = $c->getConfig(); |
|
343 | + $logger = $c->getLogger(); |
|
344 | + $timeFactory = new TimeFactory(); |
|
345 | + return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
346 | + }); |
|
347 | + $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
|
348 | + |
|
349 | + $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
350 | + $manager = $c->getUserManager(); |
|
351 | + $session = new \OC\Session\Memory(''); |
|
352 | + $timeFactory = new TimeFactory(); |
|
353 | + // Token providers might require a working database. This code |
|
354 | + // might however be called when ownCloud is not yet setup. |
|
355 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
356 | + $defaultTokenProvider = $c->query(IProvider::class); |
|
357 | + } else { |
|
358 | + $defaultTokenProvider = null; |
|
359 | + } |
|
360 | + |
|
361 | + $dispatcher = $c->getEventDispatcher(); |
|
362 | + |
|
363 | + $userSession = new \OC\User\Session( |
|
364 | + $manager, |
|
365 | + $session, |
|
366 | + $timeFactory, |
|
367 | + $defaultTokenProvider, |
|
368 | + $c->getConfig(), |
|
369 | + $c->getSecureRandom(), |
|
370 | + $c->getLockdownManager(), |
|
371 | + $c->getLogger() |
|
372 | + ); |
|
373 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
374 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
375 | + }); |
|
376 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
377 | + /** @var $user \OC\User\User */ |
|
378 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
379 | + }); |
|
380 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
381 | + /** @var $user \OC\User\User */ |
|
382 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
383 | + $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
384 | + }); |
|
385 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
386 | + /** @var $user \OC\User\User */ |
|
387 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
388 | + }); |
|
389 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
390 | + /** @var $user \OC\User\User */ |
|
391 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
392 | + }); |
|
393 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
394 | + /** @var $user \OC\User\User */ |
|
395 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
396 | + }); |
|
397 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
398 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
399 | + }); |
|
400 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
401 | + /** @var $user \OC\User\User */ |
|
402 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
403 | + }); |
|
404 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
405 | + /** @var $user \OC\User\User */ |
|
406 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
407 | + }); |
|
408 | + $userSession->listen('\OC\User', 'logout', function () { |
|
409 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
410 | + }); |
|
411 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
412 | + /** @var $user \OC\User\User */ |
|
413 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
414 | + $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
415 | + }); |
|
416 | + return $userSession; |
|
417 | + }); |
|
418 | + $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
419 | + |
|
420 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
421 | + return new \OC\Authentication\TwoFactorAuth\Manager( |
|
422 | + $c->getAppManager(), |
|
423 | + $c->getSession(), |
|
424 | + $c->getConfig(), |
|
425 | + $c->getActivityManager(), |
|
426 | + $c->getLogger(), |
|
427 | + $c->query(IProvider::class), |
|
428 | + $c->query(ITimeFactory::class), |
|
429 | + $c->query(EventDispatcherInterface::class) |
|
430 | + ); |
|
431 | + }); |
|
432 | + |
|
433 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
434 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
435 | + |
|
436 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
437 | + return new \OC\AllConfig( |
|
438 | + $c->getSystemConfig() |
|
439 | + ); |
|
440 | + }); |
|
441 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
442 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
443 | + |
|
444 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
445 | + return new \OC\SystemConfig($config); |
|
446 | + }); |
|
447 | + |
|
448 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
449 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
450 | + }); |
|
451 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
452 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
453 | + |
|
454 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
455 | + return new \OC\L10N\Factory( |
|
456 | + $c->getConfig(), |
|
457 | + $c->getRequest(), |
|
458 | + $c->getUserSession(), |
|
459 | + \OC::$SERVERROOT |
|
460 | + ); |
|
461 | + }); |
|
462 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
463 | + |
|
464 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
465 | + $config = $c->getConfig(); |
|
466 | + $cacheFactory = $c->getMemCacheFactory(); |
|
467 | + $request = $c->getRequest(); |
|
468 | + return new \OC\URLGenerator( |
|
469 | + $config, |
|
470 | + $cacheFactory, |
|
471 | + $request |
|
472 | + ); |
|
473 | + }); |
|
474 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
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); |
|
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 | + $factory = new LogFactory($c); |
|
552 | + $logger = $factory->get($logType); |
|
553 | + $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
554 | + |
|
555 | + return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
556 | + }); |
|
557 | + $this->registerAlias('Logger', \OCP\ILogger::class); |
|
558 | + |
|
559 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
560 | + return new LogFactory($c); |
|
561 | + }); |
|
562 | + $this->registerAlias('LogFactory', ILogFactory::class); |
|
563 | + |
|
564 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
565 | + $config = $c->getConfig(); |
|
566 | + return new \OC\BackgroundJob\JobList( |
|
567 | + $c->getDatabaseConnection(), |
|
568 | + $config, |
|
569 | + new TimeFactory() |
|
570 | + ); |
|
571 | + }); |
|
572 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
573 | + |
|
574 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
575 | + $cacheFactory = $c->getMemCacheFactory(); |
|
576 | + $logger = $c->getLogger(); |
|
577 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
578 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
579 | + } else { |
|
580 | + $router = new \OC\Route\Router($logger); |
|
581 | + } |
|
582 | + return $router; |
|
583 | + }); |
|
584 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
585 | + |
|
586 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
587 | + return new Search(); |
|
588 | + }); |
|
589 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
590 | + |
|
591 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
592 | + return new \OC\Security\RateLimiting\Limiter( |
|
593 | + $this->getUserSession(), |
|
594 | + $this->getRequest(), |
|
595 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
596 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
597 | + ); |
|
598 | + }); |
|
599 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
600 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
601 | + $this->getMemCacheFactory(), |
|
602 | + new \OC\AppFramework\Utility\TimeFactory() |
|
603 | + ); |
|
604 | + }); |
|
605 | + |
|
606 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
607 | + return new SecureRandom(); |
|
608 | + }); |
|
609 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
610 | + |
|
611 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
612 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
613 | + }); |
|
614 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
615 | + |
|
616 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
617 | + return new Hasher($c->getConfig()); |
|
618 | + }); |
|
619 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
620 | + |
|
621 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
622 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
623 | + }); |
|
624 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
625 | + |
|
626 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
627 | + $systemConfig = $c->getSystemConfig(); |
|
628 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
629 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
630 | + if (!$factory->isValidType($type)) { |
|
631 | + throw new \OC\DatabaseException('Invalid database type'); |
|
632 | + } |
|
633 | + $connectionParams = $factory->createConnectionParams(); |
|
634 | + $connection = $factory->getConnection($type, $connectionParams); |
|
635 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
636 | + return $connection; |
|
637 | + }); |
|
638 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
639 | + |
|
640 | + |
|
641 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
642 | + $user = \OC_User::getUser(); |
|
643 | + $uid = $user ? $user : null; |
|
644 | + return new ClientService( |
|
645 | + $c->getConfig(), |
|
646 | + new \OC\Security\CertificateManager( |
|
647 | + $uid, |
|
648 | + new View(), |
|
649 | + $c->getConfig(), |
|
650 | + $c->getLogger(), |
|
651 | + $c->getSecureRandom() |
|
652 | + ) |
|
653 | + ); |
|
654 | + }); |
|
655 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
656 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
657 | + $eventLogger = new EventLogger(); |
|
658 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
659 | + // In debug mode, module is being activated by default |
|
660 | + $eventLogger->activate(); |
|
661 | + } |
|
662 | + return $eventLogger; |
|
663 | + }); |
|
664 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
665 | + |
|
666 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
667 | + $queryLogger = new QueryLogger(); |
|
668 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
669 | + // In debug mode, module is being activated by default |
|
670 | + $queryLogger->activate(); |
|
671 | + } |
|
672 | + return $queryLogger; |
|
673 | + }); |
|
674 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
675 | + |
|
676 | + $this->registerService(TempManager::class, function (Server $c) { |
|
677 | + return new TempManager( |
|
678 | + $c->getLogger(), |
|
679 | + $c->getConfig() |
|
680 | + ); |
|
681 | + }); |
|
682 | + $this->registerAlias('TempManager', TempManager::class); |
|
683 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
684 | + |
|
685 | + $this->registerService(AppManager::class, function (Server $c) { |
|
686 | + return new \OC\App\AppManager( |
|
687 | + $c->getUserSession(), |
|
688 | + $c->query(\OC\AppConfig::class), |
|
689 | + $c->getGroupManager(), |
|
690 | + $c->getMemCacheFactory(), |
|
691 | + $c->getEventDispatcher() |
|
692 | + ); |
|
693 | + }); |
|
694 | + $this->registerAlias('AppManager', AppManager::class); |
|
695 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
696 | + |
|
697 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
698 | + return new DateTimeZone( |
|
699 | + $c->getConfig(), |
|
700 | + $c->getSession() |
|
701 | + ); |
|
702 | + }); |
|
703 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
704 | + |
|
705 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
706 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
707 | + |
|
708 | + return new DateTimeFormatter( |
|
709 | + $c->getDateTimeZone()->getTimeZone(), |
|
710 | + $c->getL10N('lib', $language) |
|
711 | + ); |
|
712 | + }); |
|
713 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
714 | + |
|
715 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
716 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
717 | + $listener = new UserMountCacheListener($mountCache); |
|
718 | + $listener->listen($c->getUserManager()); |
|
719 | + return $mountCache; |
|
720 | + }); |
|
721 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
722 | + |
|
723 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
724 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
725 | + $mountCache = $c->query('UserMountCache'); |
|
726 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
727 | + |
|
728 | + // builtin providers |
|
729 | + |
|
730 | + $config = $c->getConfig(); |
|
731 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
732 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
733 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
734 | + |
|
735 | + return $manager; |
|
736 | + }); |
|
737 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
738 | + |
|
739 | + $this->registerService('IniWrapper', function ($c) { |
|
740 | + return new IniGetWrapper(); |
|
741 | + }); |
|
742 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
743 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
744 | + if ($busClass) { |
|
745 | + list($app, $class) = explode('::', $busClass, 2); |
|
746 | + if ($c->getAppManager()->isInstalled($app)) { |
|
747 | + \OC_App::loadApp($app); |
|
748 | + return $c->query($class); |
|
749 | + } else { |
|
750 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
751 | + } |
|
752 | + } else { |
|
753 | + $jobList = $c->getJobList(); |
|
754 | + return new CronBus($jobList); |
|
755 | + } |
|
756 | + }); |
|
757 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
758 | + return new TrustedDomainHelper($this->getConfig()); |
|
759 | + }); |
|
760 | + $this->registerService('Throttler', function (Server $c) { |
|
761 | + return new Throttler( |
|
762 | + $c->getDatabaseConnection(), |
|
763 | + new TimeFactory(), |
|
764 | + $c->getLogger(), |
|
765 | + $c->getConfig() |
|
766 | + ); |
|
767 | + }); |
|
768 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
769 | + // IConfig and IAppManager requires a working database. This code |
|
770 | + // might however be called when ownCloud is not yet setup. |
|
771 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
772 | + $config = $c->getConfig(); |
|
773 | + $appManager = $c->getAppManager(); |
|
774 | + } else { |
|
775 | + $config = null; |
|
776 | + $appManager = null; |
|
777 | + } |
|
778 | + |
|
779 | + return new Checker( |
|
780 | + new EnvironmentHelper(), |
|
781 | + new FileAccessHelper(), |
|
782 | + new AppLocator(), |
|
783 | + $config, |
|
784 | + $c->getMemCacheFactory(), |
|
785 | + $appManager, |
|
786 | + $c->getTempManager() |
|
787 | + ); |
|
788 | + }); |
|
789 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
790 | + if (isset($this['urlParams'])) { |
|
791 | + $urlParams = $this['urlParams']; |
|
792 | + } else { |
|
793 | + $urlParams = []; |
|
794 | + } |
|
795 | + |
|
796 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
797 | + && in_array('fakeinput', stream_get_wrappers()) |
|
798 | + ) { |
|
799 | + $stream = 'fakeinput://data'; |
|
800 | + } else { |
|
801 | + $stream = 'php://input'; |
|
802 | + } |
|
803 | + |
|
804 | + return new Request( |
|
805 | + [ |
|
806 | + 'get' => $_GET, |
|
807 | + 'post' => $_POST, |
|
808 | + 'files' => $_FILES, |
|
809 | + 'server' => $_SERVER, |
|
810 | + 'env' => $_ENV, |
|
811 | + 'cookies' => $_COOKIE, |
|
812 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
813 | + ? $_SERVER['REQUEST_METHOD'] |
|
814 | + : '', |
|
815 | + 'urlParams' => $urlParams, |
|
816 | + ], |
|
817 | + $this->getSecureRandom(), |
|
818 | + $this->getConfig(), |
|
819 | + $this->getCsrfTokenManager(), |
|
820 | + $stream |
|
821 | + ); |
|
822 | + }); |
|
823 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
824 | + |
|
825 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
826 | + return new Mailer( |
|
827 | + $c->getConfig(), |
|
828 | + $c->getLogger(), |
|
829 | + $c->query(Defaults::class), |
|
830 | + $c->getURLGenerator(), |
|
831 | + $c->getL10N('lib') |
|
832 | + ); |
|
833 | + }); |
|
834 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
835 | + |
|
836 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
837 | + $config = $c->getConfig(); |
|
838 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
839 | + if (is_null($factoryClass)) { |
|
840 | + throw new \Exception('ldapProviderFactory not set'); |
|
841 | + } |
|
842 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
843 | + $factory = new $factoryClass($this); |
|
844 | + return $factory->getLDAPProvider(); |
|
845 | + }); |
|
846 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
847 | + $ini = $c->getIniWrapper(); |
|
848 | + $config = $c->getConfig(); |
|
849 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
850 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
851 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
852 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
853 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
854 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
855 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
856 | + } |
|
857 | + return new DBLockingProvider( |
|
858 | + $c->getDatabaseConnection(), |
|
859 | + $c->getLogger(), |
|
860 | + new TimeFactory(), |
|
861 | + $ttl, |
|
862 | + !\OC::$CLI |
|
863 | + ); |
|
864 | + } |
|
865 | + return new NoopLockingProvider(); |
|
866 | + }); |
|
867 | + $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
868 | + |
|
869 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
870 | + return new \OC\Files\Mount\Manager(); |
|
871 | + }); |
|
872 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
873 | + |
|
874 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
875 | + return new \OC\Files\Type\Detection( |
|
876 | + $c->getURLGenerator(), |
|
877 | + \OC::$configDir, |
|
878 | + \OC::$SERVERROOT . '/resources/config/' |
|
879 | + ); |
|
880 | + }); |
|
881 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
882 | + |
|
883 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
884 | + return new \OC\Files\Type\Loader( |
|
885 | + $c->getDatabaseConnection() |
|
886 | + ); |
|
887 | + }); |
|
888 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
889 | + $this->registerService(BundleFetcher::class, function () { |
|
890 | + return new BundleFetcher($this->getL10N('lib')); |
|
891 | + }); |
|
892 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
893 | + return new Manager( |
|
894 | + $c->query(IValidator::class) |
|
895 | + ); |
|
896 | + }); |
|
897 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
898 | + |
|
899 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
900 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
901 | + $manager->registerCapability(function () use ($c) { |
|
902 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
903 | + }); |
|
904 | + $manager->registerCapability(function () use ($c) { |
|
905 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
906 | + }); |
|
907 | + return $manager; |
|
908 | + }); |
|
909 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
910 | + |
|
911 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
912 | + $config = $c->getConfig(); |
|
913 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
914 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
915 | + $factory = new $factoryClass($this); |
|
916 | + $manager = $factory->getManager(); |
|
917 | + |
|
918 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
919 | + $manager = $c->getUserManager(); |
|
920 | + $user = $manager->get($id); |
|
921 | + if(is_null($user)) { |
|
922 | + $l = $c->getL10N('core'); |
|
923 | + $displayName = $l->t('Unknown user'); |
|
924 | + } else { |
|
925 | + $displayName = $user->getDisplayName(); |
|
926 | + } |
|
927 | + return $displayName; |
|
928 | + }); |
|
929 | + |
|
930 | + return $manager; |
|
931 | + }); |
|
932 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
933 | + |
|
934 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
935 | + /* |
|
936 | 936 | * Dark magic for autoloader. |
937 | 937 | * If we do a class_exists it will try to load the class which will |
938 | 938 | * make composer cache the result. Resulting in errors when enabling |
939 | 939 | * the theming app. |
940 | 940 | */ |
941 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
942 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
943 | - $classExists = true; |
|
944 | - } else { |
|
945 | - $classExists = false; |
|
946 | - } |
|
947 | - |
|
948 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
949 | - return new ThemingDefaults( |
|
950 | - $c->getConfig(), |
|
951 | - $c->getL10N('theming'), |
|
952 | - $c->getURLGenerator(), |
|
953 | - $c->getMemCacheFactory(), |
|
954 | - new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
955 | - new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator()), |
|
956 | - $c->getAppManager() |
|
957 | - ); |
|
958 | - } |
|
959 | - return new \OC_Defaults(); |
|
960 | - }); |
|
961 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
962 | - /** @var Factory $cacheFactory */ |
|
963 | - $cacheFactory = $c->query(Factory::class); |
|
964 | - return new SCSSCacher( |
|
965 | - $c->getLogger(), |
|
966 | - $c->query(\OC\Files\AppData\Factory::class), |
|
967 | - $c->getURLGenerator(), |
|
968 | - $c->getConfig(), |
|
969 | - $c->getThemingDefaults(), |
|
970 | - \OC::$SERVERROOT, |
|
971 | - $this->getMemCacheFactory() |
|
972 | - ); |
|
973 | - }); |
|
974 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
975 | - /** @var Factory $cacheFactory */ |
|
976 | - $cacheFactory = $c->query(Factory::class); |
|
977 | - return new JSCombiner( |
|
978 | - $c->getAppDataDir('js'), |
|
979 | - $c->getURLGenerator(), |
|
980 | - $this->getMemCacheFactory(), |
|
981 | - $c->getSystemConfig(), |
|
982 | - $c->getLogger() |
|
983 | - ); |
|
984 | - }); |
|
985 | - $this->registerService(EventDispatcher::class, function () { |
|
986 | - return new EventDispatcher(); |
|
987 | - }); |
|
988 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
989 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
990 | - |
|
991 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
992 | - // FIXME: Instantiiated here due to cyclic dependency |
|
993 | - $request = new Request( |
|
994 | - [ |
|
995 | - 'get' => $_GET, |
|
996 | - 'post' => $_POST, |
|
997 | - 'files' => $_FILES, |
|
998 | - 'server' => $_SERVER, |
|
999 | - 'env' => $_ENV, |
|
1000 | - 'cookies' => $_COOKIE, |
|
1001 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1002 | - ? $_SERVER['REQUEST_METHOD'] |
|
1003 | - : null, |
|
1004 | - ], |
|
1005 | - $c->getSecureRandom(), |
|
1006 | - $c->getConfig() |
|
1007 | - ); |
|
1008 | - |
|
1009 | - return new CryptoWrapper( |
|
1010 | - $c->getConfig(), |
|
1011 | - $c->getCrypto(), |
|
1012 | - $c->getSecureRandom(), |
|
1013 | - $request |
|
1014 | - ); |
|
1015 | - }); |
|
1016 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1017 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1018 | - |
|
1019 | - return new CsrfTokenManager( |
|
1020 | - $tokenGenerator, |
|
1021 | - $c->query(SessionStorage::class) |
|
1022 | - ); |
|
1023 | - }); |
|
1024 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1025 | - return new SessionStorage($c->getSession()); |
|
1026 | - }); |
|
1027 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1028 | - return new ContentSecurityPolicyManager(); |
|
1029 | - }); |
|
1030 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
1031 | - |
|
1032 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1033 | - return new ContentSecurityPolicyNonceManager( |
|
1034 | - $c->getCsrfTokenManager(), |
|
1035 | - $c->getRequest() |
|
1036 | - ); |
|
1037 | - }); |
|
1038 | - |
|
1039 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1040 | - $config = $c->getConfig(); |
|
1041 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1042 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
1043 | - $factory = new $factoryClass($this); |
|
1044 | - |
|
1045 | - $manager = new \OC\Share20\Manager( |
|
1046 | - $c->getLogger(), |
|
1047 | - $c->getConfig(), |
|
1048 | - $c->getSecureRandom(), |
|
1049 | - $c->getHasher(), |
|
1050 | - $c->getMountManager(), |
|
1051 | - $c->getGroupManager(), |
|
1052 | - $c->getL10N('lib'), |
|
1053 | - $c->getL10NFactory(), |
|
1054 | - $factory, |
|
1055 | - $c->getUserManager(), |
|
1056 | - $c->getLazyRootFolder(), |
|
1057 | - $c->getEventDispatcher(), |
|
1058 | - $c->getMailer(), |
|
1059 | - $c->getURLGenerator(), |
|
1060 | - $c->getThemingDefaults() |
|
1061 | - ); |
|
1062 | - |
|
1063 | - return $manager; |
|
1064 | - }); |
|
1065 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1066 | - |
|
1067 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1068 | - $instance = new Collaboration\Collaborators\Search($c); |
|
1069 | - |
|
1070 | - // register default plugins |
|
1071 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1072 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1073 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1074 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1075 | - |
|
1076 | - return $instance; |
|
1077 | - }); |
|
1078 | - $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1079 | - |
|
1080 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1081 | - |
|
1082 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1083 | - $manager = new \OC\Settings\Manager( |
|
1084 | - $c->getLogger(), |
|
1085 | - $c->getDatabaseConnection(), |
|
1086 | - $c->getL10N('lib'), |
|
1087 | - $c->getConfig(), |
|
1088 | - $c->getEncryptionManager(), |
|
1089 | - $c->getUserManager(), |
|
1090 | - $c->getLockingProvider(), |
|
1091 | - $c->getRequest(), |
|
1092 | - $c->getURLGenerator(), |
|
1093 | - $c->query(AccountManager::class), |
|
1094 | - $c->getGroupManager(), |
|
1095 | - $c->getL10NFactory(), |
|
1096 | - $c->getAppManager() |
|
1097 | - ); |
|
1098 | - return $manager; |
|
1099 | - }); |
|
1100 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1101 | - return new \OC\Files\AppData\Factory( |
|
1102 | - $c->getRootFolder(), |
|
1103 | - $c->getSystemConfig() |
|
1104 | - ); |
|
1105 | - }); |
|
1106 | - |
|
1107 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1108 | - return new LockdownManager(function () use ($c) { |
|
1109 | - return $c->getSession(); |
|
1110 | - }); |
|
1111 | - }); |
|
1112 | - |
|
1113 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1114 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1115 | - }); |
|
1116 | - |
|
1117 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1118 | - return new CloudIdManager(); |
|
1119 | - }); |
|
1120 | - |
|
1121 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1122 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1123 | - |
|
1124 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1125 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1126 | - |
|
1127 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1128 | - return new Defaults( |
|
1129 | - $c->getThemingDefaults() |
|
1130 | - ); |
|
1131 | - }); |
|
1132 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1133 | - |
|
1134 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1135 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1136 | - }); |
|
1137 | - |
|
1138 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1139 | - return new ShareHelper( |
|
1140 | - $c->query(\OCP\Share\IManager::class) |
|
1141 | - ); |
|
1142 | - }); |
|
1143 | - |
|
1144 | - $this->registerService(Installer::class, function(Server $c) { |
|
1145 | - return new Installer( |
|
1146 | - $c->getAppFetcher(), |
|
1147 | - $c->getHTTPClientService(), |
|
1148 | - $c->getTempManager(), |
|
1149 | - $c->getLogger(), |
|
1150 | - $c->getConfig() |
|
1151 | - ); |
|
1152 | - }); |
|
1153 | - |
|
1154 | - $this->registerService(IApiFactory::class, function(Server $c) { |
|
1155 | - return new ApiFactory($c->getHTTPClientService()); |
|
1156 | - }); |
|
1157 | - |
|
1158 | - $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1159 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
1160 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1161 | - }); |
|
1162 | - |
|
1163 | - $this->registerService(IContactsStore::class, function(Server $c) { |
|
1164 | - return new ContactsStore( |
|
1165 | - $c->getContactsManager(), |
|
1166 | - $c->getConfig(), |
|
1167 | - $c->getUserManager(), |
|
1168 | - $c->getGroupManager() |
|
1169 | - ); |
|
1170 | - }); |
|
1171 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1172 | - |
|
1173 | - $this->connectDispatcher(); |
|
1174 | - } |
|
1175 | - |
|
1176 | - /** |
|
1177 | - * @return \OCP\Calendar\IManager |
|
1178 | - */ |
|
1179 | - public function getCalendarManager() { |
|
1180 | - return $this->query('CalendarManager'); |
|
1181 | - } |
|
1182 | - |
|
1183 | - private function connectDispatcher() { |
|
1184 | - $dispatcher = $this->getEventDispatcher(); |
|
1185 | - |
|
1186 | - // Delete avatar on user deletion |
|
1187 | - $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1188 | - $logger = $this->getLogger(); |
|
1189 | - $manager = $this->getAvatarManager(); |
|
1190 | - /** @var IUser $user */ |
|
1191 | - $user = $e->getSubject(); |
|
1192 | - |
|
1193 | - try { |
|
1194 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1195 | - $avatar->remove(); |
|
1196 | - } catch (NotFoundException $e) { |
|
1197 | - // no avatar to remove |
|
1198 | - } catch (\Exception $e) { |
|
1199 | - // Ignore exceptions |
|
1200 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1201 | - } |
|
1202 | - }); |
|
1203 | - |
|
1204 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1205 | - $manager = $this->getAvatarManager(); |
|
1206 | - /** @var IUser $user */ |
|
1207 | - $user = $e->getSubject(); |
|
1208 | - $feature = $e->getArgument('feature'); |
|
1209 | - $oldValue = $e->getArgument('oldValue'); |
|
1210 | - $value = $e->getArgument('value'); |
|
1211 | - |
|
1212 | - try { |
|
1213 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1214 | - $avatar->userChanged($feature, $oldValue, $value); |
|
1215 | - } catch (NotFoundException $e) { |
|
1216 | - // no avatar to remove |
|
1217 | - } |
|
1218 | - }); |
|
1219 | - } |
|
1220 | - |
|
1221 | - /** |
|
1222 | - * @return \OCP\Contacts\IManager |
|
1223 | - */ |
|
1224 | - public function getContactsManager() { |
|
1225 | - return $this->query('ContactsManager'); |
|
1226 | - } |
|
1227 | - |
|
1228 | - /** |
|
1229 | - * @return \OC\Encryption\Manager |
|
1230 | - */ |
|
1231 | - public function getEncryptionManager() { |
|
1232 | - return $this->query('EncryptionManager'); |
|
1233 | - } |
|
1234 | - |
|
1235 | - /** |
|
1236 | - * @return \OC\Encryption\File |
|
1237 | - */ |
|
1238 | - public function getEncryptionFilesHelper() { |
|
1239 | - return $this->query('EncryptionFileHelper'); |
|
1240 | - } |
|
1241 | - |
|
1242 | - /** |
|
1243 | - * @return \OCP\Encryption\Keys\IStorage |
|
1244 | - */ |
|
1245 | - public function getEncryptionKeyStorage() { |
|
1246 | - return $this->query('EncryptionKeyStorage'); |
|
1247 | - } |
|
1248 | - |
|
1249 | - /** |
|
1250 | - * The current request object holding all information about the request |
|
1251 | - * currently being processed is returned from this method. |
|
1252 | - * In case the current execution was not initiated by a web request null is returned |
|
1253 | - * |
|
1254 | - * @return \OCP\IRequest |
|
1255 | - */ |
|
1256 | - public function getRequest() { |
|
1257 | - return $this->query('Request'); |
|
1258 | - } |
|
1259 | - |
|
1260 | - /** |
|
1261 | - * Returns the preview manager which can create preview images for a given file |
|
1262 | - * |
|
1263 | - * @return \OCP\IPreview |
|
1264 | - */ |
|
1265 | - public function getPreviewManager() { |
|
1266 | - return $this->query('PreviewManager'); |
|
1267 | - } |
|
1268 | - |
|
1269 | - /** |
|
1270 | - * Returns the tag manager which can get and set tags for different object types |
|
1271 | - * |
|
1272 | - * @see \OCP\ITagManager::load() |
|
1273 | - * @return \OCP\ITagManager |
|
1274 | - */ |
|
1275 | - public function getTagManager() { |
|
1276 | - return $this->query('TagManager'); |
|
1277 | - } |
|
1278 | - |
|
1279 | - /** |
|
1280 | - * Returns the system-tag manager |
|
1281 | - * |
|
1282 | - * @return \OCP\SystemTag\ISystemTagManager |
|
1283 | - * |
|
1284 | - * @since 9.0.0 |
|
1285 | - */ |
|
1286 | - public function getSystemTagManager() { |
|
1287 | - return $this->query('SystemTagManager'); |
|
1288 | - } |
|
1289 | - |
|
1290 | - /** |
|
1291 | - * Returns the system-tag object mapper |
|
1292 | - * |
|
1293 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1294 | - * |
|
1295 | - * @since 9.0.0 |
|
1296 | - */ |
|
1297 | - public function getSystemTagObjectMapper() { |
|
1298 | - return $this->query('SystemTagObjectMapper'); |
|
1299 | - } |
|
1300 | - |
|
1301 | - /** |
|
1302 | - * Returns the avatar manager, used for avatar functionality |
|
1303 | - * |
|
1304 | - * @return \OCP\IAvatarManager |
|
1305 | - */ |
|
1306 | - public function getAvatarManager() { |
|
1307 | - return $this->query('AvatarManager'); |
|
1308 | - } |
|
1309 | - |
|
1310 | - /** |
|
1311 | - * Returns the root folder of ownCloud's data directory |
|
1312 | - * |
|
1313 | - * @return \OCP\Files\IRootFolder |
|
1314 | - */ |
|
1315 | - public function getRootFolder() { |
|
1316 | - return $this->query('LazyRootFolder'); |
|
1317 | - } |
|
1318 | - |
|
1319 | - /** |
|
1320 | - * Returns the root folder of ownCloud's data directory |
|
1321 | - * This is the lazy variant so this gets only initialized once it |
|
1322 | - * is actually used. |
|
1323 | - * |
|
1324 | - * @return \OCP\Files\IRootFolder |
|
1325 | - */ |
|
1326 | - public function getLazyRootFolder() { |
|
1327 | - return $this->query('LazyRootFolder'); |
|
1328 | - } |
|
1329 | - |
|
1330 | - /** |
|
1331 | - * Returns a view to ownCloud's files folder |
|
1332 | - * |
|
1333 | - * @param string $userId user ID |
|
1334 | - * @return \OCP\Files\Folder|null |
|
1335 | - */ |
|
1336 | - public function getUserFolder($userId = null) { |
|
1337 | - if ($userId === null) { |
|
1338 | - $user = $this->getUserSession()->getUser(); |
|
1339 | - if (!$user) { |
|
1340 | - return null; |
|
1341 | - } |
|
1342 | - $userId = $user->getUID(); |
|
1343 | - } |
|
1344 | - $root = $this->getRootFolder(); |
|
1345 | - return $root->getUserFolder($userId); |
|
1346 | - } |
|
1347 | - |
|
1348 | - /** |
|
1349 | - * Returns an app-specific view in ownClouds data directory |
|
1350 | - * |
|
1351 | - * @return \OCP\Files\Folder |
|
1352 | - * @deprecated since 9.2.0 use IAppData |
|
1353 | - */ |
|
1354 | - public function getAppFolder() { |
|
1355 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1356 | - $root = $this->getRootFolder(); |
|
1357 | - if (!$root->nodeExists($dir)) { |
|
1358 | - $folder = $root->newFolder($dir); |
|
1359 | - } else { |
|
1360 | - $folder = $root->get($dir); |
|
1361 | - } |
|
1362 | - return $folder; |
|
1363 | - } |
|
1364 | - |
|
1365 | - /** |
|
1366 | - * @return \OC\User\Manager |
|
1367 | - */ |
|
1368 | - public function getUserManager() { |
|
1369 | - return $this->query('UserManager'); |
|
1370 | - } |
|
1371 | - |
|
1372 | - /** |
|
1373 | - * @return \OC\Group\Manager |
|
1374 | - */ |
|
1375 | - public function getGroupManager() { |
|
1376 | - return $this->query('GroupManager'); |
|
1377 | - } |
|
1378 | - |
|
1379 | - /** |
|
1380 | - * @return \OC\User\Session |
|
1381 | - */ |
|
1382 | - public function getUserSession() { |
|
1383 | - return $this->query('UserSession'); |
|
1384 | - } |
|
1385 | - |
|
1386 | - /** |
|
1387 | - * @return \OCP\ISession |
|
1388 | - */ |
|
1389 | - public function getSession() { |
|
1390 | - return $this->query('UserSession')->getSession(); |
|
1391 | - } |
|
1392 | - |
|
1393 | - /** |
|
1394 | - * @param \OCP\ISession $session |
|
1395 | - */ |
|
1396 | - public function setSession(\OCP\ISession $session) { |
|
1397 | - $this->query(SessionStorage::class)->setSession($session); |
|
1398 | - $this->query('UserSession')->setSession($session); |
|
1399 | - $this->query(Store::class)->setSession($session); |
|
1400 | - } |
|
1401 | - |
|
1402 | - /** |
|
1403 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1404 | - */ |
|
1405 | - public function getTwoFactorAuthManager() { |
|
1406 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1407 | - } |
|
1408 | - |
|
1409 | - /** |
|
1410 | - * @return \OC\NavigationManager |
|
1411 | - */ |
|
1412 | - public function getNavigationManager() { |
|
1413 | - return $this->query('NavigationManager'); |
|
1414 | - } |
|
1415 | - |
|
1416 | - /** |
|
1417 | - * @return \OCP\IConfig |
|
1418 | - */ |
|
1419 | - public function getConfig() { |
|
1420 | - return $this->query('AllConfig'); |
|
1421 | - } |
|
1422 | - |
|
1423 | - /** |
|
1424 | - * @return \OC\SystemConfig |
|
1425 | - */ |
|
1426 | - public function getSystemConfig() { |
|
1427 | - return $this->query('SystemConfig'); |
|
1428 | - } |
|
1429 | - |
|
1430 | - /** |
|
1431 | - * Returns the app config manager |
|
1432 | - * |
|
1433 | - * @return \OCP\IAppConfig |
|
1434 | - */ |
|
1435 | - public function getAppConfig() { |
|
1436 | - return $this->query('AppConfig'); |
|
1437 | - } |
|
1438 | - |
|
1439 | - /** |
|
1440 | - * @return \OCP\L10N\IFactory |
|
1441 | - */ |
|
1442 | - public function getL10NFactory() { |
|
1443 | - return $this->query('L10NFactory'); |
|
1444 | - } |
|
1445 | - |
|
1446 | - /** |
|
1447 | - * get an L10N instance |
|
1448 | - * |
|
1449 | - * @param string $app appid |
|
1450 | - * @param string $lang |
|
1451 | - * @return IL10N |
|
1452 | - */ |
|
1453 | - public function getL10N($app, $lang = null) { |
|
1454 | - return $this->getL10NFactory()->get($app, $lang); |
|
1455 | - } |
|
1456 | - |
|
1457 | - /** |
|
1458 | - * @return \OCP\IURLGenerator |
|
1459 | - */ |
|
1460 | - public function getURLGenerator() { |
|
1461 | - return $this->query('URLGenerator'); |
|
1462 | - } |
|
1463 | - |
|
1464 | - /** |
|
1465 | - * @return AppFetcher |
|
1466 | - */ |
|
1467 | - public function getAppFetcher() { |
|
1468 | - return $this->query(AppFetcher::class); |
|
1469 | - } |
|
1470 | - |
|
1471 | - /** |
|
1472 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1473 | - * getMemCacheFactory() instead. |
|
1474 | - * |
|
1475 | - * @return \OCP\ICache |
|
1476 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1477 | - */ |
|
1478 | - public function getCache() { |
|
1479 | - return $this->query('UserCache'); |
|
1480 | - } |
|
1481 | - |
|
1482 | - /** |
|
1483 | - * Returns an \OCP\CacheFactory instance |
|
1484 | - * |
|
1485 | - * @return \OCP\ICacheFactory |
|
1486 | - */ |
|
1487 | - public function getMemCacheFactory() { |
|
1488 | - return $this->query('MemCacheFactory'); |
|
1489 | - } |
|
1490 | - |
|
1491 | - /** |
|
1492 | - * Returns an \OC\RedisFactory instance |
|
1493 | - * |
|
1494 | - * @return \OC\RedisFactory |
|
1495 | - */ |
|
1496 | - public function getGetRedisFactory() { |
|
1497 | - return $this->query('RedisFactory'); |
|
1498 | - } |
|
1499 | - |
|
1500 | - |
|
1501 | - /** |
|
1502 | - * Returns the current session |
|
1503 | - * |
|
1504 | - * @return \OCP\IDBConnection |
|
1505 | - */ |
|
1506 | - public function getDatabaseConnection() { |
|
1507 | - return $this->query('DatabaseConnection'); |
|
1508 | - } |
|
1509 | - |
|
1510 | - /** |
|
1511 | - * Returns the activity manager |
|
1512 | - * |
|
1513 | - * @return \OCP\Activity\IManager |
|
1514 | - */ |
|
1515 | - public function getActivityManager() { |
|
1516 | - return $this->query('ActivityManager'); |
|
1517 | - } |
|
1518 | - |
|
1519 | - /** |
|
1520 | - * Returns an job list for controlling background jobs |
|
1521 | - * |
|
1522 | - * @return \OCP\BackgroundJob\IJobList |
|
1523 | - */ |
|
1524 | - public function getJobList() { |
|
1525 | - return $this->query('JobList'); |
|
1526 | - } |
|
1527 | - |
|
1528 | - /** |
|
1529 | - * Returns a logger instance |
|
1530 | - * |
|
1531 | - * @return \OCP\ILogger |
|
1532 | - */ |
|
1533 | - public function getLogger() { |
|
1534 | - return $this->query('Logger'); |
|
1535 | - } |
|
1536 | - |
|
1537 | - /** |
|
1538 | - * @return ILogFactory |
|
1539 | - * @throws \OCP\AppFramework\QueryException |
|
1540 | - */ |
|
1541 | - public function getLogFactory() { |
|
1542 | - return $this->query('LogFactory'); |
|
1543 | - } |
|
1544 | - |
|
1545 | - /** |
|
1546 | - * Returns a router for generating and matching urls |
|
1547 | - * |
|
1548 | - * @return \OCP\Route\IRouter |
|
1549 | - */ |
|
1550 | - public function getRouter() { |
|
1551 | - return $this->query('Router'); |
|
1552 | - } |
|
1553 | - |
|
1554 | - /** |
|
1555 | - * Returns a search instance |
|
1556 | - * |
|
1557 | - * @return \OCP\ISearch |
|
1558 | - */ |
|
1559 | - public function getSearch() { |
|
1560 | - return $this->query('Search'); |
|
1561 | - } |
|
1562 | - |
|
1563 | - /** |
|
1564 | - * Returns a SecureRandom instance |
|
1565 | - * |
|
1566 | - * @return \OCP\Security\ISecureRandom |
|
1567 | - */ |
|
1568 | - public function getSecureRandom() { |
|
1569 | - return $this->query('SecureRandom'); |
|
1570 | - } |
|
1571 | - |
|
1572 | - /** |
|
1573 | - * Returns a Crypto instance |
|
1574 | - * |
|
1575 | - * @return \OCP\Security\ICrypto |
|
1576 | - */ |
|
1577 | - public function getCrypto() { |
|
1578 | - return $this->query('Crypto'); |
|
1579 | - } |
|
1580 | - |
|
1581 | - /** |
|
1582 | - * Returns a Hasher instance |
|
1583 | - * |
|
1584 | - * @return \OCP\Security\IHasher |
|
1585 | - */ |
|
1586 | - public function getHasher() { |
|
1587 | - return $this->query('Hasher'); |
|
1588 | - } |
|
1589 | - |
|
1590 | - /** |
|
1591 | - * Returns a CredentialsManager instance |
|
1592 | - * |
|
1593 | - * @return \OCP\Security\ICredentialsManager |
|
1594 | - */ |
|
1595 | - public function getCredentialsManager() { |
|
1596 | - return $this->query('CredentialsManager'); |
|
1597 | - } |
|
1598 | - |
|
1599 | - /** |
|
1600 | - * Get the certificate manager for the user |
|
1601 | - * |
|
1602 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1603 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1604 | - */ |
|
1605 | - public function getCertificateManager($userId = '') { |
|
1606 | - if ($userId === '') { |
|
1607 | - $userSession = $this->getUserSession(); |
|
1608 | - $user = $userSession->getUser(); |
|
1609 | - if (is_null($user)) { |
|
1610 | - return null; |
|
1611 | - } |
|
1612 | - $userId = $user->getUID(); |
|
1613 | - } |
|
1614 | - return new CertificateManager( |
|
1615 | - $userId, |
|
1616 | - new View(), |
|
1617 | - $this->getConfig(), |
|
1618 | - $this->getLogger(), |
|
1619 | - $this->getSecureRandom() |
|
1620 | - ); |
|
1621 | - } |
|
1622 | - |
|
1623 | - /** |
|
1624 | - * Returns an instance of the HTTP client service |
|
1625 | - * |
|
1626 | - * @return \OCP\Http\Client\IClientService |
|
1627 | - */ |
|
1628 | - public function getHTTPClientService() { |
|
1629 | - return $this->query('HttpClientService'); |
|
1630 | - } |
|
1631 | - |
|
1632 | - /** |
|
1633 | - * Create a new event source |
|
1634 | - * |
|
1635 | - * @return \OCP\IEventSource |
|
1636 | - */ |
|
1637 | - public function createEventSource() { |
|
1638 | - return new \OC_EventSource(); |
|
1639 | - } |
|
1640 | - |
|
1641 | - /** |
|
1642 | - * Get the active event logger |
|
1643 | - * |
|
1644 | - * The returned logger only logs data when debug mode is enabled |
|
1645 | - * |
|
1646 | - * @return \OCP\Diagnostics\IEventLogger |
|
1647 | - */ |
|
1648 | - public function getEventLogger() { |
|
1649 | - return $this->query('EventLogger'); |
|
1650 | - } |
|
1651 | - |
|
1652 | - /** |
|
1653 | - * Get the active query logger |
|
1654 | - * |
|
1655 | - * The returned logger only logs data when debug mode is enabled |
|
1656 | - * |
|
1657 | - * @return \OCP\Diagnostics\IQueryLogger |
|
1658 | - */ |
|
1659 | - public function getQueryLogger() { |
|
1660 | - return $this->query('QueryLogger'); |
|
1661 | - } |
|
1662 | - |
|
1663 | - /** |
|
1664 | - * Get the manager for temporary files and folders |
|
1665 | - * |
|
1666 | - * @return \OCP\ITempManager |
|
1667 | - */ |
|
1668 | - public function getTempManager() { |
|
1669 | - return $this->query('TempManager'); |
|
1670 | - } |
|
1671 | - |
|
1672 | - /** |
|
1673 | - * Get the app manager |
|
1674 | - * |
|
1675 | - * @return \OCP\App\IAppManager |
|
1676 | - */ |
|
1677 | - public function getAppManager() { |
|
1678 | - return $this->query('AppManager'); |
|
1679 | - } |
|
1680 | - |
|
1681 | - /** |
|
1682 | - * Creates a new mailer |
|
1683 | - * |
|
1684 | - * @return \OCP\Mail\IMailer |
|
1685 | - */ |
|
1686 | - public function getMailer() { |
|
1687 | - return $this->query('Mailer'); |
|
1688 | - } |
|
1689 | - |
|
1690 | - /** |
|
1691 | - * Get the webroot |
|
1692 | - * |
|
1693 | - * @return string |
|
1694 | - */ |
|
1695 | - public function getWebRoot() { |
|
1696 | - return $this->webRoot; |
|
1697 | - } |
|
1698 | - |
|
1699 | - /** |
|
1700 | - * @return \OC\OCSClient |
|
1701 | - */ |
|
1702 | - public function getOcsClient() { |
|
1703 | - return $this->query('OcsClient'); |
|
1704 | - } |
|
1705 | - |
|
1706 | - /** |
|
1707 | - * @return \OCP\IDateTimeZone |
|
1708 | - */ |
|
1709 | - public function getDateTimeZone() { |
|
1710 | - return $this->query('DateTimeZone'); |
|
1711 | - } |
|
1712 | - |
|
1713 | - /** |
|
1714 | - * @return \OCP\IDateTimeFormatter |
|
1715 | - */ |
|
1716 | - public function getDateTimeFormatter() { |
|
1717 | - return $this->query('DateTimeFormatter'); |
|
1718 | - } |
|
1719 | - |
|
1720 | - /** |
|
1721 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
1722 | - */ |
|
1723 | - public function getMountProviderCollection() { |
|
1724 | - return $this->query('MountConfigManager'); |
|
1725 | - } |
|
1726 | - |
|
1727 | - /** |
|
1728 | - * Get the IniWrapper |
|
1729 | - * |
|
1730 | - * @return IniGetWrapper |
|
1731 | - */ |
|
1732 | - public function getIniWrapper() { |
|
1733 | - return $this->query('IniWrapper'); |
|
1734 | - } |
|
1735 | - |
|
1736 | - /** |
|
1737 | - * @return \OCP\Command\IBus |
|
1738 | - */ |
|
1739 | - public function getCommandBus() { |
|
1740 | - return $this->query('AsyncCommandBus'); |
|
1741 | - } |
|
1742 | - |
|
1743 | - /** |
|
1744 | - * Get the trusted domain helper |
|
1745 | - * |
|
1746 | - * @return TrustedDomainHelper |
|
1747 | - */ |
|
1748 | - public function getTrustedDomainHelper() { |
|
1749 | - return $this->query('TrustedDomainHelper'); |
|
1750 | - } |
|
1751 | - |
|
1752 | - /** |
|
1753 | - * Get the locking provider |
|
1754 | - * |
|
1755 | - * @return \OCP\Lock\ILockingProvider |
|
1756 | - * @since 8.1.0 |
|
1757 | - */ |
|
1758 | - public function getLockingProvider() { |
|
1759 | - return $this->query('LockingProvider'); |
|
1760 | - } |
|
1761 | - |
|
1762 | - /** |
|
1763 | - * @return \OCP\Files\Mount\IMountManager |
|
1764 | - **/ |
|
1765 | - function getMountManager() { |
|
1766 | - return $this->query('MountManager'); |
|
1767 | - } |
|
1768 | - |
|
1769 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
1770 | - function getUserMountCache() { |
|
1771 | - return $this->query('UserMountCache'); |
|
1772 | - } |
|
1773 | - |
|
1774 | - /** |
|
1775 | - * Get the MimeTypeDetector |
|
1776 | - * |
|
1777 | - * @return \OCP\Files\IMimeTypeDetector |
|
1778 | - */ |
|
1779 | - public function getMimeTypeDetector() { |
|
1780 | - return $this->query('MimeTypeDetector'); |
|
1781 | - } |
|
1782 | - |
|
1783 | - /** |
|
1784 | - * Get the MimeTypeLoader |
|
1785 | - * |
|
1786 | - * @return \OCP\Files\IMimeTypeLoader |
|
1787 | - */ |
|
1788 | - public function getMimeTypeLoader() { |
|
1789 | - return $this->query('MimeTypeLoader'); |
|
1790 | - } |
|
1791 | - |
|
1792 | - /** |
|
1793 | - * Get the manager of all the capabilities |
|
1794 | - * |
|
1795 | - * @return \OC\CapabilitiesManager |
|
1796 | - */ |
|
1797 | - public function getCapabilitiesManager() { |
|
1798 | - return $this->query('CapabilitiesManager'); |
|
1799 | - } |
|
1800 | - |
|
1801 | - /** |
|
1802 | - * Get the EventDispatcher |
|
1803 | - * |
|
1804 | - * @return EventDispatcherInterface |
|
1805 | - * @since 8.2.0 |
|
1806 | - */ |
|
1807 | - public function getEventDispatcher() { |
|
1808 | - return $this->query('EventDispatcher'); |
|
1809 | - } |
|
1810 | - |
|
1811 | - /** |
|
1812 | - * Get the Notification Manager |
|
1813 | - * |
|
1814 | - * @return \OCP\Notification\IManager |
|
1815 | - * @since 8.2.0 |
|
1816 | - */ |
|
1817 | - public function getNotificationManager() { |
|
1818 | - return $this->query('NotificationManager'); |
|
1819 | - } |
|
1820 | - |
|
1821 | - /** |
|
1822 | - * @return \OCP\Comments\ICommentsManager |
|
1823 | - */ |
|
1824 | - public function getCommentsManager() { |
|
1825 | - return $this->query('CommentsManager'); |
|
1826 | - } |
|
1827 | - |
|
1828 | - /** |
|
1829 | - * @return \OCA\Theming\ThemingDefaults |
|
1830 | - */ |
|
1831 | - public function getThemingDefaults() { |
|
1832 | - return $this->query('ThemingDefaults'); |
|
1833 | - } |
|
1834 | - |
|
1835 | - /** |
|
1836 | - * @return \OC\IntegrityCheck\Checker |
|
1837 | - */ |
|
1838 | - public function getIntegrityCodeChecker() { |
|
1839 | - return $this->query('IntegrityCodeChecker'); |
|
1840 | - } |
|
1841 | - |
|
1842 | - /** |
|
1843 | - * @return \OC\Session\CryptoWrapper |
|
1844 | - */ |
|
1845 | - public function getSessionCryptoWrapper() { |
|
1846 | - return $this->query('CryptoWrapper'); |
|
1847 | - } |
|
1848 | - |
|
1849 | - /** |
|
1850 | - * @return CsrfTokenManager |
|
1851 | - */ |
|
1852 | - public function getCsrfTokenManager() { |
|
1853 | - return $this->query('CsrfTokenManager'); |
|
1854 | - } |
|
1855 | - |
|
1856 | - /** |
|
1857 | - * @return Throttler |
|
1858 | - */ |
|
1859 | - public function getBruteForceThrottler() { |
|
1860 | - return $this->query('Throttler'); |
|
1861 | - } |
|
1862 | - |
|
1863 | - /** |
|
1864 | - * @return IContentSecurityPolicyManager |
|
1865 | - */ |
|
1866 | - public function getContentSecurityPolicyManager() { |
|
1867 | - return $this->query('ContentSecurityPolicyManager'); |
|
1868 | - } |
|
1869 | - |
|
1870 | - /** |
|
1871 | - * @return ContentSecurityPolicyNonceManager |
|
1872 | - */ |
|
1873 | - public function getContentSecurityPolicyNonceManager() { |
|
1874 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
1875 | - } |
|
1876 | - |
|
1877 | - /** |
|
1878 | - * Not a public API as of 8.2, wait for 9.0 |
|
1879 | - * |
|
1880 | - * @return \OCA\Files_External\Service\BackendService |
|
1881 | - */ |
|
1882 | - public function getStoragesBackendService() { |
|
1883 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1884 | - } |
|
1885 | - |
|
1886 | - /** |
|
1887 | - * Not a public API as of 8.2, wait for 9.0 |
|
1888 | - * |
|
1889 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1890 | - */ |
|
1891 | - public function getGlobalStoragesService() { |
|
1892 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1893 | - } |
|
1894 | - |
|
1895 | - /** |
|
1896 | - * Not a public API as of 8.2, wait for 9.0 |
|
1897 | - * |
|
1898 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1899 | - */ |
|
1900 | - public function getUserGlobalStoragesService() { |
|
1901 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1902 | - } |
|
1903 | - |
|
1904 | - /** |
|
1905 | - * Not a public API as of 8.2, wait for 9.0 |
|
1906 | - * |
|
1907 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
1908 | - */ |
|
1909 | - public function getUserStoragesService() { |
|
1910 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1911 | - } |
|
1912 | - |
|
1913 | - /** |
|
1914 | - * @return \OCP\Share\IManager |
|
1915 | - */ |
|
1916 | - public function getShareManager() { |
|
1917 | - return $this->query('ShareManager'); |
|
1918 | - } |
|
1919 | - |
|
1920 | - /** |
|
1921 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
1922 | - */ |
|
1923 | - public function getCollaboratorSearch() { |
|
1924 | - return $this->query('CollaboratorSearch'); |
|
1925 | - } |
|
1926 | - |
|
1927 | - /** |
|
1928 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
1929 | - */ |
|
1930 | - public function getAutoCompleteManager(){ |
|
1931 | - return $this->query(IManager::class); |
|
1932 | - } |
|
1933 | - |
|
1934 | - /** |
|
1935 | - * Returns the LDAP Provider |
|
1936 | - * |
|
1937 | - * @return \OCP\LDAP\ILDAPProvider |
|
1938 | - */ |
|
1939 | - public function getLDAPProvider() { |
|
1940 | - return $this->query('LDAPProvider'); |
|
1941 | - } |
|
1942 | - |
|
1943 | - /** |
|
1944 | - * @return \OCP\Settings\IManager |
|
1945 | - */ |
|
1946 | - public function getSettingsManager() { |
|
1947 | - return $this->query('SettingsManager'); |
|
1948 | - } |
|
1949 | - |
|
1950 | - /** |
|
1951 | - * @return \OCP\Files\IAppData |
|
1952 | - */ |
|
1953 | - public function getAppDataDir($app) { |
|
1954 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
1955 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1956 | - return $factory->get($app); |
|
1957 | - } |
|
1958 | - |
|
1959 | - /** |
|
1960 | - * @return \OCP\Lockdown\ILockdownManager |
|
1961 | - */ |
|
1962 | - public function getLockdownManager() { |
|
1963 | - return $this->query('LockdownManager'); |
|
1964 | - } |
|
1965 | - |
|
1966 | - /** |
|
1967 | - * @return \OCP\Federation\ICloudIdManager |
|
1968 | - */ |
|
1969 | - public function getCloudIdManager() { |
|
1970 | - return $this->query(ICloudIdManager::class); |
|
1971 | - } |
|
1972 | - |
|
1973 | - /** |
|
1974 | - * @return \OCP\Remote\Api\IApiFactory |
|
1975 | - */ |
|
1976 | - public function getRemoteApiFactory() { |
|
1977 | - return $this->query(IApiFactory::class); |
|
1978 | - } |
|
1979 | - |
|
1980 | - /** |
|
1981 | - * @return \OCP\Remote\IInstanceFactory |
|
1982 | - */ |
|
1983 | - public function getRemoteInstanceFactory() { |
|
1984 | - return $this->query(IInstanceFactory::class); |
|
1985 | - } |
|
941 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
942 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
943 | + $classExists = true; |
|
944 | + } else { |
|
945 | + $classExists = false; |
|
946 | + } |
|
947 | + |
|
948 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
949 | + return new ThemingDefaults( |
|
950 | + $c->getConfig(), |
|
951 | + $c->getL10N('theming'), |
|
952 | + $c->getURLGenerator(), |
|
953 | + $c->getMemCacheFactory(), |
|
954 | + new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
955 | + new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator()), |
|
956 | + $c->getAppManager() |
|
957 | + ); |
|
958 | + } |
|
959 | + return new \OC_Defaults(); |
|
960 | + }); |
|
961 | + $this->registerService(SCSSCacher::class, function (Server $c) { |
|
962 | + /** @var Factory $cacheFactory */ |
|
963 | + $cacheFactory = $c->query(Factory::class); |
|
964 | + return new SCSSCacher( |
|
965 | + $c->getLogger(), |
|
966 | + $c->query(\OC\Files\AppData\Factory::class), |
|
967 | + $c->getURLGenerator(), |
|
968 | + $c->getConfig(), |
|
969 | + $c->getThemingDefaults(), |
|
970 | + \OC::$SERVERROOT, |
|
971 | + $this->getMemCacheFactory() |
|
972 | + ); |
|
973 | + }); |
|
974 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
975 | + /** @var Factory $cacheFactory */ |
|
976 | + $cacheFactory = $c->query(Factory::class); |
|
977 | + return new JSCombiner( |
|
978 | + $c->getAppDataDir('js'), |
|
979 | + $c->getURLGenerator(), |
|
980 | + $this->getMemCacheFactory(), |
|
981 | + $c->getSystemConfig(), |
|
982 | + $c->getLogger() |
|
983 | + ); |
|
984 | + }); |
|
985 | + $this->registerService(EventDispatcher::class, function () { |
|
986 | + return new EventDispatcher(); |
|
987 | + }); |
|
988 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
989 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
990 | + |
|
991 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
992 | + // FIXME: Instantiiated here due to cyclic dependency |
|
993 | + $request = new Request( |
|
994 | + [ |
|
995 | + 'get' => $_GET, |
|
996 | + 'post' => $_POST, |
|
997 | + 'files' => $_FILES, |
|
998 | + 'server' => $_SERVER, |
|
999 | + 'env' => $_ENV, |
|
1000 | + 'cookies' => $_COOKIE, |
|
1001 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1002 | + ? $_SERVER['REQUEST_METHOD'] |
|
1003 | + : null, |
|
1004 | + ], |
|
1005 | + $c->getSecureRandom(), |
|
1006 | + $c->getConfig() |
|
1007 | + ); |
|
1008 | + |
|
1009 | + return new CryptoWrapper( |
|
1010 | + $c->getConfig(), |
|
1011 | + $c->getCrypto(), |
|
1012 | + $c->getSecureRandom(), |
|
1013 | + $request |
|
1014 | + ); |
|
1015 | + }); |
|
1016 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1017 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1018 | + |
|
1019 | + return new CsrfTokenManager( |
|
1020 | + $tokenGenerator, |
|
1021 | + $c->query(SessionStorage::class) |
|
1022 | + ); |
|
1023 | + }); |
|
1024 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
1025 | + return new SessionStorage($c->getSession()); |
|
1026 | + }); |
|
1027 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1028 | + return new ContentSecurityPolicyManager(); |
|
1029 | + }); |
|
1030 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
1031 | + |
|
1032 | + $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1033 | + return new ContentSecurityPolicyNonceManager( |
|
1034 | + $c->getCsrfTokenManager(), |
|
1035 | + $c->getRequest() |
|
1036 | + ); |
|
1037 | + }); |
|
1038 | + |
|
1039 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1040 | + $config = $c->getConfig(); |
|
1041 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1042 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
1043 | + $factory = new $factoryClass($this); |
|
1044 | + |
|
1045 | + $manager = new \OC\Share20\Manager( |
|
1046 | + $c->getLogger(), |
|
1047 | + $c->getConfig(), |
|
1048 | + $c->getSecureRandom(), |
|
1049 | + $c->getHasher(), |
|
1050 | + $c->getMountManager(), |
|
1051 | + $c->getGroupManager(), |
|
1052 | + $c->getL10N('lib'), |
|
1053 | + $c->getL10NFactory(), |
|
1054 | + $factory, |
|
1055 | + $c->getUserManager(), |
|
1056 | + $c->getLazyRootFolder(), |
|
1057 | + $c->getEventDispatcher(), |
|
1058 | + $c->getMailer(), |
|
1059 | + $c->getURLGenerator(), |
|
1060 | + $c->getThemingDefaults() |
|
1061 | + ); |
|
1062 | + |
|
1063 | + return $manager; |
|
1064 | + }); |
|
1065 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1066 | + |
|
1067 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1068 | + $instance = new Collaboration\Collaborators\Search($c); |
|
1069 | + |
|
1070 | + // register default plugins |
|
1071 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1072 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1073 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1074 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1075 | + |
|
1076 | + return $instance; |
|
1077 | + }); |
|
1078 | + $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1079 | + |
|
1080 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1081 | + |
|
1082 | + $this->registerService('SettingsManager', function (Server $c) { |
|
1083 | + $manager = new \OC\Settings\Manager( |
|
1084 | + $c->getLogger(), |
|
1085 | + $c->getDatabaseConnection(), |
|
1086 | + $c->getL10N('lib'), |
|
1087 | + $c->getConfig(), |
|
1088 | + $c->getEncryptionManager(), |
|
1089 | + $c->getUserManager(), |
|
1090 | + $c->getLockingProvider(), |
|
1091 | + $c->getRequest(), |
|
1092 | + $c->getURLGenerator(), |
|
1093 | + $c->query(AccountManager::class), |
|
1094 | + $c->getGroupManager(), |
|
1095 | + $c->getL10NFactory(), |
|
1096 | + $c->getAppManager() |
|
1097 | + ); |
|
1098 | + return $manager; |
|
1099 | + }); |
|
1100 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1101 | + return new \OC\Files\AppData\Factory( |
|
1102 | + $c->getRootFolder(), |
|
1103 | + $c->getSystemConfig() |
|
1104 | + ); |
|
1105 | + }); |
|
1106 | + |
|
1107 | + $this->registerService('LockdownManager', function (Server $c) { |
|
1108 | + return new LockdownManager(function () use ($c) { |
|
1109 | + return $c->getSession(); |
|
1110 | + }); |
|
1111 | + }); |
|
1112 | + |
|
1113 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1114 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1115 | + }); |
|
1116 | + |
|
1117 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1118 | + return new CloudIdManager(); |
|
1119 | + }); |
|
1120 | + |
|
1121 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1122 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1123 | + |
|
1124 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1125 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1126 | + |
|
1127 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1128 | + return new Defaults( |
|
1129 | + $c->getThemingDefaults() |
|
1130 | + ); |
|
1131 | + }); |
|
1132 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1133 | + |
|
1134 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1135 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1136 | + }); |
|
1137 | + |
|
1138 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
1139 | + return new ShareHelper( |
|
1140 | + $c->query(\OCP\Share\IManager::class) |
|
1141 | + ); |
|
1142 | + }); |
|
1143 | + |
|
1144 | + $this->registerService(Installer::class, function(Server $c) { |
|
1145 | + return new Installer( |
|
1146 | + $c->getAppFetcher(), |
|
1147 | + $c->getHTTPClientService(), |
|
1148 | + $c->getTempManager(), |
|
1149 | + $c->getLogger(), |
|
1150 | + $c->getConfig() |
|
1151 | + ); |
|
1152 | + }); |
|
1153 | + |
|
1154 | + $this->registerService(IApiFactory::class, function(Server $c) { |
|
1155 | + return new ApiFactory($c->getHTTPClientService()); |
|
1156 | + }); |
|
1157 | + |
|
1158 | + $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1159 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
1160 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1161 | + }); |
|
1162 | + |
|
1163 | + $this->registerService(IContactsStore::class, function(Server $c) { |
|
1164 | + return new ContactsStore( |
|
1165 | + $c->getContactsManager(), |
|
1166 | + $c->getConfig(), |
|
1167 | + $c->getUserManager(), |
|
1168 | + $c->getGroupManager() |
|
1169 | + ); |
|
1170 | + }); |
|
1171 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1172 | + |
|
1173 | + $this->connectDispatcher(); |
|
1174 | + } |
|
1175 | + |
|
1176 | + /** |
|
1177 | + * @return \OCP\Calendar\IManager |
|
1178 | + */ |
|
1179 | + public function getCalendarManager() { |
|
1180 | + return $this->query('CalendarManager'); |
|
1181 | + } |
|
1182 | + |
|
1183 | + private function connectDispatcher() { |
|
1184 | + $dispatcher = $this->getEventDispatcher(); |
|
1185 | + |
|
1186 | + // Delete avatar on user deletion |
|
1187 | + $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1188 | + $logger = $this->getLogger(); |
|
1189 | + $manager = $this->getAvatarManager(); |
|
1190 | + /** @var IUser $user */ |
|
1191 | + $user = $e->getSubject(); |
|
1192 | + |
|
1193 | + try { |
|
1194 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1195 | + $avatar->remove(); |
|
1196 | + } catch (NotFoundException $e) { |
|
1197 | + // no avatar to remove |
|
1198 | + } catch (\Exception $e) { |
|
1199 | + // Ignore exceptions |
|
1200 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1201 | + } |
|
1202 | + }); |
|
1203 | + |
|
1204 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1205 | + $manager = $this->getAvatarManager(); |
|
1206 | + /** @var IUser $user */ |
|
1207 | + $user = $e->getSubject(); |
|
1208 | + $feature = $e->getArgument('feature'); |
|
1209 | + $oldValue = $e->getArgument('oldValue'); |
|
1210 | + $value = $e->getArgument('value'); |
|
1211 | + |
|
1212 | + try { |
|
1213 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1214 | + $avatar->userChanged($feature, $oldValue, $value); |
|
1215 | + } catch (NotFoundException $e) { |
|
1216 | + // no avatar to remove |
|
1217 | + } |
|
1218 | + }); |
|
1219 | + } |
|
1220 | + |
|
1221 | + /** |
|
1222 | + * @return \OCP\Contacts\IManager |
|
1223 | + */ |
|
1224 | + public function getContactsManager() { |
|
1225 | + return $this->query('ContactsManager'); |
|
1226 | + } |
|
1227 | + |
|
1228 | + /** |
|
1229 | + * @return \OC\Encryption\Manager |
|
1230 | + */ |
|
1231 | + public function getEncryptionManager() { |
|
1232 | + return $this->query('EncryptionManager'); |
|
1233 | + } |
|
1234 | + |
|
1235 | + /** |
|
1236 | + * @return \OC\Encryption\File |
|
1237 | + */ |
|
1238 | + public function getEncryptionFilesHelper() { |
|
1239 | + return $this->query('EncryptionFileHelper'); |
|
1240 | + } |
|
1241 | + |
|
1242 | + /** |
|
1243 | + * @return \OCP\Encryption\Keys\IStorage |
|
1244 | + */ |
|
1245 | + public function getEncryptionKeyStorage() { |
|
1246 | + return $this->query('EncryptionKeyStorage'); |
|
1247 | + } |
|
1248 | + |
|
1249 | + /** |
|
1250 | + * The current request object holding all information about the request |
|
1251 | + * currently being processed is returned from this method. |
|
1252 | + * In case the current execution was not initiated by a web request null is returned |
|
1253 | + * |
|
1254 | + * @return \OCP\IRequest |
|
1255 | + */ |
|
1256 | + public function getRequest() { |
|
1257 | + return $this->query('Request'); |
|
1258 | + } |
|
1259 | + |
|
1260 | + /** |
|
1261 | + * Returns the preview manager which can create preview images for a given file |
|
1262 | + * |
|
1263 | + * @return \OCP\IPreview |
|
1264 | + */ |
|
1265 | + public function getPreviewManager() { |
|
1266 | + return $this->query('PreviewManager'); |
|
1267 | + } |
|
1268 | + |
|
1269 | + /** |
|
1270 | + * Returns the tag manager which can get and set tags for different object types |
|
1271 | + * |
|
1272 | + * @see \OCP\ITagManager::load() |
|
1273 | + * @return \OCP\ITagManager |
|
1274 | + */ |
|
1275 | + public function getTagManager() { |
|
1276 | + return $this->query('TagManager'); |
|
1277 | + } |
|
1278 | + |
|
1279 | + /** |
|
1280 | + * Returns the system-tag manager |
|
1281 | + * |
|
1282 | + * @return \OCP\SystemTag\ISystemTagManager |
|
1283 | + * |
|
1284 | + * @since 9.0.0 |
|
1285 | + */ |
|
1286 | + public function getSystemTagManager() { |
|
1287 | + return $this->query('SystemTagManager'); |
|
1288 | + } |
|
1289 | + |
|
1290 | + /** |
|
1291 | + * Returns the system-tag object mapper |
|
1292 | + * |
|
1293 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1294 | + * |
|
1295 | + * @since 9.0.0 |
|
1296 | + */ |
|
1297 | + public function getSystemTagObjectMapper() { |
|
1298 | + return $this->query('SystemTagObjectMapper'); |
|
1299 | + } |
|
1300 | + |
|
1301 | + /** |
|
1302 | + * Returns the avatar manager, used for avatar functionality |
|
1303 | + * |
|
1304 | + * @return \OCP\IAvatarManager |
|
1305 | + */ |
|
1306 | + public function getAvatarManager() { |
|
1307 | + return $this->query('AvatarManager'); |
|
1308 | + } |
|
1309 | + |
|
1310 | + /** |
|
1311 | + * Returns the root folder of ownCloud's data directory |
|
1312 | + * |
|
1313 | + * @return \OCP\Files\IRootFolder |
|
1314 | + */ |
|
1315 | + public function getRootFolder() { |
|
1316 | + return $this->query('LazyRootFolder'); |
|
1317 | + } |
|
1318 | + |
|
1319 | + /** |
|
1320 | + * Returns the root folder of ownCloud's data directory |
|
1321 | + * This is the lazy variant so this gets only initialized once it |
|
1322 | + * is actually used. |
|
1323 | + * |
|
1324 | + * @return \OCP\Files\IRootFolder |
|
1325 | + */ |
|
1326 | + public function getLazyRootFolder() { |
|
1327 | + return $this->query('LazyRootFolder'); |
|
1328 | + } |
|
1329 | + |
|
1330 | + /** |
|
1331 | + * Returns a view to ownCloud's files folder |
|
1332 | + * |
|
1333 | + * @param string $userId user ID |
|
1334 | + * @return \OCP\Files\Folder|null |
|
1335 | + */ |
|
1336 | + public function getUserFolder($userId = null) { |
|
1337 | + if ($userId === null) { |
|
1338 | + $user = $this->getUserSession()->getUser(); |
|
1339 | + if (!$user) { |
|
1340 | + return null; |
|
1341 | + } |
|
1342 | + $userId = $user->getUID(); |
|
1343 | + } |
|
1344 | + $root = $this->getRootFolder(); |
|
1345 | + return $root->getUserFolder($userId); |
|
1346 | + } |
|
1347 | + |
|
1348 | + /** |
|
1349 | + * Returns an app-specific view in ownClouds data directory |
|
1350 | + * |
|
1351 | + * @return \OCP\Files\Folder |
|
1352 | + * @deprecated since 9.2.0 use IAppData |
|
1353 | + */ |
|
1354 | + public function getAppFolder() { |
|
1355 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
1356 | + $root = $this->getRootFolder(); |
|
1357 | + if (!$root->nodeExists($dir)) { |
|
1358 | + $folder = $root->newFolder($dir); |
|
1359 | + } else { |
|
1360 | + $folder = $root->get($dir); |
|
1361 | + } |
|
1362 | + return $folder; |
|
1363 | + } |
|
1364 | + |
|
1365 | + /** |
|
1366 | + * @return \OC\User\Manager |
|
1367 | + */ |
|
1368 | + public function getUserManager() { |
|
1369 | + return $this->query('UserManager'); |
|
1370 | + } |
|
1371 | + |
|
1372 | + /** |
|
1373 | + * @return \OC\Group\Manager |
|
1374 | + */ |
|
1375 | + public function getGroupManager() { |
|
1376 | + return $this->query('GroupManager'); |
|
1377 | + } |
|
1378 | + |
|
1379 | + /** |
|
1380 | + * @return \OC\User\Session |
|
1381 | + */ |
|
1382 | + public function getUserSession() { |
|
1383 | + return $this->query('UserSession'); |
|
1384 | + } |
|
1385 | + |
|
1386 | + /** |
|
1387 | + * @return \OCP\ISession |
|
1388 | + */ |
|
1389 | + public function getSession() { |
|
1390 | + return $this->query('UserSession')->getSession(); |
|
1391 | + } |
|
1392 | + |
|
1393 | + /** |
|
1394 | + * @param \OCP\ISession $session |
|
1395 | + */ |
|
1396 | + public function setSession(\OCP\ISession $session) { |
|
1397 | + $this->query(SessionStorage::class)->setSession($session); |
|
1398 | + $this->query('UserSession')->setSession($session); |
|
1399 | + $this->query(Store::class)->setSession($session); |
|
1400 | + } |
|
1401 | + |
|
1402 | + /** |
|
1403 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1404 | + */ |
|
1405 | + public function getTwoFactorAuthManager() { |
|
1406 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1407 | + } |
|
1408 | + |
|
1409 | + /** |
|
1410 | + * @return \OC\NavigationManager |
|
1411 | + */ |
|
1412 | + public function getNavigationManager() { |
|
1413 | + return $this->query('NavigationManager'); |
|
1414 | + } |
|
1415 | + |
|
1416 | + /** |
|
1417 | + * @return \OCP\IConfig |
|
1418 | + */ |
|
1419 | + public function getConfig() { |
|
1420 | + return $this->query('AllConfig'); |
|
1421 | + } |
|
1422 | + |
|
1423 | + /** |
|
1424 | + * @return \OC\SystemConfig |
|
1425 | + */ |
|
1426 | + public function getSystemConfig() { |
|
1427 | + return $this->query('SystemConfig'); |
|
1428 | + } |
|
1429 | + |
|
1430 | + /** |
|
1431 | + * Returns the app config manager |
|
1432 | + * |
|
1433 | + * @return \OCP\IAppConfig |
|
1434 | + */ |
|
1435 | + public function getAppConfig() { |
|
1436 | + return $this->query('AppConfig'); |
|
1437 | + } |
|
1438 | + |
|
1439 | + /** |
|
1440 | + * @return \OCP\L10N\IFactory |
|
1441 | + */ |
|
1442 | + public function getL10NFactory() { |
|
1443 | + return $this->query('L10NFactory'); |
|
1444 | + } |
|
1445 | + |
|
1446 | + /** |
|
1447 | + * get an L10N instance |
|
1448 | + * |
|
1449 | + * @param string $app appid |
|
1450 | + * @param string $lang |
|
1451 | + * @return IL10N |
|
1452 | + */ |
|
1453 | + public function getL10N($app, $lang = null) { |
|
1454 | + return $this->getL10NFactory()->get($app, $lang); |
|
1455 | + } |
|
1456 | + |
|
1457 | + /** |
|
1458 | + * @return \OCP\IURLGenerator |
|
1459 | + */ |
|
1460 | + public function getURLGenerator() { |
|
1461 | + return $this->query('URLGenerator'); |
|
1462 | + } |
|
1463 | + |
|
1464 | + /** |
|
1465 | + * @return AppFetcher |
|
1466 | + */ |
|
1467 | + public function getAppFetcher() { |
|
1468 | + return $this->query(AppFetcher::class); |
|
1469 | + } |
|
1470 | + |
|
1471 | + /** |
|
1472 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1473 | + * getMemCacheFactory() instead. |
|
1474 | + * |
|
1475 | + * @return \OCP\ICache |
|
1476 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1477 | + */ |
|
1478 | + public function getCache() { |
|
1479 | + return $this->query('UserCache'); |
|
1480 | + } |
|
1481 | + |
|
1482 | + /** |
|
1483 | + * Returns an \OCP\CacheFactory instance |
|
1484 | + * |
|
1485 | + * @return \OCP\ICacheFactory |
|
1486 | + */ |
|
1487 | + public function getMemCacheFactory() { |
|
1488 | + return $this->query('MemCacheFactory'); |
|
1489 | + } |
|
1490 | + |
|
1491 | + /** |
|
1492 | + * Returns an \OC\RedisFactory instance |
|
1493 | + * |
|
1494 | + * @return \OC\RedisFactory |
|
1495 | + */ |
|
1496 | + public function getGetRedisFactory() { |
|
1497 | + return $this->query('RedisFactory'); |
|
1498 | + } |
|
1499 | + |
|
1500 | + |
|
1501 | + /** |
|
1502 | + * Returns the current session |
|
1503 | + * |
|
1504 | + * @return \OCP\IDBConnection |
|
1505 | + */ |
|
1506 | + public function getDatabaseConnection() { |
|
1507 | + return $this->query('DatabaseConnection'); |
|
1508 | + } |
|
1509 | + |
|
1510 | + /** |
|
1511 | + * Returns the activity manager |
|
1512 | + * |
|
1513 | + * @return \OCP\Activity\IManager |
|
1514 | + */ |
|
1515 | + public function getActivityManager() { |
|
1516 | + return $this->query('ActivityManager'); |
|
1517 | + } |
|
1518 | + |
|
1519 | + /** |
|
1520 | + * Returns an job list for controlling background jobs |
|
1521 | + * |
|
1522 | + * @return \OCP\BackgroundJob\IJobList |
|
1523 | + */ |
|
1524 | + public function getJobList() { |
|
1525 | + return $this->query('JobList'); |
|
1526 | + } |
|
1527 | + |
|
1528 | + /** |
|
1529 | + * Returns a logger instance |
|
1530 | + * |
|
1531 | + * @return \OCP\ILogger |
|
1532 | + */ |
|
1533 | + public function getLogger() { |
|
1534 | + return $this->query('Logger'); |
|
1535 | + } |
|
1536 | + |
|
1537 | + /** |
|
1538 | + * @return ILogFactory |
|
1539 | + * @throws \OCP\AppFramework\QueryException |
|
1540 | + */ |
|
1541 | + public function getLogFactory() { |
|
1542 | + return $this->query('LogFactory'); |
|
1543 | + } |
|
1544 | + |
|
1545 | + /** |
|
1546 | + * Returns a router for generating and matching urls |
|
1547 | + * |
|
1548 | + * @return \OCP\Route\IRouter |
|
1549 | + */ |
|
1550 | + public function getRouter() { |
|
1551 | + return $this->query('Router'); |
|
1552 | + } |
|
1553 | + |
|
1554 | + /** |
|
1555 | + * Returns a search instance |
|
1556 | + * |
|
1557 | + * @return \OCP\ISearch |
|
1558 | + */ |
|
1559 | + public function getSearch() { |
|
1560 | + return $this->query('Search'); |
|
1561 | + } |
|
1562 | + |
|
1563 | + /** |
|
1564 | + * Returns a SecureRandom instance |
|
1565 | + * |
|
1566 | + * @return \OCP\Security\ISecureRandom |
|
1567 | + */ |
|
1568 | + public function getSecureRandom() { |
|
1569 | + return $this->query('SecureRandom'); |
|
1570 | + } |
|
1571 | + |
|
1572 | + /** |
|
1573 | + * Returns a Crypto instance |
|
1574 | + * |
|
1575 | + * @return \OCP\Security\ICrypto |
|
1576 | + */ |
|
1577 | + public function getCrypto() { |
|
1578 | + return $this->query('Crypto'); |
|
1579 | + } |
|
1580 | + |
|
1581 | + /** |
|
1582 | + * Returns a Hasher instance |
|
1583 | + * |
|
1584 | + * @return \OCP\Security\IHasher |
|
1585 | + */ |
|
1586 | + public function getHasher() { |
|
1587 | + return $this->query('Hasher'); |
|
1588 | + } |
|
1589 | + |
|
1590 | + /** |
|
1591 | + * Returns a CredentialsManager instance |
|
1592 | + * |
|
1593 | + * @return \OCP\Security\ICredentialsManager |
|
1594 | + */ |
|
1595 | + public function getCredentialsManager() { |
|
1596 | + return $this->query('CredentialsManager'); |
|
1597 | + } |
|
1598 | + |
|
1599 | + /** |
|
1600 | + * Get the certificate manager for the user |
|
1601 | + * |
|
1602 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1603 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1604 | + */ |
|
1605 | + public function getCertificateManager($userId = '') { |
|
1606 | + if ($userId === '') { |
|
1607 | + $userSession = $this->getUserSession(); |
|
1608 | + $user = $userSession->getUser(); |
|
1609 | + if (is_null($user)) { |
|
1610 | + return null; |
|
1611 | + } |
|
1612 | + $userId = $user->getUID(); |
|
1613 | + } |
|
1614 | + return new CertificateManager( |
|
1615 | + $userId, |
|
1616 | + new View(), |
|
1617 | + $this->getConfig(), |
|
1618 | + $this->getLogger(), |
|
1619 | + $this->getSecureRandom() |
|
1620 | + ); |
|
1621 | + } |
|
1622 | + |
|
1623 | + /** |
|
1624 | + * Returns an instance of the HTTP client service |
|
1625 | + * |
|
1626 | + * @return \OCP\Http\Client\IClientService |
|
1627 | + */ |
|
1628 | + public function getHTTPClientService() { |
|
1629 | + return $this->query('HttpClientService'); |
|
1630 | + } |
|
1631 | + |
|
1632 | + /** |
|
1633 | + * Create a new event source |
|
1634 | + * |
|
1635 | + * @return \OCP\IEventSource |
|
1636 | + */ |
|
1637 | + public function createEventSource() { |
|
1638 | + return new \OC_EventSource(); |
|
1639 | + } |
|
1640 | + |
|
1641 | + /** |
|
1642 | + * Get the active event logger |
|
1643 | + * |
|
1644 | + * The returned logger only logs data when debug mode is enabled |
|
1645 | + * |
|
1646 | + * @return \OCP\Diagnostics\IEventLogger |
|
1647 | + */ |
|
1648 | + public function getEventLogger() { |
|
1649 | + return $this->query('EventLogger'); |
|
1650 | + } |
|
1651 | + |
|
1652 | + /** |
|
1653 | + * Get the active query logger |
|
1654 | + * |
|
1655 | + * The returned logger only logs data when debug mode is enabled |
|
1656 | + * |
|
1657 | + * @return \OCP\Diagnostics\IQueryLogger |
|
1658 | + */ |
|
1659 | + public function getQueryLogger() { |
|
1660 | + return $this->query('QueryLogger'); |
|
1661 | + } |
|
1662 | + |
|
1663 | + /** |
|
1664 | + * Get the manager for temporary files and folders |
|
1665 | + * |
|
1666 | + * @return \OCP\ITempManager |
|
1667 | + */ |
|
1668 | + public function getTempManager() { |
|
1669 | + return $this->query('TempManager'); |
|
1670 | + } |
|
1671 | + |
|
1672 | + /** |
|
1673 | + * Get the app manager |
|
1674 | + * |
|
1675 | + * @return \OCP\App\IAppManager |
|
1676 | + */ |
|
1677 | + public function getAppManager() { |
|
1678 | + return $this->query('AppManager'); |
|
1679 | + } |
|
1680 | + |
|
1681 | + /** |
|
1682 | + * Creates a new mailer |
|
1683 | + * |
|
1684 | + * @return \OCP\Mail\IMailer |
|
1685 | + */ |
|
1686 | + public function getMailer() { |
|
1687 | + return $this->query('Mailer'); |
|
1688 | + } |
|
1689 | + |
|
1690 | + /** |
|
1691 | + * Get the webroot |
|
1692 | + * |
|
1693 | + * @return string |
|
1694 | + */ |
|
1695 | + public function getWebRoot() { |
|
1696 | + return $this->webRoot; |
|
1697 | + } |
|
1698 | + |
|
1699 | + /** |
|
1700 | + * @return \OC\OCSClient |
|
1701 | + */ |
|
1702 | + public function getOcsClient() { |
|
1703 | + return $this->query('OcsClient'); |
|
1704 | + } |
|
1705 | + |
|
1706 | + /** |
|
1707 | + * @return \OCP\IDateTimeZone |
|
1708 | + */ |
|
1709 | + public function getDateTimeZone() { |
|
1710 | + return $this->query('DateTimeZone'); |
|
1711 | + } |
|
1712 | + |
|
1713 | + /** |
|
1714 | + * @return \OCP\IDateTimeFormatter |
|
1715 | + */ |
|
1716 | + public function getDateTimeFormatter() { |
|
1717 | + return $this->query('DateTimeFormatter'); |
|
1718 | + } |
|
1719 | + |
|
1720 | + /** |
|
1721 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
1722 | + */ |
|
1723 | + public function getMountProviderCollection() { |
|
1724 | + return $this->query('MountConfigManager'); |
|
1725 | + } |
|
1726 | + |
|
1727 | + /** |
|
1728 | + * Get the IniWrapper |
|
1729 | + * |
|
1730 | + * @return IniGetWrapper |
|
1731 | + */ |
|
1732 | + public function getIniWrapper() { |
|
1733 | + return $this->query('IniWrapper'); |
|
1734 | + } |
|
1735 | + |
|
1736 | + /** |
|
1737 | + * @return \OCP\Command\IBus |
|
1738 | + */ |
|
1739 | + public function getCommandBus() { |
|
1740 | + return $this->query('AsyncCommandBus'); |
|
1741 | + } |
|
1742 | + |
|
1743 | + /** |
|
1744 | + * Get the trusted domain helper |
|
1745 | + * |
|
1746 | + * @return TrustedDomainHelper |
|
1747 | + */ |
|
1748 | + public function getTrustedDomainHelper() { |
|
1749 | + return $this->query('TrustedDomainHelper'); |
|
1750 | + } |
|
1751 | + |
|
1752 | + /** |
|
1753 | + * Get the locking provider |
|
1754 | + * |
|
1755 | + * @return \OCP\Lock\ILockingProvider |
|
1756 | + * @since 8.1.0 |
|
1757 | + */ |
|
1758 | + public function getLockingProvider() { |
|
1759 | + return $this->query('LockingProvider'); |
|
1760 | + } |
|
1761 | + |
|
1762 | + /** |
|
1763 | + * @return \OCP\Files\Mount\IMountManager |
|
1764 | + **/ |
|
1765 | + function getMountManager() { |
|
1766 | + return $this->query('MountManager'); |
|
1767 | + } |
|
1768 | + |
|
1769 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
1770 | + function getUserMountCache() { |
|
1771 | + return $this->query('UserMountCache'); |
|
1772 | + } |
|
1773 | + |
|
1774 | + /** |
|
1775 | + * Get the MimeTypeDetector |
|
1776 | + * |
|
1777 | + * @return \OCP\Files\IMimeTypeDetector |
|
1778 | + */ |
|
1779 | + public function getMimeTypeDetector() { |
|
1780 | + return $this->query('MimeTypeDetector'); |
|
1781 | + } |
|
1782 | + |
|
1783 | + /** |
|
1784 | + * Get the MimeTypeLoader |
|
1785 | + * |
|
1786 | + * @return \OCP\Files\IMimeTypeLoader |
|
1787 | + */ |
|
1788 | + public function getMimeTypeLoader() { |
|
1789 | + return $this->query('MimeTypeLoader'); |
|
1790 | + } |
|
1791 | + |
|
1792 | + /** |
|
1793 | + * Get the manager of all the capabilities |
|
1794 | + * |
|
1795 | + * @return \OC\CapabilitiesManager |
|
1796 | + */ |
|
1797 | + public function getCapabilitiesManager() { |
|
1798 | + return $this->query('CapabilitiesManager'); |
|
1799 | + } |
|
1800 | + |
|
1801 | + /** |
|
1802 | + * Get the EventDispatcher |
|
1803 | + * |
|
1804 | + * @return EventDispatcherInterface |
|
1805 | + * @since 8.2.0 |
|
1806 | + */ |
|
1807 | + public function getEventDispatcher() { |
|
1808 | + return $this->query('EventDispatcher'); |
|
1809 | + } |
|
1810 | + |
|
1811 | + /** |
|
1812 | + * Get the Notification Manager |
|
1813 | + * |
|
1814 | + * @return \OCP\Notification\IManager |
|
1815 | + * @since 8.2.0 |
|
1816 | + */ |
|
1817 | + public function getNotificationManager() { |
|
1818 | + return $this->query('NotificationManager'); |
|
1819 | + } |
|
1820 | + |
|
1821 | + /** |
|
1822 | + * @return \OCP\Comments\ICommentsManager |
|
1823 | + */ |
|
1824 | + public function getCommentsManager() { |
|
1825 | + return $this->query('CommentsManager'); |
|
1826 | + } |
|
1827 | + |
|
1828 | + /** |
|
1829 | + * @return \OCA\Theming\ThemingDefaults |
|
1830 | + */ |
|
1831 | + public function getThemingDefaults() { |
|
1832 | + return $this->query('ThemingDefaults'); |
|
1833 | + } |
|
1834 | + |
|
1835 | + /** |
|
1836 | + * @return \OC\IntegrityCheck\Checker |
|
1837 | + */ |
|
1838 | + public function getIntegrityCodeChecker() { |
|
1839 | + return $this->query('IntegrityCodeChecker'); |
|
1840 | + } |
|
1841 | + |
|
1842 | + /** |
|
1843 | + * @return \OC\Session\CryptoWrapper |
|
1844 | + */ |
|
1845 | + public function getSessionCryptoWrapper() { |
|
1846 | + return $this->query('CryptoWrapper'); |
|
1847 | + } |
|
1848 | + |
|
1849 | + /** |
|
1850 | + * @return CsrfTokenManager |
|
1851 | + */ |
|
1852 | + public function getCsrfTokenManager() { |
|
1853 | + return $this->query('CsrfTokenManager'); |
|
1854 | + } |
|
1855 | + |
|
1856 | + /** |
|
1857 | + * @return Throttler |
|
1858 | + */ |
|
1859 | + public function getBruteForceThrottler() { |
|
1860 | + return $this->query('Throttler'); |
|
1861 | + } |
|
1862 | + |
|
1863 | + /** |
|
1864 | + * @return IContentSecurityPolicyManager |
|
1865 | + */ |
|
1866 | + public function getContentSecurityPolicyManager() { |
|
1867 | + return $this->query('ContentSecurityPolicyManager'); |
|
1868 | + } |
|
1869 | + |
|
1870 | + /** |
|
1871 | + * @return ContentSecurityPolicyNonceManager |
|
1872 | + */ |
|
1873 | + public function getContentSecurityPolicyNonceManager() { |
|
1874 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
1875 | + } |
|
1876 | + |
|
1877 | + /** |
|
1878 | + * Not a public API as of 8.2, wait for 9.0 |
|
1879 | + * |
|
1880 | + * @return \OCA\Files_External\Service\BackendService |
|
1881 | + */ |
|
1882 | + public function getStoragesBackendService() { |
|
1883 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1884 | + } |
|
1885 | + |
|
1886 | + /** |
|
1887 | + * Not a public API as of 8.2, wait for 9.0 |
|
1888 | + * |
|
1889 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1890 | + */ |
|
1891 | + public function getGlobalStoragesService() { |
|
1892 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1893 | + } |
|
1894 | + |
|
1895 | + /** |
|
1896 | + * Not a public API as of 8.2, wait for 9.0 |
|
1897 | + * |
|
1898 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1899 | + */ |
|
1900 | + public function getUserGlobalStoragesService() { |
|
1901 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1902 | + } |
|
1903 | + |
|
1904 | + /** |
|
1905 | + * Not a public API as of 8.2, wait for 9.0 |
|
1906 | + * |
|
1907 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
1908 | + */ |
|
1909 | + public function getUserStoragesService() { |
|
1910 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1911 | + } |
|
1912 | + |
|
1913 | + /** |
|
1914 | + * @return \OCP\Share\IManager |
|
1915 | + */ |
|
1916 | + public function getShareManager() { |
|
1917 | + return $this->query('ShareManager'); |
|
1918 | + } |
|
1919 | + |
|
1920 | + /** |
|
1921 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
1922 | + */ |
|
1923 | + public function getCollaboratorSearch() { |
|
1924 | + return $this->query('CollaboratorSearch'); |
|
1925 | + } |
|
1926 | + |
|
1927 | + /** |
|
1928 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
1929 | + */ |
|
1930 | + public function getAutoCompleteManager(){ |
|
1931 | + return $this->query(IManager::class); |
|
1932 | + } |
|
1933 | + |
|
1934 | + /** |
|
1935 | + * Returns the LDAP Provider |
|
1936 | + * |
|
1937 | + * @return \OCP\LDAP\ILDAPProvider |
|
1938 | + */ |
|
1939 | + public function getLDAPProvider() { |
|
1940 | + return $this->query('LDAPProvider'); |
|
1941 | + } |
|
1942 | + |
|
1943 | + /** |
|
1944 | + * @return \OCP\Settings\IManager |
|
1945 | + */ |
|
1946 | + public function getSettingsManager() { |
|
1947 | + return $this->query('SettingsManager'); |
|
1948 | + } |
|
1949 | + |
|
1950 | + /** |
|
1951 | + * @return \OCP\Files\IAppData |
|
1952 | + */ |
|
1953 | + public function getAppDataDir($app) { |
|
1954 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
1955 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1956 | + return $factory->get($app); |
|
1957 | + } |
|
1958 | + |
|
1959 | + /** |
|
1960 | + * @return \OCP\Lockdown\ILockdownManager |
|
1961 | + */ |
|
1962 | + public function getLockdownManager() { |
|
1963 | + return $this->query('LockdownManager'); |
|
1964 | + } |
|
1965 | + |
|
1966 | + /** |
|
1967 | + * @return \OCP\Federation\ICloudIdManager |
|
1968 | + */ |
|
1969 | + public function getCloudIdManager() { |
|
1970 | + return $this->query(ICloudIdManager::class); |
|
1971 | + } |
|
1972 | + |
|
1973 | + /** |
|
1974 | + * @return \OCP\Remote\Api\IApiFactory |
|
1975 | + */ |
|
1976 | + public function getRemoteApiFactory() { |
|
1977 | + return $this->query(IApiFactory::class); |
|
1978 | + } |
|
1979 | + |
|
1980 | + /** |
|
1981 | + * @return \OCP\Remote\IInstanceFactory |
|
1982 | + */ |
|
1983 | + public function getRemoteInstanceFactory() { |
|
1984 | + return $this->query(IInstanceFactory::class); |
|
1985 | + } |
|
1986 | 1986 | } |
@@ -30,113 +30,113 @@ |
||
30 | 30 | use OCP\ILogger; |
31 | 31 | |
32 | 32 | class NaturalSort { |
33 | - private static $instance; |
|
34 | - private $collator; |
|
35 | - private $cache = array(); |
|
33 | + private static $instance; |
|
34 | + private $collator; |
|
35 | + private $cache = array(); |
|
36 | 36 | |
37 | - /** |
|
38 | - * Instantiate a new \OC\NaturalSort instance. |
|
39 | - * @param object $injectedCollator |
|
40 | - */ |
|
41 | - public function __construct($injectedCollator = null) { |
|
42 | - // inject an instance of \Collator('en_US') to force using the php5-intl Collator |
|
43 | - // or inject an instance of \OC\NaturalSort_DefaultCollator to force using Owncloud's default collator |
|
44 | - if (isset($injectedCollator)) { |
|
45 | - $this->collator = $injectedCollator; |
|
46 | - \OCP\Util::writeLog('core', 'forced use of '.get_class($injectedCollator), ILogger::DEBUG); |
|
47 | - } |
|
48 | - } |
|
37 | + /** |
|
38 | + * Instantiate a new \OC\NaturalSort instance. |
|
39 | + * @param object $injectedCollator |
|
40 | + */ |
|
41 | + public function __construct($injectedCollator = null) { |
|
42 | + // inject an instance of \Collator('en_US') to force using the php5-intl Collator |
|
43 | + // or inject an instance of \OC\NaturalSort_DefaultCollator to force using Owncloud's default collator |
|
44 | + if (isset($injectedCollator)) { |
|
45 | + $this->collator = $injectedCollator; |
|
46 | + \OCP\Util::writeLog('core', 'forced use of '.get_class($injectedCollator), ILogger::DEBUG); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Split the given string in chunks of numbers and strings |
|
52 | - * @param string $t string |
|
53 | - * @return array of strings and number chunks |
|
54 | - */ |
|
55 | - private function naturalSortChunkify($t) { |
|
56 | - // Adapted and ported to PHP from |
|
57 | - // http://my.opera.com/GreyWyvern/blog/show.dml/1671288 |
|
58 | - if (isset($this->cache[$t])) { |
|
59 | - return $this->cache[$t]; |
|
60 | - } |
|
61 | - $tz = array(); |
|
62 | - $x = 0; |
|
63 | - $y = -1; |
|
64 | - $n = null; |
|
50 | + /** |
|
51 | + * Split the given string in chunks of numbers and strings |
|
52 | + * @param string $t string |
|
53 | + * @return array of strings and number chunks |
|
54 | + */ |
|
55 | + private function naturalSortChunkify($t) { |
|
56 | + // Adapted and ported to PHP from |
|
57 | + // http://my.opera.com/GreyWyvern/blog/show.dml/1671288 |
|
58 | + if (isset($this->cache[$t])) { |
|
59 | + return $this->cache[$t]; |
|
60 | + } |
|
61 | + $tz = array(); |
|
62 | + $x = 0; |
|
63 | + $y = -1; |
|
64 | + $n = null; |
|
65 | 65 | |
66 | - while (isset($t[$x])) { |
|
67 | - $c = $t[$x]; |
|
68 | - // only include the dot in strings |
|
69 | - $m = ((!$n && $c === '.') || ($c >= '0' && $c <= '9')); |
|
70 | - if ($m !== $n) { |
|
71 | - // next chunk |
|
72 | - $y++; |
|
73 | - $tz[$y] = ''; |
|
74 | - $n = $m; |
|
75 | - } |
|
76 | - $tz[$y] .= $c; |
|
77 | - $x++; |
|
78 | - } |
|
79 | - $this->cache[$t] = $tz; |
|
80 | - return $tz; |
|
81 | - } |
|
66 | + while (isset($t[$x])) { |
|
67 | + $c = $t[$x]; |
|
68 | + // only include the dot in strings |
|
69 | + $m = ((!$n && $c === '.') || ($c >= '0' && $c <= '9')); |
|
70 | + if ($m !== $n) { |
|
71 | + // next chunk |
|
72 | + $y++; |
|
73 | + $tz[$y] = ''; |
|
74 | + $n = $m; |
|
75 | + } |
|
76 | + $tz[$y] .= $c; |
|
77 | + $x++; |
|
78 | + } |
|
79 | + $this->cache[$t] = $tz; |
|
80 | + return $tz; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Returns the string collator |
|
85 | - * @return \Collator string collator |
|
86 | - */ |
|
87 | - private function getCollator() { |
|
88 | - if (!isset($this->collator)) { |
|
89 | - // looks like the default is en_US_POSIX which yields wrong sorting with |
|
90 | - // German umlauts, so using en_US instead |
|
91 | - if (class_exists('Collator')) { |
|
92 | - $this->collator = new \Collator('en_US'); |
|
93 | - } |
|
94 | - else { |
|
95 | - $this->collator = new \OC\NaturalSort_DefaultCollator(); |
|
96 | - } |
|
97 | - } |
|
98 | - return $this->collator; |
|
99 | - } |
|
83 | + /** |
|
84 | + * Returns the string collator |
|
85 | + * @return \Collator string collator |
|
86 | + */ |
|
87 | + private function getCollator() { |
|
88 | + if (!isset($this->collator)) { |
|
89 | + // looks like the default is en_US_POSIX which yields wrong sorting with |
|
90 | + // German umlauts, so using en_US instead |
|
91 | + if (class_exists('Collator')) { |
|
92 | + $this->collator = new \Collator('en_US'); |
|
93 | + } |
|
94 | + else { |
|
95 | + $this->collator = new \OC\NaturalSort_DefaultCollator(); |
|
96 | + } |
|
97 | + } |
|
98 | + return $this->collator; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Compare two strings to provide a natural sort |
|
103 | - * @param string $a first string to compare |
|
104 | - * @param string $b second string to compare |
|
105 | - * @return int -1 if $b comes before $a, 1 if $a comes before $b |
|
106 | - * or 0 if the strings are identical |
|
107 | - */ |
|
108 | - public function compare($a, $b) { |
|
109 | - // Needed because PHP doesn't sort correctly when numbers are enclosed in |
|
110 | - // parenthesis, even with NUMERIC_COLLATION enabled. |
|
111 | - // For example it gave ["test (2).txt", "test.txt"] |
|
112 | - // instead of ["test.txt", "test (2).txt"] |
|
113 | - $aa = self::naturalSortChunkify($a); |
|
114 | - $bb = self::naturalSortChunkify($b); |
|
101 | + /** |
|
102 | + * Compare two strings to provide a natural sort |
|
103 | + * @param string $a first string to compare |
|
104 | + * @param string $b second string to compare |
|
105 | + * @return int -1 if $b comes before $a, 1 if $a comes before $b |
|
106 | + * or 0 if the strings are identical |
|
107 | + */ |
|
108 | + public function compare($a, $b) { |
|
109 | + // Needed because PHP doesn't sort correctly when numbers are enclosed in |
|
110 | + // parenthesis, even with NUMERIC_COLLATION enabled. |
|
111 | + // For example it gave ["test (2).txt", "test.txt"] |
|
112 | + // instead of ["test.txt", "test (2).txt"] |
|
113 | + $aa = self::naturalSortChunkify($a); |
|
114 | + $bb = self::naturalSortChunkify($b); |
|
115 | 115 | |
116 | - for ($x = 0; isset($aa[$x]) && isset($bb[$x]); $x++) { |
|
117 | - $aChunk = $aa[$x]; |
|
118 | - $bChunk = $bb[$x]; |
|
119 | - if ($aChunk !== $bChunk) { |
|
120 | - // test first character (character comparison, not number comparison) |
|
121 | - if ($aChunk[0] >= '0' && $aChunk[0] <= '9' && $bChunk[0] >= '0' && $bChunk[0] <= '9') { |
|
122 | - $aNum = (int)$aChunk; |
|
123 | - $bNum = (int)$bChunk; |
|
124 | - return $aNum - $bNum; |
|
125 | - } |
|
126 | - return self::getCollator()->compare($aChunk, $bChunk); |
|
127 | - } |
|
128 | - } |
|
129 | - return count($aa) - count($bb); |
|
130 | - } |
|
116 | + for ($x = 0; isset($aa[$x]) && isset($bb[$x]); $x++) { |
|
117 | + $aChunk = $aa[$x]; |
|
118 | + $bChunk = $bb[$x]; |
|
119 | + if ($aChunk !== $bChunk) { |
|
120 | + // test first character (character comparison, not number comparison) |
|
121 | + if ($aChunk[0] >= '0' && $aChunk[0] <= '9' && $bChunk[0] >= '0' && $bChunk[0] <= '9') { |
|
122 | + $aNum = (int)$aChunk; |
|
123 | + $bNum = (int)$bChunk; |
|
124 | + return $aNum - $bNum; |
|
125 | + } |
|
126 | + return self::getCollator()->compare($aChunk, $bChunk); |
|
127 | + } |
|
128 | + } |
|
129 | + return count($aa) - count($bb); |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Returns a singleton |
|
134 | - * @return \OC\NaturalSort instance |
|
135 | - */ |
|
136 | - public static function getInstance() { |
|
137 | - if (!isset(self::$instance)) { |
|
138 | - self::$instance = new \OC\NaturalSort(); |
|
139 | - } |
|
140 | - return self::$instance; |
|
141 | - } |
|
132 | + /** |
|
133 | + * Returns a singleton |
|
134 | + * @return \OC\NaturalSort instance |
|
135 | + */ |
|
136 | + public static function getInstance() { |
|
137 | + if (!isset(self::$instance)) { |
|
138 | + self::$instance = new \OC\NaturalSort(); |
|
139 | + } |
|
140 | + return self::$instance; |
|
141 | + } |
|
142 | 142 | } |
@@ -54,556 +54,556 @@ |
||
54 | 54 | */ |
55 | 55 | class Updater extends BasicEmitter { |
56 | 56 | |
57 | - /** @var ILogger $log */ |
|
58 | - private $log; |
|
59 | - |
|
60 | - /** @var IConfig */ |
|
61 | - private $config; |
|
62 | - |
|
63 | - /** @var Checker */ |
|
64 | - private $checker; |
|
65 | - |
|
66 | - /** @var Installer */ |
|
67 | - private $installer; |
|
68 | - |
|
69 | - private $logLevelNames = [ |
|
70 | - 0 => 'Debug', |
|
71 | - 1 => 'Info', |
|
72 | - 2 => 'Warning', |
|
73 | - 3 => 'Error', |
|
74 | - 4 => 'Fatal', |
|
75 | - ]; |
|
76 | - |
|
77 | - /** |
|
78 | - * @param IConfig $config |
|
79 | - * @param Checker $checker |
|
80 | - * @param ILogger $log |
|
81 | - * @param Installer $installer |
|
82 | - */ |
|
83 | - public function __construct(IConfig $config, |
|
84 | - Checker $checker, |
|
85 | - ILogger $log = null, |
|
86 | - Installer $installer) { |
|
87 | - $this->log = $log; |
|
88 | - $this->config = $config; |
|
89 | - $this->checker = $checker; |
|
90 | - $this->installer = $installer; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * runs the update actions in maintenance mode, does not upgrade the source files |
|
95 | - * except the main .htaccess file |
|
96 | - * |
|
97 | - * @return bool true if the operation succeeded, false otherwise |
|
98 | - */ |
|
99 | - public function upgrade() { |
|
100 | - $this->emitRepairEvents(); |
|
101 | - $this->logAllEvents(); |
|
102 | - |
|
103 | - $logLevel = $this->config->getSystemValue('loglevel', ILogger::WARN); |
|
104 | - $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
105 | - $this->config->setSystemValue('loglevel', ILogger::DEBUG); |
|
106 | - |
|
107 | - $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
108 | - |
|
109 | - if(!$wasMaintenanceModeEnabled) { |
|
110 | - $this->config->setSystemValue('maintenance', true); |
|
111 | - $this->emit('\OC\Updater', 'maintenanceEnabled'); |
|
112 | - } |
|
113 | - |
|
114 | - $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
115 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
116 | - $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core')); |
|
117 | - |
|
118 | - $success = true; |
|
119 | - try { |
|
120 | - $this->doUpgrade($currentVersion, $installedVersion); |
|
121 | - } catch (HintException $exception) { |
|
122 | - $this->log->logException($exception, ['app' => 'core']); |
|
123 | - $this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint())); |
|
124 | - $success = false; |
|
125 | - } catch (\Exception $exception) { |
|
126 | - $this->log->logException($exception, ['app' => 'core']); |
|
127 | - $this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage())); |
|
128 | - $success = false; |
|
129 | - } |
|
130 | - |
|
131 | - $this->emit('\OC\Updater', 'updateEnd', array($success)); |
|
132 | - |
|
133 | - if(!$wasMaintenanceModeEnabled && $success) { |
|
134 | - $this->config->setSystemValue('maintenance', false); |
|
135 | - $this->emit('\OC\Updater', 'maintenanceDisabled'); |
|
136 | - } else { |
|
137 | - $this->emit('\OC\Updater', 'maintenanceActive'); |
|
138 | - } |
|
139 | - |
|
140 | - $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
141 | - $this->config->setSystemValue('loglevel', $logLevel); |
|
142 | - $this->config->setSystemValue('installed', true); |
|
143 | - |
|
144 | - return $success; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Return version from which this version is allowed to upgrade from |
|
149 | - * |
|
150 | - * @return array allowed previous versions per vendor |
|
151 | - */ |
|
152 | - private function getAllowedPreviousVersions() { |
|
153 | - // this should really be a JSON file |
|
154 | - require \OC::$SERVERROOT . '/version.php'; |
|
155 | - /** @var array $OC_VersionCanBeUpgradedFrom */ |
|
156 | - return $OC_VersionCanBeUpgradedFrom; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Return vendor from which this version was published |
|
161 | - * |
|
162 | - * @return string Get the vendor |
|
163 | - */ |
|
164 | - private function getVendor() { |
|
165 | - // this should really be a JSON file |
|
166 | - require \OC::$SERVERROOT . '/version.php'; |
|
167 | - /** @var string $vendor */ |
|
168 | - return (string) $vendor; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Whether an upgrade to a specified version is possible |
|
173 | - * @param string $oldVersion |
|
174 | - * @param string $newVersion |
|
175 | - * @param array $allowedPreviousVersions |
|
176 | - * @return bool |
|
177 | - */ |
|
178 | - public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) { |
|
179 | - $version = explode('.', $oldVersion); |
|
180 | - $majorMinor = $version[0] . '.' . $version[1]; |
|
181 | - |
|
182 | - $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
|
183 | - |
|
184 | - // Vendor was not set correctly on install, so we have to white-list known versions |
|
185 | - if ($currentVendor === '' && isset($allowedPreviousVersions['owncloud'][$oldVersion])) { |
|
186 | - $currentVendor = 'owncloud'; |
|
187 | - } |
|
188 | - |
|
189 | - if ($currentVendor === 'nextcloud') { |
|
190 | - return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) |
|
191 | - && (version_compare($oldVersion, $newVersion, '<=') || |
|
192 | - $this->config->getSystemValue('debug', false)); |
|
193 | - } |
|
194 | - |
|
195 | - // Check if the instance can be migrated |
|
196 | - return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) || |
|
197 | - isset($allowedPreviousVersions[$currentVendor][$oldVersion]); |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * runs the update actions in maintenance mode, does not upgrade the source files |
|
202 | - * except the main .htaccess file |
|
203 | - * |
|
204 | - * @param string $currentVersion current version to upgrade to |
|
205 | - * @param string $installedVersion previous version from which to upgrade from |
|
206 | - * |
|
207 | - * @throws \Exception |
|
208 | - */ |
|
209 | - private function doUpgrade($currentVersion, $installedVersion) { |
|
210 | - // Stop update if the update is over several major versions |
|
211 | - $allowedPreviousVersions = $this->getAllowedPreviousVersions(); |
|
212 | - if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) { |
|
213 | - throw new \Exception('Updates between multiple major versions and downgrades are unsupported.'); |
|
214 | - } |
|
215 | - |
|
216 | - // Update .htaccess files |
|
217 | - try { |
|
218 | - Setup::updateHtaccess(); |
|
219 | - Setup::protectDataDirectory(); |
|
220 | - } catch (\Exception $e) { |
|
221 | - throw new \Exception($e->getMessage()); |
|
222 | - } |
|
223 | - |
|
224 | - // create empty file in data dir, so we can later find |
|
225 | - // out that this is indeed an ownCloud data directory |
|
226 | - // (in case it didn't exist before) |
|
227 | - file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
228 | - |
|
229 | - // pre-upgrade repairs |
|
230 | - $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher()); |
|
231 | - $repair->run(); |
|
232 | - |
|
233 | - $this->doCoreUpgrade(); |
|
234 | - |
|
235 | - try { |
|
236 | - // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 |
|
237 | - Setup::installBackgroundJobs(); |
|
238 | - } catch (\Exception $e) { |
|
239 | - throw new \Exception($e->getMessage()); |
|
240 | - } |
|
241 | - |
|
242 | - // update all shipped apps |
|
243 | - $this->checkAppsRequirements(); |
|
244 | - $this->doAppUpgrade(); |
|
245 | - |
|
246 | - // Update the appfetchers version so it downloads the correct list from the appstore |
|
247 | - \OC::$server->getAppFetcher()->setVersion($currentVersion); |
|
248 | - |
|
249 | - // upgrade appstore apps |
|
250 | - $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps()); |
|
251 | - |
|
252 | - // install new shipped apps on upgrade |
|
253 | - OC_App::loadApps(['authentication']); |
|
254 | - $errors = Installer::installShippedApps(true); |
|
255 | - foreach ($errors as $appId => $exception) { |
|
256 | - /** @var \Exception $exception */ |
|
257 | - $this->log->logException($exception, ['app' => $appId]); |
|
258 | - $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
259 | - } |
|
260 | - |
|
261 | - // post-upgrade repairs |
|
262 | - $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher()); |
|
263 | - $repair->run(); |
|
264 | - |
|
265 | - //Invalidate update feed |
|
266 | - $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
267 | - |
|
268 | - // Check for code integrity if not disabled |
|
269 | - if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
270 | - $this->emit('\OC\Updater', 'startCheckCodeIntegrity'); |
|
271 | - $this->checker->runInstanceVerification(); |
|
272 | - $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity'); |
|
273 | - } |
|
274 | - |
|
275 | - // only set the final version if everything went well |
|
276 | - $this->config->setSystemValue('version', implode('.', Util::getVersion())); |
|
277 | - $this->config->setAppValue('core', 'vendor', $this->getVendor()); |
|
278 | - } |
|
279 | - |
|
280 | - protected function doCoreUpgrade() { |
|
281 | - $this->emit('\OC\Updater', 'dbUpgradeBefore'); |
|
282 | - |
|
283 | - // execute core migrations |
|
284 | - $ms = new MigrationService('core', \OC::$server->getDatabaseConnection()); |
|
285 | - $ms->migrate(); |
|
286 | - |
|
287 | - $this->emit('\OC\Updater', 'dbUpgrade'); |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * @param string $version the oc version to check app compatibility with |
|
292 | - */ |
|
293 | - protected function checkAppUpgrade($version) { |
|
294 | - $apps = \OC_App::getEnabledApps(); |
|
295 | - $this->emit('\OC\Updater', 'appUpgradeCheckBefore'); |
|
296 | - |
|
297 | - $appManager = \OC::$server->getAppManager(); |
|
298 | - foreach ($apps as $appId) { |
|
299 | - $info = \OC_App::getAppInfo($appId); |
|
300 | - $compatible = \OC_App::isAppCompatible($version, $info); |
|
301 | - $isShipped = $appManager->isShipped($appId); |
|
302 | - |
|
303 | - if ($compatible && $isShipped && \OC_App::shouldUpgrade($appId)) { |
|
304 | - /** |
|
305 | - * FIXME: The preupdate check is performed before the database migration, otherwise database changes |
|
306 | - * are not possible anymore within it. - Consider this when touching the code. |
|
307 | - * @link https://github.com/owncloud/core/issues/10980 |
|
308 | - * @see \OC_App::updateApp |
|
309 | - */ |
|
310 | - if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) { |
|
311 | - $this->includePreUpdate($appId); |
|
312 | - } |
|
313 | - if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) { |
|
314 | - $this->emit('\OC\Updater', 'appSimulateUpdate', array($appId)); |
|
315 | - \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml'); |
|
316 | - } |
|
317 | - } |
|
318 | - } |
|
319 | - |
|
320 | - $this->emit('\OC\Updater', 'appUpgradeCheck'); |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Includes the pre-update file. Done here to prevent namespace mixups. |
|
325 | - * @param string $appId |
|
326 | - */ |
|
327 | - private function includePreUpdate($appId) { |
|
328 | - include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php'; |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * upgrades all apps within a major ownCloud upgrade. Also loads "priority" |
|
333 | - * (types authentication, filesystem, logging, in that order) afterwards. |
|
334 | - * |
|
335 | - * @throws NeedsUpdateException |
|
336 | - */ |
|
337 | - protected function doAppUpgrade() { |
|
338 | - $apps = \OC_App::getEnabledApps(); |
|
339 | - $priorityTypes = array('authentication', 'filesystem', 'logging'); |
|
340 | - $pseudoOtherType = 'other'; |
|
341 | - $stacks = array($pseudoOtherType => array()); |
|
342 | - |
|
343 | - foreach ($apps as $appId) { |
|
344 | - $priorityType = false; |
|
345 | - foreach ($priorityTypes as $type) { |
|
346 | - if(!isset($stacks[$type])) { |
|
347 | - $stacks[$type] = array(); |
|
348 | - } |
|
349 | - if (\OC_App::isType($appId, [$type])) { |
|
350 | - $stacks[$type][] = $appId; |
|
351 | - $priorityType = true; |
|
352 | - break; |
|
353 | - } |
|
354 | - } |
|
355 | - if (!$priorityType) { |
|
356 | - $stacks[$pseudoOtherType][] = $appId; |
|
357 | - } |
|
358 | - } |
|
359 | - foreach ($stacks as $type => $stack) { |
|
360 | - foreach ($stack as $appId) { |
|
361 | - if (\OC_App::shouldUpgrade($appId)) { |
|
362 | - $this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]); |
|
363 | - \OC_App::updateApp($appId); |
|
364 | - $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]); |
|
365 | - } |
|
366 | - if($type !== $pseudoOtherType) { |
|
367 | - // load authentication, filesystem and logging apps after |
|
368 | - // upgrading them. Other apps my need to rely on modifying |
|
369 | - // user and/or filesystem aspects. |
|
370 | - \OC_App::loadApp($appId); |
|
371 | - } |
|
372 | - } |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * check if the current enabled apps are compatible with the current |
|
378 | - * ownCloud version. disable them if not. |
|
379 | - * This is important if you upgrade ownCloud and have non ported 3rd |
|
380 | - * party apps installed. |
|
381 | - * |
|
382 | - * @return array |
|
383 | - * @throws \Exception |
|
384 | - */ |
|
385 | - private function checkAppsRequirements() { |
|
386 | - $isCoreUpgrade = $this->isCodeUpgrade(); |
|
387 | - $apps = OC_App::getEnabledApps(); |
|
388 | - $version = implode('.', Util::getVersion()); |
|
389 | - $disabledApps = []; |
|
390 | - $appManager = \OC::$server->getAppManager(); |
|
391 | - foreach ($apps as $app) { |
|
392 | - // check if the app is compatible with this version of ownCloud |
|
393 | - $info = OC_App::getAppInfo($app); |
|
394 | - if($info === null || !OC_App::isAppCompatible($version, $info)) { |
|
395 | - if ($appManager->isShipped($app)) { |
|
396 | - throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
397 | - } |
|
398 | - \OC::$server->getAppManager()->disableApp($app); |
|
399 | - $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app)); |
|
400 | - } |
|
401 | - // no need to disable any app in case this is a non-core upgrade |
|
402 | - if (!$isCoreUpgrade) { |
|
403 | - continue; |
|
404 | - } |
|
405 | - // shipped apps will remain enabled |
|
406 | - if ($appManager->isShipped($app)) { |
|
407 | - continue; |
|
408 | - } |
|
409 | - // authentication and session apps will remain enabled as well |
|
410 | - if (OC_App::isType($app, ['session', 'authentication'])) { |
|
411 | - continue; |
|
412 | - } |
|
413 | - } |
|
414 | - return $disabledApps; |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * @return bool |
|
419 | - */ |
|
420 | - private function isCodeUpgrade() { |
|
421 | - $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
422 | - $currentVersion = implode('.', Util::getVersion()); |
|
423 | - if (version_compare($currentVersion, $installedVersion, '>')) { |
|
424 | - return true; |
|
425 | - } |
|
426 | - return false; |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * @param array $disabledApps |
|
431 | - * @throws \Exception |
|
432 | - */ |
|
433 | - private function upgradeAppStoreApps(array $disabledApps) { |
|
434 | - foreach($disabledApps as $app) { |
|
435 | - try { |
|
436 | - $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]); |
|
437 | - if ($this->installer->isUpdateAvailable($app)) { |
|
438 | - $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]); |
|
439 | - $this->installer->updateAppstoreApp($app); |
|
440 | - } |
|
441 | - $this->emit('\OC\Updater', 'checkAppStoreApp', [$app]); |
|
442 | - } catch (\Exception $ex) { |
|
443 | - $this->log->logException($ex, ['app' => 'core']); |
|
444 | - } |
|
445 | - } |
|
446 | - } |
|
447 | - |
|
448 | - /** |
|
449 | - * Forward messages emitted by the repair routine |
|
450 | - */ |
|
451 | - private function emitRepairEvents() { |
|
452 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
453 | - $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
454 | - if ($event instanceof GenericEvent) { |
|
455 | - $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
|
456 | - } |
|
457 | - }); |
|
458 | - $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
459 | - if ($event instanceof GenericEvent) { |
|
460 | - $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
|
461 | - } |
|
462 | - }); |
|
463 | - $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
464 | - if ($event instanceof GenericEvent) { |
|
465 | - $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
|
466 | - } |
|
467 | - }); |
|
468 | - $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
469 | - if ($event instanceof GenericEvent) { |
|
470 | - $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
|
471 | - } |
|
472 | - }); |
|
473 | - } |
|
474 | - |
|
475 | - private function logAllEvents() { |
|
476 | - $log = $this->log; |
|
477 | - |
|
478 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
479 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) { |
|
480 | - if (!$event instanceof GenericEvent) { |
|
481 | - return; |
|
482 | - } |
|
483 | - $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
484 | - }); |
|
485 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) { |
|
486 | - if (!$event instanceof GenericEvent) { |
|
487 | - return; |
|
488 | - } |
|
489 | - $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
490 | - }); |
|
491 | - |
|
492 | - $repairListener = function($event) use ($log) { |
|
493 | - if (!$event instanceof GenericEvent) { |
|
494 | - return; |
|
495 | - } |
|
496 | - switch ($event->getSubject()) { |
|
497 | - case '\OC\Repair::startProgress': |
|
498 | - $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
499 | - break; |
|
500 | - case '\OC\Repair::advance': |
|
501 | - $desc = $event->getArgument(1); |
|
502 | - if (empty($desc)) { |
|
503 | - $desc = ''; |
|
504 | - } |
|
505 | - $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
506 | - |
|
507 | - break; |
|
508 | - case '\OC\Repair::finishProgress': |
|
509 | - $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
|
510 | - break; |
|
511 | - case '\OC\Repair::step': |
|
512 | - $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
513 | - break; |
|
514 | - case '\OC\Repair::info': |
|
515 | - $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
516 | - break; |
|
517 | - case '\OC\Repair::warning': |
|
518 | - $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
519 | - break; |
|
520 | - case '\OC\Repair::error': |
|
521 | - $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
522 | - break; |
|
523 | - } |
|
524 | - }; |
|
525 | - |
|
526 | - $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
527 | - $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
528 | - $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
529 | - $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
530 | - $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
531 | - $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
532 | - $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
533 | - |
|
534 | - |
|
535 | - $this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) { |
|
536 | - $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
|
537 | - }); |
|
538 | - $this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) { |
|
539 | - $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
|
540 | - }); |
|
541 | - $this->listen('\OC\Updater', 'maintenanceActive', function () use($log) { |
|
542 | - $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
|
543 | - }); |
|
544 | - $this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) { |
|
545 | - if ($success) { |
|
546 | - $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
|
547 | - } else { |
|
548 | - $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
|
549 | - } |
|
550 | - }); |
|
551 | - $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) { |
|
552 | - $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
|
553 | - }); |
|
554 | - $this->listen('\OC\Updater', 'dbUpgrade', function () use($log) { |
|
555 | - $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
|
556 | - }); |
|
557 | - $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) { |
|
558 | - $log->info('\OC\Updater::dbSimulateUpgradeBefore: Checking whether the database schema can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
559 | - }); |
|
560 | - $this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) { |
|
561 | - $log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']); |
|
562 | - }); |
|
563 | - $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) { |
|
564 | - $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
565 | - }); |
|
566 | - $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($log) { |
|
567 | - $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
568 | - }); |
|
569 | - $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) { |
|
570 | - $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']); |
|
571 | - }); |
|
572 | - $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($log) { |
|
573 | - $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
574 | - }); |
|
575 | - $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) { |
|
576 | - $log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']); |
|
577 | - }); |
|
578 | - $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
579 | - $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <' . $app . '> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
580 | - }); |
|
581 | - $this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) { |
|
582 | - $log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']); |
|
583 | - }); |
|
584 | - $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
585 | - $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
586 | - }); |
|
587 | - $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
588 | - $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
589 | - }); |
|
590 | - $this->listen('\OC\Updater', 'failure', function ($message) use($log) { |
|
591 | - $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
592 | - }); |
|
593 | - $this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) { |
|
594 | - $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
|
595 | - }); |
|
596 | - $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) { |
|
597 | - $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
598 | - }); |
|
599 | - $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) { |
|
600 | - $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
|
601 | - }); |
|
602 | - $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) { |
|
603 | - $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
|
604 | - }); |
|
605 | - |
|
606 | - } |
|
57 | + /** @var ILogger $log */ |
|
58 | + private $log; |
|
59 | + |
|
60 | + /** @var IConfig */ |
|
61 | + private $config; |
|
62 | + |
|
63 | + /** @var Checker */ |
|
64 | + private $checker; |
|
65 | + |
|
66 | + /** @var Installer */ |
|
67 | + private $installer; |
|
68 | + |
|
69 | + private $logLevelNames = [ |
|
70 | + 0 => 'Debug', |
|
71 | + 1 => 'Info', |
|
72 | + 2 => 'Warning', |
|
73 | + 3 => 'Error', |
|
74 | + 4 => 'Fatal', |
|
75 | + ]; |
|
76 | + |
|
77 | + /** |
|
78 | + * @param IConfig $config |
|
79 | + * @param Checker $checker |
|
80 | + * @param ILogger $log |
|
81 | + * @param Installer $installer |
|
82 | + */ |
|
83 | + public function __construct(IConfig $config, |
|
84 | + Checker $checker, |
|
85 | + ILogger $log = null, |
|
86 | + Installer $installer) { |
|
87 | + $this->log = $log; |
|
88 | + $this->config = $config; |
|
89 | + $this->checker = $checker; |
|
90 | + $this->installer = $installer; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * runs the update actions in maintenance mode, does not upgrade the source files |
|
95 | + * except the main .htaccess file |
|
96 | + * |
|
97 | + * @return bool true if the operation succeeded, false otherwise |
|
98 | + */ |
|
99 | + public function upgrade() { |
|
100 | + $this->emitRepairEvents(); |
|
101 | + $this->logAllEvents(); |
|
102 | + |
|
103 | + $logLevel = $this->config->getSystemValue('loglevel', ILogger::WARN); |
|
104 | + $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
105 | + $this->config->setSystemValue('loglevel', ILogger::DEBUG); |
|
106 | + |
|
107 | + $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
108 | + |
|
109 | + if(!$wasMaintenanceModeEnabled) { |
|
110 | + $this->config->setSystemValue('maintenance', true); |
|
111 | + $this->emit('\OC\Updater', 'maintenanceEnabled'); |
|
112 | + } |
|
113 | + |
|
114 | + $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
115 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
116 | + $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core')); |
|
117 | + |
|
118 | + $success = true; |
|
119 | + try { |
|
120 | + $this->doUpgrade($currentVersion, $installedVersion); |
|
121 | + } catch (HintException $exception) { |
|
122 | + $this->log->logException($exception, ['app' => 'core']); |
|
123 | + $this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint())); |
|
124 | + $success = false; |
|
125 | + } catch (\Exception $exception) { |
|
126 | + $this->log->logException($exception, ['app' => 'core']); |
|
127 | + $this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage())); |
|
128 | + $success = false; |
|
129 | + } |
|
130 | + |
|
131 | + $this->emit('\OC\Updater', 'updateEnd', array($success)); |
|
132 | + |
|
133 | + if(!$wasMaintenanceModeEnabled && $success) { |
|
134 | + $this->config->setSystemValue('maintenance', false); |
|
135 | + $this->emit('\OC\Updater', 'maintenanceDisabled'); |
|
136 | + } else { |
|
137 | + $this->emit('\OC\Updater', 'maintenanceActive'); |
|
138 | + } |
|
139 | + |
|
140 | + $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
141 | + $this->config->setSystemValue('loglevel', $logLevel); |
|
142 | + $this->config->setSystemValue('installed', true); |
|
143 | + |
|
144 | + return $success; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Return version from which this version is allowed to upgrade from |
|
149 | + * |
|
150 | + * @return array allowed previous versions per vendor |
|
151 | + */ |
|
152 | + private function getAllowedPreviousVersions() { |
|
153 | + // this should really be a JSON file |
|
154 | + require \OC::$SERVERROOT . '/version.php'; |
|
155 | + /** @var array $OC_VersionCanBeUpgradedFrom */ |
|
156 | + return $OC_VersionCanBeUpgradedFrom; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Return vendor from which this version was published |
|
161 | + * |
|
162 | + * @return string Get the vendor |
|
163 | + */ |
|
164 | + private function getVendor() { |
|
165 | + // this should really be a JSON file |
|
166 | + require \OC::$SERVERROOT . '/version.php'; |
|
167 | + /** @var string $vendor */ |
|
168 | + return (string) $vendor; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Whether an upgrade to a specified version is possible |
|
173 | + * @param string $oldVersion |
|
174 | + * @param string $newVersion |
|
175 | + * @param array $allowedPreviousVersions |
|
176 | + * @return bool |
|
177 | + */ |
|
178 | + public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) { |
|
179 | + $version = explode('.', $oldVersion); |
|
180 | + $majorMinor = $version[0] . '.' . $version[1]; |
|
181 | + |
|
182 | + $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
|
183 | + |
|
184 | + // Vendor was not set correctly on install, so we have to white-list known versions |
|
185 | + if ($currentVendor === '' && isset($allowedPreviousVersions['owncloud'][$oldVersion])) { |
|
186 | + $currentVendor = 'owncloud'; |
|
187 | + } |
|
188 | + |
|
189 | + if ($currentVendor === 'nextcloud') { |
|
190 | + return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) |
|
191 | + && (version_compare($oldVersion, $newVersion, '<=') || |
|
192 | + $this->config->getSystemValue('debug', false)); |
|
193 | + } |
|
194 | + |
|
195 | + // Check if the instance can be migrated |
|
196 | + return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) || |
|
197 | + isset($allowedPreviousVersions[$currentVendor][$oldVersion]); |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * runs the update actions in maintenance mode, does not upgrade the source files |
|
202 | + * except the main .htaccess file |
|
203 | + * |
|
204 | + * @param string $currentVersion current version to upgrade to |
|
205 | + * @param string $installedVersion previous version from which to upgrade from |
|
206 | + * |
|
207 | + * @throws \Exception |
|
208 | + */ |
|
209 | + private function doUpgrade($currentVersion, $installedVersion) { |
|
210 | + // Stop update if the update is over several major versions |
|
211 | + $allowedPreviousVersions = $this->getAllowedPreviousVersions(); |
|
212 | + if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) { |
|
213 | + throw new \Exception('Updates between multiple major versions and downgrades are unsupported.'); |
|
214 | + } |
|
215 | + |
|
216 | + // Update .htaccess files |
|
217 | + try { |
|
218 | + Setup::updateHtaccess(); |
|
219 | + Setup::protectDataDirectory(); |
|
220 | + } catch (\Exception $e) { |
|
221 | + throw new \Exception($e->getMessage()); |
|
222 | + } |
|
223 | + |
|
224 | + // create empty file in data dir, so we can later find |
|
225 | + // out that this is indeed an ownCloud data directory |
|
226 | + // (in case it didn't exist before) |
|
227 | + file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
228 | + |
|
229 | + // pre-upgrade repairs |
|
230 | + $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher()); |
|
231 | + $repair->run(); |
|
232 | + |
|
233 | + $this->doCoreUpgrade(); |
|
234 | + |
|
235 | + try { |
|
236 | + // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 |
|
237 | + Setup::installBackgroundJobs(); |
|
238 | + } catch (\Exception $e) { |
|
239 | + throw new \Exception($e->getMessage()); |
|
240 | + } |
|
241 | + |
|
242 | + // update all shipped apps |
|
243 | + $this->checkAppsRequirements(); |
|
244 | + $this->doAppUpgrade(); |
|
245 | + |
|
246 | + // Update the appfetchers version so it downloads the correct list from the appstore |
|
247 | + \OC::$server->getAppFetcher()->setVersion($currentVersion); |
|
248 | + |
|
249 | + // upgrade appstore apps |
|
250 | + $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps()); |
|
251 | + |
|
252 | + // install new shipped apps on upgrade |
|
253 | + OC_App::loadApps(['authentication']); |
|
254 | + $errors = Installer::installShippedApps(true); |
|
255 | + foreach ($errors as $appId => $exception) { |
|
256 | + /** @var \Exception $exception */ |
|
257 | + $this->log->logException($exception, ['app' => $appId]); |
|
258 | + $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
259 | + } |
|
260 | + |
|
261 | + // post-upgrade repairs |
|
262 | + $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher()); |
|
263 | + $repair->run(); |
|
264 | + |
|
265 | + //Invalidate update feed |
|
266 | + $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
267 | + |
|
268 | + // Check for code integrity if not disabled |
|
269 | + if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
270 | + $this->emit('\OC\Updater', 'startCheckCodeIntegrity'); |
|
271 | + $this->checker->runInstanceVerification(); |
|
272 | + $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity'); |
|
273 | + } |
|
274 | + |
|
275 | + // only set the final version if everything went well |
|
276 | + $this->config->setSystemValue('version', implode('.', Util::getVersion())); |
|
277 | + $this->config->setAppValue('core', 'vendor', $this->getVendor()); |
|
278 | + } |
|
279 | + |
|
280 | + protected function doCoreUpgrade() { |
|
281 | + $this->emit('\OC\Updater', 'dbUpgradeBefore'); |
|
282 | + |
|
283 | + // execute core migrations |
|
284 | + $ms = new MigrationService('core', \OC::$server->getDatabaseConnection()); |
|
285 | + $ms->migrate(); |
|
286 | + |
|
287 | + $this->emit('\OC\Updater', 'dbUpgrade'); |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * @param string $version the oc version to check app compatibility with |
|
292 | + */ |
|
293 | + protected function checkAppUpgrade($version) { |
|
294 | + $apps = \OC_App::getEnabledApps(); |
|
295 | + $this->emit('\OC\Updater', 'appUpgradeCheckBefore'); |
|
296 | + |
|
297 | + $appManager = \OC::$server->getAppManager(); |
|
298 | + foreach ($apps as $appId) { |
|
299 | + $info = \OC_App::getAppInfo($appId); |
|
300 | + $compatible = \OC_App::isAppCompatible($version, $info); |
|
301 | + $isShipped = $appManager->isShipped($appId); |
|
302 | + |
|
303 | + if ($compatible && $isShipped && \OC_App::shouldUpgrade($appId)) { |
|
304 | + /** |
|
305 | + * FIXME: The preupdate check is performed before the database migration, otherwise database changes |
|
306 | + * are not possible anymore within it. - Consider this when touching the code. |
|
307 | + * @link https://github.com/owncloud/core/issues/10980 |
|
308 | + * @see \OC_App::updateApp |
|
309 | + */ |
|
310 | + if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) { |
|
311 | + $this->includePreUpdate($appId); |
|
312 | + } |
|
313 | + if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) { |
|
314 | + $this->emit('\OC\Updater', 'appSimulateUpdate', array($appId)); |
|
315 | + \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml'); |
|
316 | + } |
|
317 | + } |
|
318 | + } |
|
319 | + |
|
320 | + $this->emit('\OC\Updater', 'appUpgradeCheck'); |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Includes the pre-update file. Done here to prevent namespace mixups. |
|
325 | + * @param string $appId |
|
326 | + */ |
|
327 | + private function includePreUpdate($appId) { |
|
328 | + include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php'; |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * upgrades all apps within a major ownCloud upgrade. Also loads "priority" |
|
333 | + * (types authentication, filesystem, logging, in that order) afterwards. |
|
334 | + * |
|
335 | + * @throws NeedsUpdateException |
|
336 | + */ |
|
337 | + protected function doAppUpgrade() { |
|
338 | + $apps = \OC_App::getEnabledApps(); |
|
339 | + $priorityTypes = array('authentication', 'filesystem', 'logging'); |
|
340 | + $pseudoOtherType = 'other'; |
|
341 | + $stacks = array($pseudoOtherType => array()); |
|
342 | + |
|
343 | + foreach ($apps as $appId) { |
|
344 | + $priorityType = false; |
|
345 | + foreach ($priorityTypes as $type) { |
|
346 | + if(!isset($stacks[$type])) { |
|
347 | + $stacks[$type] = array(); |
|
348 | + } |
|
349 | + if (\OC_App::isType($appId, [$type])) { |
|
350 | + $stacks[$type][] = $appId; |
|
351 | + $priorityType = true; |
|
352 | + break; |
|
353 | + } |
|
354 | + } |
|
355 | + if (!$priorityType) { |
|
356 | + $stacks[$pseudoOtherType][] = $appId; |
|
357 | + } |
|
358 | + } |
|
359 | + foreach ($stacks as $type => $stack) { |
|
360 | + foreach ($stack as $appId) { |
|
361 | + if (\OC_App::shouldUpgrade($appId)) { |
|
362 | + $this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]); |
|
363 | + \OC_App::updateApp($appId); |
|
364 | + $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]); |
|
365 | + } |
|
366 | + if($type !== $pseudoOtherType) { |
|
367 | + // load authentication, filesystem and logging apps after |
|
368 | + // upgrading them. Other apps my need to rely on modifying |
|
369 | + // user and/or filesystem aspects. |
|
370 | + \OC_App::loadApp($appId); |
|
371 | + } |
|
372 | + } |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * check if the current enabled apps are compatible with the current |
|
378 | + * ownCloud version. disable them if not. |
|
379 | + * This is important if you upgrade ownCloud and have non ported 3rd |
|
380 | + * party apps installed. |
|
381 | + * |
|
382 | + * @return array |
|
383 | + * @throws \Exception |
|
384 | + */ |
|
385 | + private function checkAppsRequirements() { |
|
386 | + $isCoreUpgrade = $this->isCodeUpgrade(); |
|
387 | + $apps = OC_App::getEnabledApps(); |
|
388 | + $version = implode('.', Util::getVersion()); |
|
389 | + $disabledApps = []; |
|
390 | + $appManager = \OC::$server->getAppManager(); |
|
391 | + foreach ($apps as $app) { |
|
392 | + // check if the app is compatible with this version of ownCloud |
|
393 | + $info = OC_App::getAppInfo($app); |
|
394 | + if($info === null || !OC_App::isAppCompatible($version, $info)) { |
|
395 | + if ($appManager->isShipped($app)) { |
|
396 | + throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
397 | + } |
|
398 | + \OC::$server->getAppManager()->disableApp($app); |
|
399 | + $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app)); |
|
400 | + } |
|
401 | + // no need to disable any app in case this is a non-core upgrade |
|
402 | + if (!$isCoreUpgrade) { |
|
403 | + continue; |
|
404 | + } |
|
405 | + // shipped apps will remain enabled |
|
406 | + if ($appManager->isShipped($app)) { |
|
407 | + continue; |
|
408 | + } |
|
409 | + // authentication and session apps will remain enabled as well |
|
410 | + if (OC_App::isType($app, ['session', 'authentication'])) { |
|
411 | + continue; |
|
412 | + } |
|
413 | + } |
|
414 | + return $disabledApps; |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * @return bool |
|
419 | + */ |
|
420 | + private function isCodeUpgrade() { |
|
421 | + $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
422 | + $currentVersion = implode('.', Util::getVersion()); |
|
423 | + if (version_compare($currentVersion, $installedVersion, '>')) { |
|
424 | + return true; |
|
425 | + } |
|
426 | + return false; |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * @param array $disabledApps |
|
431 | + * @throws \Exception |
|
432 | + */ |
|
433 | + private function upgradeAppStoreApps(array $disabledApps) { |
|
434 | + foreach($disabledApps as $app) { |
|
435 | + try { |
|
436 | + $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]); |
|
437 | + if ($this->installer->isUpdateAvailable($app)) { |
|
438 | + $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]); |
|
439 | + $this->installer->updateAppstoreApp($app); |
|
440 | + } |
|
441 | + $this->emit('\OC\Updater', 'checkAppStoreApp', [$app]); |
|
442 | + } catch (\Exception $ex) { |
|
443 | + $this->log->logException($ex, ['app' => 'core']); |
|
444 | + } |
|
445 | + } |
|
446 | + } |
|
447 | + |
|
448 | + /** |
|
449 | + * Forward messages emitted by the repair routine |
|
450 | + */ |
|
451 | + private function emitRepairEvents() { |
|
452 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
453 | + $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
454 | + if ($event instanceof GenericEvent) { |
|
455 | + $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
|
456 | + } |
|
457 | + }); |
|
458 | + $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
459 | + if ($event instanceof GenericEvent) { |
|
460 | + $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
|
461 | + } |
|
462 | + }); |
|
463 | + $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
464 | + if ($event instanceof GenericEvent) { |
|
465 | + $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
|
466 | + } |
|
467 | + }); |
|
468 | + $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
469 | + if ($event instanceof GenericEvent) { |
|
470 | + $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
|
471 | + } |
|
472 | + }); |
|
473 | + } |
|
474 | + |
|
475 | + private function logAllEvents() { |
|
476 | + $log = $this->log; |
|
477 | + |
|
478 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
479 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) { |
|
480 | + if (!$event instanceof GenericEvent) { |
|
481 | + return; |
|
482 | + } |
|
483 | + $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
484 | + }); |
|
485 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) { |
|
486 | + if (!$event instanceof GenericEvent) { |
|
487 | + return; |
|
488 | + } |
|
489 | + $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
490 | + }); |
|
491 | + |
|
492 | + $repairListener = function($event) use ($log) { |
|
493 | + if (!$event instanceof GenericEvent) { |
|
494 | + return; |
|
495 | + } |
|
496 | + switch ($event->getSubject()) { |
|
497 | + case '\OC\Repair::startProgress': |
|
498 | + $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
499 | + break; |
|
500 | + case '\OC\Repair::advance': |
|
501 | + $desc = $event->getArgument(1); |
|
502 | + if (empty($desc)) { |
|
503 | + $desc = ''; |
|
504 | + } |
|
505 | + $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
506 | + |
|
507 | + break; |
|
508 | + case '\OC\Repair::finishProgress': |
|
509 | + $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
|
510 | + break; |
|
511 | + case '\OC\Repair::step': |
|
512 | + $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
513 | + break; |
|
514 | + case '\OC\Repair::info': |
|
515 | + $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
516 | + break; |
|
517 | + case '\OC\Repair::warning': |
|
518 | + $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
519 | + break; |
|
520 | + case '\OC\Repair::error': |
|
521 | + $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
522 | + break; |
|
523 | + } |
|
524 | + }; |
|
525 | + |
|
526 | + $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
527 | + $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
528 | + $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
529 | + $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
530 | + $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
531 | + $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
532 | + $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
533 | + |
|
534 | + |
|
535 | + $this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) { |
|
536 | + $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
|
537 | + }); |
|
538 | + $this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) { |
|
539 | + $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
|
540 | + }); |
|
541 | + $this->listen('\OC\Updater', 'maintenanceActive', function () use($log) { |
|
542 | + $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
|
543 | + }); |
|
544 | + $this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) { |
|
545 | + if ($success) { |
|
546 | + $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
|
547 | + } else { |
|
548 | + $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
|
549 | + } |
|
550 | + }); |
|
551 | + $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) { |
|
552 | + $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
|
553 | + }); |
|
554 | + $this->listen('\OC\Updater', 'dbUpgrade', function () use($log) { |
|
555 | + $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
|
556 | + }); |
|
557 | + $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) { |
|
558 | + $log->info('\OC\Updater::dbSimulateUpgradeBefore: Checking whether the database schema can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
559 | + }); |
|
560 | + $this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) { |
|
561 | + $log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']); |
|
562 | + }); |
|
563 | + $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) { |
|
564 | + $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
565 | + }); |
|
566 | + $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($log) { |
|
567 | + $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
568 | + }); |
|
569 | + $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) { |
|
570 | + $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']); |
|
571 | + }); |
|
572 | + $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($log) { |
|
573 | + $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
574 | + }); |
|
575 | + $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) { |
|
576 | + $log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']); |
|
577 | + }); |
|
578 | + $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
579 | + $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <' . $app . '> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
580 | + }); |
|
581 | + $this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) { |
|
582 | + $log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']); |
|
583 | + }); |
|
584 | + $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
585 | + $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
586 | + }); |
|
587 | + $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
588 | + $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
589 | + }); |
|
590 | + $this->listen('\OC\Updater', 'failure', function ($message) use($log) { |
|
591 | + $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
592 | + }); |
|
593 | + $this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) { |
|
594 | + $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
|
595 | + }); |
|
596 | + $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) { |
|
597 | + $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
598 | + }); |
|
599 | + $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) { |
|
600 | + $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
|
601 | + }); |
|
602 | + $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) { |
|
603 | + $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
|
604 | + }); |
|
605 | + |
|
606 | + } |
|
607 | 607 | |
608 | 608 | } |
609 | 609 |
@@ -35,170 +35,170 @@ |
||
35 | 35 | |
36 | 36 | class File implements ICache { |
37 | 37 | |
38 | - /** @var View */ |
|
39 | - protected $storage; |
|
38 | + /** @var View */ |
|
39 | + protected $storage; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Returns the cache storage for the logged in user |
|
43 | - * |
|
44 | - * @return \OC\Files\View cache storage |
|
45 | - * @throws \OC\ForbiddenException |
|
46 | - * @throws \OC\User\NoUserException |
|
47 | - */ |
|
48 | - protected function getStorage() { |
|
49 | - if (isset($this->storage)) { |
|
50 | - return $this->storage; |
|
51 | - } |
|
52 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
53 | - $rootView = new View(); |
|
54 | - $user = \OC::$server->getUserSession()->getUser(); |
|
55 | - Filesystem::initMountPoints($user->getUID()); |
|
56 | - if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) { |
|
57 | - $rootView->mkdir('/' . $user->getUID() . '/cache'); |
|
58 | - } |
|
59 | - $this->storage = new View('/' . $user->getUID() . '/cache'); |
|
60 | - return $this->storage; |
|
61 | - } else { |
|
62 | - \OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', ILogger::ERROR); |
|
63 | - throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in'); |
|
64 | - } |
|
65 | - } |
|
41 | + /** |
|
42 | + * Returns the cache storage for the logged in user |
|
43 | + * |
|
44 | + * @return \OC\Files\View cache storage |
|
45 | + * @throws \OC\ForbiddenException |
|
46 | + * @throws \OC\User\NoUserException |
|
47 | + */ |
|
48 | + protected function getStorage() { |
|
49 | + if (isset($this->storage)) { |
|
50 | + return $this->storage; |
|
51 | + } |
|
52 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
53 | + $rootView = new View(); |
|
54 | + $user = \OC::$server->getUserSession()->getUser(); |
|
55 | + Filesystem::initMountPoints($user->getUID()); |
|
56 | + if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) { |
|
57 | + $rootView->mkdir('/' . $user->getUID() . '/cache'); |
|
58 | + } |
|
59 | + $this->storage = new View('/' . $user->getUID() . '/cache'); |
|
60 | + return $this->storage; |
|
61 | + } else { |
|
62 | + \OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', ILogger::ERROR); |
|
63 | + throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in'); |
|
64 | + } |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param string $key |
|
69 | - * @return mixed|null |
|
70 | - * @throws \OC\ForbiddenException |
|
71 | - */ |
|
72 | - public function get($key) { |
|
73 | - $result = null; |
|
74 | - if ($this->hasKey($key)) { |
|
75 | - $storage = $this->getStorage(); |
|
76 | - $result = $storage->file_get_contents($key); |
|
77 | - } |
|
78 | - return $result; |
|
79 | - } |
|
67 | + /** |
|
68 | + * @param string $key |
|
69 | + * @return mixed|null |
|
70 | + * @throws \OC\ForbiddenException |
|
71 | + */ |
|
72 | + public function get($key) { |
|
73 | + $result = null; |
|
74 | + if ($this->hasKey($key)) { |
|
75 | + $storage = $this->getStorage(); |
|
76 | + $result = $storage->file_get_contents($key); |
|
77 | + } |
|
78 | + return $result; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Returns the size of the stored/cached data |
|
83 | - * |
|
84 | - * @param string $key |
|
85 | - * @return int |
|
86 | - */ |
|
87 | - public function size($key) { |
|
88 | - $result = 0; |
|
89 | - if ($this->hasKey($key)) { |
|
90 | - $storage = $this->getStorage(); |
|
91 | - $result = $storage->filesize($key); |
|
92 | - } |
|
93 | - return $result; |
|
94 | - } |
|
81 | + /** |
|
82 | + * Returns the size of the stored/cached data |
|
83 | + * |
|
84 | + * @param string $key |
|
85 | + * @return int |
|
86 | + */ |
|
87 | + public function size($key) { |
|
88 | + $result = 0; |
|
89 | + if ($this->hasKey($key)) { |
|
90 | + $storage = $this->getStorage(); |
|
91 | + $result = $storage->filesize($key); |
|
92 | + } |
|
93 | + return $result; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @param string $key |
|
98 | - * @param mixed $value |
|
99 | - * @param int $ttl |
|
100 | - * @return bool|mixed |
|
101 | - * @throws \OC\ForbiddenException |
|
102 | - */ |
|
103 | - public function set($key, $value, $ttl = 0) { |
|
104 | - $storage = $this->getStorage(); |
|
105 | - $result = false; |
|
106 | - // unique id to avoid chunk collision, just in case |
|
107 | - $uniqueId = \OC::$server->getSecureRandom()->generate( |
|
108 | - 16, |
|
109 | - ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER |
|
110 | - ); |
|
96 | + /** |
|
97 | + * @param string $key |
|
98 | + * @param mixed $value |
|
99 | + * @param int $ttl |
|
100 | + * @return bool|mixed |
|
101 | + * @throws \OC\ForbiddenException |
|
102 | + */ |
|
103 | + public function set($key, $value, $ttl = 0) { |
|
104 | + $storage = $this->getStorage(); |
|
105 | + $result = false; |
|
106 | + // unique id to avoid chunk collision, just in case |
|
107 | + $uniqueId = \OC::$server->getSecureRandom()->generate( |
|
108 | + 16, |
|
109 | + ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER |
|
110 | + ); |
|
111 | 111 | |
112 | - // use part file to prevent hasKey() to find the key |
|
113 | - // while it is being written |
|
114 | - $keyPart = $key . '.' . $uniqueId . '.part'; |
|
115 | - if ($storage and $storage->file_put_contents($keyPart, $value)) { |
|
116 | - if ($ttl === 0) { |
|
117 | - $ttl = 86400; // 60*60*24 |
|
118 | - } |
|
119 | - $result = $storage->touch($keyPart, time() + $ttl); |
|
120 | - $result &= $storage->rename($keyPart, $key); |
|
121 | - } |
|
122 | - return $result; |
|
123 | - } |
|
112 | + // use part file to prevent hasKey() to find the key |
|
113 | + // while it is being written |
|
114 | + $keyPart = $key . '.' . $uniqueId . '.part'; |
|
115 | + if ($storage and $storage->file_put_contents($keyPart, $value)) { |
|
116 | + if ($ttl === 0) { |
|
117 | + $ttl = 86400; // 60*60*24 |
|
118 | + } |
|
119 | + $result = $storage->touch($keyPart, time() + $ttl); |
|
120 | + $result &= $storage->rename($keyPart, $key); |
|
121 | + } |
|
122 | + return $result; |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * @param string $key |
|
127 | - * @return bool |
|
128 | - * @throws \OC\ForbiddenException |
|
129 | - */ |
|
130 | - public function hasKey($key) { |
|
131 | - $storage = $this->getStorage(); |
|
132 | - if ($storage && $storage->is_file($key) && $storage->isReadable($key)) { |
|
133 | - return true; |
|
134 | - } |
|
135 | - return false; |
|
136 | - } |
|
125 | + /** |
|
126 | + * @param string $key |
|
127 | + * @return bool |
|
128 | + * @throws \OC\ForbiddenException |
|
129 | + */ |
|
130 | + public function hasKey($key) { |
|
131 | + $storage = $this->getStorage(); |
|
132 | + if ($storage && $storage->is_file($key) && $storage->isReadable($key)) { |
|
133 | + return true; |
|
134 | + } |
|
135 | + return false; |
|
136 | + } |
|
137 | 137 | |
138 | - /** |
|
139 | - * @param string $key |
|
140 | - * @return bool|mixed |
|
141 | - * @throws \OC\ForbiddenException |
|
142 | - */ |
|
143 | - public function remove($key) { |
|
144 | - $storage = $this->getStorage(); |
|
145 | - if (!$storage) { |
|
146 | - return false; |
|
147 | - } |
|
148 | - return $storage->unlink($key); |
|
149 | - } |
|
138 | + /** |
|
139 | + * @param string $key |
|
140 | + * @return bool|mixed |
|
141 | + * @throws \OC\ForbiddenException |
|
142 | + */ |
|
143 | + public function remove($key) { |
|
144 | + $storage = $this->getStorage(); |
|
145 | + if (!$storage) { |
|
146 | + return false; |
|
147 | + } |
|
148 | + return $storage->unlink($key); |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * @param string $prefix |
|
153 | - * @return bool |
|
154 | - * @throws \OC\ForbiddenException |
|
155 | - */ |
|
156 | - public function clear($prefix = '') { |
|
157 | - $storage = $this->getStorage(); |
|
158 | - if ($storage and $storage->is_dir('/')) { |
|
159 | - $dh = $storage->opendir('/'); |
|
160 | - if (is_resource($dh)) { |
|
161 | - while (($file = readdir($dh)) !== false) { |
|
162 | - if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) { |
|
163 | - $storage->unlink('/' . $file); |
|
164 | - } |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
168 | - return true; |
|
169 | - } |
|
151 | + /** |
|
152 | + * @param string $prefix |
|
153 | + * @return bool |
|
154 | + * @throws \OC\ForbiddenException |
|
155 | + */ |
|
156 | + public function clear($prefix = '') { |
|
157 | + $storage = $this->getStorage(); |
|
158 | + if ($storage and $storage->is_dir('/')) { |
|
159 | + $dh = $storage->opendir('/'); |
|
160 | + if (is_resource($dh)) { |
|
161 | + while (($file = readdir($dh)) !== false) { |
|
162 | + if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) { |
|
163 | + $storage->unlink('/' . $file); |
|
164 | + } |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | + return true; |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Runs GC |
|
173 | - * @throws \OC\ForbiddenException |
|
174 | - */ |
|
175 | - public function gc() { |
|
176 | - $storage = $this->getStorage(); |
|
177 | - if ($storage and $storage->is_dir('/')) { |
|
178 | - // extra hour safety, in case of stray part chunks that take longer to write, |
|
179 | - // because touch() is only called after the chunk was finished |
|
180 | - $now = time() - 3600; |
|
181 | - $dh = $storage->opendir('/'); |
|
182 | - if (!is_resource($dh)) { |
|
183 | - return null; |
|
184 | - } |
|
185 | - while (($file = readdir($dh)) !== false) { |
|
186 | - if ($file != '.' and $file != '..') { |
|
187 | - try { |
|
188 | - $mtime = $storage->filemtime('/' . $file); |
|
189 | - if ($mtime < $now) { |
|
190 | - $storage->unlink('/' . $file); |
|
191 | - } |
|
192 | - } catch (\OCP\Lock\LockedException $e) { |
|
193 | - // ignore locked chunks |
|
194 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
195 | - } catch (\OCP\Files\ForbiddenException $e) { |
|
196 | - \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', array('app' => 'core')); |
|
197 | - } catch (\OCP\Files\LockNotAcquiredException $e) { |
|
198 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
202 | - } |
|
203 | - } |
|
171 | + /** |
|
172 | + * Runs GC |
|
173 | + * @throws \OC\ForbiddenException |
|
174 | + */ |
|
175 | + public function gc() { |
|
176 | + $storage = $this->getStorage(); |
|
177 | + if ($storage and $storage->is_dir('/')) { |
|
178 | + // extra hour safety, in case of stray part chunks that take longer to write, |
|
179 | + // because touch() is only called after the chunk was finished |
|
180 | + $now = time() - 3600; |
|
181 | + $dh = $storage->opendir('/'); |
|
182 | + if (!is_resource($dh)) { |
|
183 | + return null; |
|
184 | + } |
|
185 | + while (($file = readdir($dh)) !== false) { |
|
186 | + if ($file != '.' and $file != '..') { |
|
187 | + try { |
|
188 | + $mtime = $storage->filemtime('/' . $file); |
|
189 | + if ($mtime < $now) { |
|
190 | + $storage->unlink('/' . $file); |
|
191 | + } |
|
192 | + } catch (\OCP\Lock\LockedException $e) { |
|
193 | + // ignore locked chunks |
|
194 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
195 | + } catch (\OCP\Files\ForbiddenException $e) { |
|
196 | + \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', array('app' => 'core')); |
|
197 | + } catch (\OCP\Files\LockNotAcquiredException $e) { |
|
198 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | + } |
|
203 | + } |
|
204 | 204 | } |
@@ -76,384 +76,384 @@ |
||
76 | 76 | * Class for user management in a SQL Database (e.g. MySQL, SQLite) |
77 | 77 | */ |
78 | 78 | class Database extends ABackend |
79 | - implements ICreateUserBackend, |
|
80 | - ISetPasswordBackend, |
|
81 | - ISetDisplayNameBackend, |
|
82 | - IGetDisplayNameBackend, |
|
83 | - ICheckPasswordBackend, |
|
84 | - IGetHomeBackend, |
|
85 | - ICountUsersBackend { |
|
86 | - /** @var CappedMemoryCache */ |
|
87 | - private $cache; |
|
88 | - |
|
89 | - /** @var EventDispatcher */ |
|
90 | - private $eventDispatcher; |
|
91 | - |
|
92 | - /** @var IDBConnection */ |
|
93 | - private $dbConn; |
|
94 | - |
|
95 | - /** |
|
96 | - * \OC\User\Database constructor. |
|
97 | - * |
|
98 | - * @param EventDispatcher $eventDispatcher |
|
99 | - */ |
|
100 | - public function __construct($eventDispatcher = null) { |
|
101 | - $this->cache = new CappedMemoryCache(); |
|
102 | - $this->eventDispatcher = $eventDispatcher ? $eventDispatcher : \OC::$server->getEventDispatcher(); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * FIXME: This function should not be required! |
|
107 | - */ |
|
108 | - private function fixDI() { |
|
109 | - if ($this->dbConn === null) { |
|
110 | - $this->dbConn = \OC::$server->getDatabaseConnection(); |
|
111 | - } |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Create a new user |
|
116 | - * |
|
117 | - * @param string $uid The username of the user to create |
|
118 | - * @param string $password The password of the new user |
|
119 | - * @return bool |
|
120 | - * |
|
121 | - * Creates a new user. Basic checking of username is done in OC_User |
|
122 | - * itself, not in its subclasses. |
|
123 | - */ |
|
124 | - public function createUser(string $uid, string $password): bool { |
|
125 | - $this->fixDI(); |
|
126 | - |
|
127 | - if (!$this->userExists($uid)) { |
|
128 | - $event = new GenericEvent($password); |
|
129 | - $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); |
|
130 | - |
|
131 | - $qb = $this->dbConn->getQueryBuilder(); |
|
132 | - $qb->insert('users') |
|
133 | - ->values([ |
|
134 | - 'uid' => $qb->createNamedParameter($uid), |
|
135 | - 'password' => $qb->createNamedParameter(\OC::$server->getHasher()->hash($password)), |
|
136 | - 'uid_lower' => $qb->createNamedParameter(mb_strtolower($uid)), |
|
137 | - ]); |
|
138 | - |
|
139 | - $result = $qb->execute(); |
|
140 | - |
|
141 | - // Clear cache |
|
142 | - unset($this->cache[$uid]); |
|
143 | - |
|
144 | - return $result ? true : false; |
|
145 | - } |
|
146 | - |
|
147 | - return false; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * delete a user |
|
152 | - * |
|
153 | - * @param string $uid The username of the user to delete |
|
154 | - * @return bool |
|
155 | - * |
|
156 | - * Deletes a user |
|
157 | - */ |
|
158 | - public function deleteUser($uid) { |
|
159 | - $this->fixDI(); |
|
160 | - |
|
161 | - // Delete user-group-relation |
|
162 | - $query = \OC_DB::prepare('DELETE FROM `*PREFIX*users` WHERE `uid` = ?'); |
|
163 | - $result = $query->execute([$uid]); |
|
164 | - |
|
165 | - if (isset($this->cache[$uid])) { |
|
166 | - unset($this->cache[$uid]); |
|
167 | - } |
|
168 | - |
|
169 | - return $result ? true : false; |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Set password |
|
174 | - * |
|
175 | - * @param string $uid The username |
|
176 | - * @param string $password The new password |
|
177 | - * @return bool |
|
178 | - * |
|
179 | - * Change the password of a user |
|
180 | - */ |
|
181 | - public function setPassword(string $uid, string $password): bool { |
|
182 | - $this->fixDI(); |
|
183 | - |
|
184 | - if ($this->userExists($uid)) { |
|
185 | - $event = new GenericEvent($password); |
|
186 | - $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); |
|
187 | - $query = \OC_DB::prepare('UPDATE `*PREFIX*users` SET `password` = ? WHERE `uid` = ?'); |
|
188 | - $result = $query->execute([\OC::$server->getHasher()->hash($password), $uid]); |
|
189 | - |
|
190 | - return $result ? true : false; |
|
191 | - } |
|
192 | - |
|
193 | - return false; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Set display name |
|
198 | - * |
|
199 | - * @param string $uid The username |
|
200 | - * @param string $displayName The new display name |
|
201 | - * @return bool |
|
202 | - * |
|
203 | - * Change the display name of a user |
|
204 | - */ |
|
205 | - public function setDisplayName(string $uid, string $displayName): bool { |
|
206 | - $this->fixDI(); |
|
207 | - |
|
208 | - if ($this->userExists($uid)) { |
|
209 | - $query = \OC_DB::prepare('UPDATE `*PREFIX*users` SET `displayname` = ? WHERE LOWER(`uid`) = LOWER(?)'); |
|
210 | - $query->execute([$displayName, $uid]); |
|
211 | - $this->cache[$uid]['displayname'] = $displayName; |
|
212 | - |
|
213 | - return true; |
|
214 | - } |
|
215 | - |
|
216 | - return false; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * get display name of the user |
|
221 | - * |
|
222 | - * @param string $uid user ID of the user |
|
223 | - * @return string display name |
|
224 | - */ |
|
225 | - public function getDisplayName($uid): string { |
|
226 | - $uid = (string)$uid; |
|
227 | - $this->loadUser($uid); |
|
228 | - return empty($this->cache[$uid]['displayname']) ? $uid : $this->cache[$uid]['displayname']; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Get a list of all display names and user ids. |
|
233 | - * |
|
234 | - * @param string $search |
|
235 | - * @param string|null $limit |
|
236 | - * @param string|null $offset |
|
237 | - * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
238 | - */ |
|
239 | - public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
240 | - $this->fixDI(); |
|
241 | - |
|
242 | - $query = $this->dbConn->getQueryBuilder(); |
|
243 | - |
|
244 | - $query->select('uid', 'displayname') |
|
245 | - ->from('users', 'u') |
|
246 | - ->leftJoin('u', 'preferences', 'p', $query->expr()->andX( |
|
247 | - $query->expr()->eq('userid', 'uid'), |
|
248 | - $query->expr()->eq('appid', $query->expr()->literal('settings')), |
|
249 | - $query->expr()->eq('configkey', $query->expr()->literal('email'))) |
|
250 | - ) |
|
251 | - // sqlite doesn't like re-using a single named parameter here |
|
252 | - ->where($query->expr()->iLike('uid', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%'))) |
|
253 | - ->orWhere($query->expr()->iLike('displayname', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%'))) |
|
254 | - ->orWhere($query->expr()->iLike('configvalue', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%'))) |
|
255 | - ->orderBy($query->func()->lower('displayname'), 'ASC') |
|
256 | - ->orderBy($query->func()->lower('uid'), 'ASC') |
|
257 | - ->setMaxResults($limit) |
|
258 | - ->setFirstResult($offset); |
|
259 | - |
|
260 | - $result = $query->execute(); |
|
261 | - $displayNames = []; |
|
262 | - while ($row = $result->fetch()) { |
|
263 | - $displayNames[(string)$row['uid']] = (string)$row['displayname']; |
|
264 | - } |
|
265 | - |
|
266 | - return $displayNames; |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * Check if the password is correct |
|
271 | - * |
|
272 | - * @param string $uid The username |
|
273 | - * @param string $password The password |
|
274 | - * @return string |
|
275 | - * |
|
276 | - * Check if the password is correct without logging in the user |
|
277 | - * returns the user id or false |
|
278 | - */ |
|
279 | - public function checkPassword(string $uid, string $password) { |
|
280 | - $this->fixDI(); |
|
281 | - |
|
282 | - $qb = $this->dbConn->getQueryBuilder(); |
|
283 | - $qb->select('uid', 'password') |
|
284 | - ->from('users') |
|
285 | - ->where( |
|
286 | - $qb->expr()->eq( |
|
287 | - 'uid_lower', $qb->createNamedParameter(mb_strtolower($uid)) |
|
288 | - ) |
|
289 | - ); |
|
290 | - $result = $qb->execute(); |
|
291 | - $row = $result->fetch(); |
|
292 | - $result->closeCursor(); |
|
293 | - |
|
294 | - if ($row) { |
|
295 | - $storedHash = $row['password']; |
|
296 | - $newHash = ''; |
|
297 | - if (\OC::$server->getHasher()->verify($password, $storedHash, $newHash)) { |
|
298 | - if (!empty($newHash)) { |
|
299 | - $this->setPassword($uid, $password); |
|
300 | - } |
|
301 | - return (string)$row['uid']; |
|
302 | - } |
|
303 | - |
|
304 | - } |
|
305 | - |
|
306 | - return false; |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * Load an user in the cache |
|
311 | - * |
|
312 | - * @param string $uid the username |
|
313 | - * @return boolean true if user was found, false otherwise |
|
314 | - */ |
|
315 | - private function loadUser($uid) { |
|
316 | - $this->fixDI(); |
|
317 | - |
|
318 | - $uid = (string)$uid; |
|
319 | - if (!isset($this->cache[$uid])) { |
|
320 | - //guests $uid could be NULL or '' |
|
321 | - if ($uid === '') { |
|
322 | - $this->cache[$uid] = false; |
|
323 | - return true; |
|
324 | - } |
|
325 | - |
|
326 | - $qb = $this->dbConn->getQueryBuilder(); |
|
327 | - $qb->select('uid', 'displayname') |
|
328 | - ->from('users') |
|
329 | - ->where( |
|
330 | - $qb->expr()->eq( |
|
331 | - 'uid_lower', $qb->createNamedParameter(mb_strtolower($uid)) |
|
332 | - ) |
|
333 | - ); |
|
334 | - $result = $qb->execute(); |
|
335 | - $row = $result->fetch(); |
|
336 | - $result->closeCursor(); |
|
337 | - |
|
338 | - $this->cache[$uid] = false; |
|
339 | - |
|
340 | - // "uid" is primary key, so there can only be a single result |
|
341 | - if ($row !== false) { |
|
342 | - $this->cache[$uid]['uid'] = (string)$row['uid']; |
|
343 | - $this->cache[$uid]['displayname'] = (string)$row['displayname']; |
|
344 | - } else { |
|
345 | - return false; |
|
346 | - } |
|
347 | - } |
|
348 | - |
|
349 | - return true; |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Get a list of all users |
|
354 | - * |
|
355 | - * @param string $search |
|
356 | - * @param null|int $limit |
|
357 | - * @param null|int $offset |
|
358 | - * @return string[] an array of all uids |
|
359 | - */ |
|
360 | - public function getUsers($search = '', $limit = null, $offset = null) { |
|
361 | - $users = $this->getDisplayNames($search, $limit, $offset); |
|
362 | - $userIds = array_map(function ($uid) { |
|
363 | - return (string)$uid; |
|
364 | - }, array_keys($users)); |
|
365 | - sort($userIds, SORT_STRING | SORT_FLAG_CASE); |
|
366 | - return $userIds; |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * check if a user exists |
|
371 | - * |
|
372 | - * @param string $uid the username |
|
373 | - * @return boolean |
|
374 | - */ |
|
375 | - public function userExists($uid) { |
|
376 | - $this->loadUser($uid); |
|
377 | - return $this->cache[$uid] !== false; |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * get the user's home directory |
|
382 | - * |
|
383 | - * @param string $uid the username |
|
384 | - * @return string|false |
|
385 | - */ |
|
386 | - public function getHome(string $uid) { |
|
387 | - if ($this->userExists($uid)) { |
|
388 | - return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $uid; |
|
389 | - } |
|
390 | - |
|
391 | - return false; |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * @return bool |
|
396 | - */ |
|
397 | - public function hasUserListings() { |
|
398 | - return true; |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * counts the users in the database |
|
403 | - * |
|
404 | - * @return int|bool |
|
405 | - */ |
|
406 | - public function countUsers() { |
|
407 | - $this->fixDI(); |
|
408 | - |
|
409 | - $query = \OC_DB::prepare('SELECT COUNT(*) FROM `*PREFIX*users`'); |
|
410 | - $result = $query->execute(); |
|
411 | - if ($result === false) { |
|
412 | - Util::writeLog('core', \OC_DB::getErrorMessage(), ILogger::ERROR); |
|
413 | - return false; |
|
414 | - } |
|
415 | - return $result->fetchOne(); |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * returns the username for the given login name in the correct casing |
|
420 | - * |
|
421 | - * @param string $loginName |
|
422 | - * @return string|false |
|
423 | - */ |
|
424 | - public function loginName2UserName($loginName) { |
|
425 | - if ($this->userExists($loginName)) { |
|
426 | - return $this->cache[$loginName]['uid']; |
|
427 | - } |
|
428 | - |
|
429 | - return false; |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Backend name to be shown in user management |
|
434 | - * |
|
435 | - * @return string the name of the backend to be shown |
|
436 | - */ |
|
437 | - public function getBackendName() { |
|
438 | - return 'Database'; |
|
439 | - } |
|
440 | - |
|
441 | - public static function preLoginNameUsedAsUserName($param) { |
|
442 | - if (!isset($param['uid'])) { |
|
443 | - throw new \Exception('key uid is expected to be set in $param'); |
|
444 | - } |
|
445 | - |
|
446 | - $backends = \OC::$server->getUserManager()->getBackends(); |
|
447 | - foreach ($backends as $backend) { |
|
448 | - if ($backend instanceof Database) { |
|
449 | - /** @var \OC\User\Database $backend */ |
|
450 | - $uid = $backend->loginName2UserName($param['uid']); |
|
451 | - if ($uid !== false) { |
|
452 | - $param['uid'] = $uid; |
|
453 | - return; |
|
454 | - } |
|
455 | - } |
|
456 | - } |
|
457 | - |
|
458 | - } |
|
79 | + implements ICreateUserBackend, |
|
80 | + ISetPasswordBackend, |
|
81 | + ISetDisplayNameBackend, |
|
82 | + IGetDisplayNameBackend, |
|
83 | + ICheckPasswordBackend, |
|
84 | + IGetHomeBackend, |
|
85 | + ICountUsersBackend { |
|
86 | + /** @var CappedMemoryCache */ |
|
87 | + private $cache; |
|
88 | + |
|
89 | + /** @var EventDispatcher */ |
|
90 | + private $eventDispatcher; |
|
91 | + |
|
92 | + /** @var IDBConnection */ |
|
93 | + private $dbConn; |
|
94 | + |
|
95 | + /** |
|
96 | + * \OC\User\Database constructor. |
|
97 | + * |
|
98 | + * @param EventDispatcher $eventDispatcher |
|
99 | + */ |
|
100 | + public function __construct($eventDispatcher = null) { |
|
101 | + $this->cache = new CappedMemoryCache(); |
|
102 | + $this->eventDispatcher = $eventDispatcher ? $eventDispatcher : \OC::$server->getEventDispatcher(); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * FIXME: This function should not be required! |
|
107 | + */ |
|
108 | + private function fixDI() { |
|
109 | + if ($this->dbConn === null) { |
|
110 | + $this->dbConn = \OC::$server->getDatabaseConnection(); |
|
111 | + } |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Create a new user |
|
116 | + * |
|
117 | + * @param string $uid The username of the user to create |
|
118 | + * @param string $password The password of the new user |
|
119 | + * @return bool |
|
120 | + * |
|
121 | + * Creates a new user. Basic checking of username is done in OC_User |
|
122 | + * itself, not in its subclasses. |
|
123 | + */ |
|
124 | + public function createUser(string $uid, string $password): bool { |
|
125 | + $this->fixDI(); |
|
126 | + |
|
127 | + if (!$this->userExists($uid)) { |
|
128 | + $event = new GenericEvent($password); |
|
129 | + $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); |
|
130 | + |
|
131 | + $qb = $this->dbConn->getQueryBuilder(); |
|
132 | + $qb->insert('users') |
|
133 | + ->values([ |
|
134 | + 'uid' => $qb->createNamedParameter($uid), |
|
135 | + 'password' => $qb->createNamedParameter(\OC::$server->getHasher()->hash($password)), |
|
136 | + 'uid_lower' => $qb->createNamedParameter(mb_strtolower($uid)), |
|
137 | + ]); |
|
138 | + |
|
139 | + $result = $qb->execute(); |
|
140 | + |
|
141 | + // Clear cache |
|
142 | + unset($this->cache[$uid]); |
|
143 | + |
|
144 | + return $result ? true : false; |
|
145 | + } |
|
146 | + |
|
147 | + return false; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * delete a user |
|
152 | + * |
|
153 | + * @param string $uid The username of the user to delete |
|
154 | + * @return bool |
|
155 | + * |
|
156 | + * Deletes a user |
|
157 | + */ |
|
158 | + public function deleteUser($uid) { |
|
159 | + $this->fixDI(); |
|
160 | + |
|
161 | + // Delete user-group-relation |
|
162 | + $query = \OC_DB::prepare('DELETE FROM `*PREFIX*users` WHERE `uid` = ?'); |
|
163 | + $result = $query->execute([$uid]); |
|
164 | + |
|
165 | + if (isset($this->cache[$uid])) { |
|
166 | + unset($this->cache[$uid]); |
|
167 | + } |
|
168 | + |
|
169 | + return $result ? true : false; |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Set password |
|
174 | + * |
|
175 | + * @param string $uid The username |
|
176 | + * @param string $password The new password |
|
177 | + * @return bool |
|
178 | + * |
|
179 | + * Change the password of a user |
|
180 | + */ |
|
181 | + public function setPassword(string $uid, string $password): bool { |
|
182 | + $this->fixDI(); |
|
183 | + |
|
184 | + if ($this->userExists($uid)) { |
|
185 | + $event = new GenericEvent($password); |
|
186 | + $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); |
|
187 | + $query = \OC_DB::prepare('UPDATE `*PREFIX*users` SET `password` = ? WHERE `uid` = ?'); |
|
188 | + $result = $query->execute([\OC::$server->getHasher()->hash($password), $uid]); |
|
189 | + |
|
190 | + return $result ? true : false; |
|
191 | + } |
|
192 | + |
|
193 | + return false; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Set display name |
|
198 | + * |
|
199 | + * @param string $uid The username |
|
200 | + * @param string $displayName The new display name |
|
201 | + * @return bool |
|
202 | + * |
|
203 | + * Change the display name of a user |
|
204 | + */ |
|
205 | + public function setDisplayName(string $uid, string $displayName): bool { |
|
206 | + $this->fixDI(); |
|
207 | + |
|
208 | + if ($this->userExists($uid)) { |
|
209 | + $query = \OC_DB::prepare('UPDATE `*PREFIX*users` SET `displayname` = ? WHERE LOWER(`uid`) = LOWER(?)'); |
|
210 | + $query->execute([$displayName, $uid]); |
|
211 | + $this->cache[$uid]['displayname'] = $displayName; |
|
212 | + |
|
213 | + return true; |
|
214 | + } |
|
215 | + |
|
216 | + return false; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * get display name of the user |
|
221 | + * |
|
222 | + * @param string $uid user ID of the user |
|
223 | + * @return string display name |
|
224 | + */ |
|
225 | + public function getDisplayName($uid): string { |
|
226 | + $uid = (string)$uid; |
|
227 | + $this->loadUser($uid); |
|
228 | + return empty($this->cache[$uid]['displayname']) ? $uid : $this->cache[$uid]['displayname']; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Get a list of all display names and user ids. |
|
233 | + * |
|
234 | + * @param string $search |
|
235 | + * @param string|null $limit |
|
236 | + * @param string|null $offset |
|
237 | + * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
238 | + */ |
|
239 | + public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
240 | + $this->fixDI(); |
|
241 | + |
|
242 | + $query = $this->dbConn->getQueryBuilder(); |
|
243 | + |
|
244 | + $query->select('uid', 'displayname') |
|
245 | + ->from('users', 'u') |
|
246 | + ->leftJoin('u', 'preferences', 'p', $query->expr()->andX( |
|
247 | + $query->expr()->eq('userid', 'uid'), |
|
248 | + $query->expr()->eq('appid', $query->expr()->literal('settings')), |
|
249 | + $query->expr()->eq('configkey', $query->expr()->literal('email'))) |
|
250 | + ) |
|
251 | + // sqlite doesn't like re-using a single named parameter here |
|
252 | + ->where($query->expr()->iLike('uid', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%'))) |
|
253 | + ->orWhere($query->expr()->iLike('displayname', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%'))) |
|
254 | + ->orWhere($query->expr()->iLike('configvalue', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%'))) |
|
255 | + ->orderBy($query->func()->lower('displayname'), 'ASC') |
|
256 | + ->orderBy($query->func()->lower('uid'), 'ASC') |
|
257 | + ->setMaxResults($limit) |
|
258 | + ->setFirstResult($offset); |
|
259 | + |
|
260 | + $result = $query->execute(); |
|
261 | + $displayNames = []; |
|
262 | + while ($row = $result->fetch()) { |
|
263 | + $displayNames[(string)$row['uid']] = (string)$row['displayname']; |
|
264 | + } |
|
265 | + |
|
266 | + return $displayNames; |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * Check if the password is correct |
|
271 | + * |
|
272 | + * @param string $uid The username |
|
273 | + * @param string $password The password |
|
274 | + * @return string |
|
275 | + * |
|
276 | + * Check if the password is correct without logging in the user |
|
277 | + * returns the user id or false |
|
278 | + */ |
|
279 | + public function checkPassword(string $uid, string $password) { |
|
280 | + $this->fixDI(); |
|
281 | + |
|
282 | + $qb = $this->dbConn->getQueryBuilder(); |
|
283 | + $qb->select('uid', 'password') |
|
284 | + ->from('users') |
|
285 | + ->where( |
|
286 | + $qb->expr()->eq( |
|
287 | + 'uid_lower', $qb->createNamedParameter(mb_strtolower($uid)) |
|
288 | + ) |
|
289 | + ); |
|
290 | + $result = $qb->execute(); |
|
291 | + $row = $result->fetch(); |
|
292 | + $result->closeCursor(); |
|
293 | + |
|
294 | + if ($row) { |
|
295 | + $storedHash = $row['password']; |
|
296 | + $newHash = ''; |
|
297 | + if (\OC::$server->getHasher()->verify($password, $storedHash, $newHash)) { |
|
298 | + if (!empty($newHash)) { |
|
299 | + $this->setPassword($uid, $password); |
|
300 | + } |
|
301 | + return (string)$row['uid']; |
|
302 | + } |
|
303 | + |
|
304 | + } |
|
305 | + |
|
306 | + return false; |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * Load an user in the cache |
|
311 | + * |
|
312 | + * @param string $uid the username |
|
313 | + * @return boolean true if user was found, false otherwise |
|
314 | + */ |
|
315 | + private function loadUser($uid) { |
|
316 | + $this->fixDI(); |
|
317 | + |
|
318 | + $uid = (string)$uid; |
|
319 | + if (!isset($this->cache[$uid])) { |
|
320 | + //guests $uid could be NULL or '' |
|
321 | + if ($uid === '') { |
|
322 | + $this->cache[$uid] = false; |
|
323 | + return true; |
|
324 | + } |
|
325 | + |
|
326 | + $qb = $this->dbConn->getQueryBuilder(); |
|
327 | + $qb->select('uid', 'displayname') |
|
328 | + ->from('users') |
|
329 | + ->where( |
|
330 | + $qb->expr()->eq( |
|
331 | + 'uid_lower', $qb->createNamedParameter(mb_strtolower($uid)) |
|
332 | + ) |
|
333 | + ); |
|
334 | + $result = $qb->execute(); |
|
335 | + $row = $result->fetch(); |
|
336 | + $result->closeCursor(); |
|
337 | + |
|
338 | + $this->cache[$uid] = false; |
|
339 | + |
|
340 | + // "uid" is primary key, so there can only be a single result |
|
341 | + if ($row !== false) { |
|
342 | + $this->cache[$uid]['uid'] = (string)$row['uid']; |
|
343 | + $this->cache[$uid]['displayname'] = (string)$row['displayname']; |
|
344 | + } else { |
|
345 | + return false; |
|
346 | + } |
|
347 | + } |
|
348 | + |
|
349 | + return true; |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Get a list of all users |
|
354 | + * |
|
355 | + * @param string $search |
|
356 | + * @param null|int $limit |
|
357 | + * @param null|int $offset |
|
358 | + * @return string[] an array of all uids |
|
359 | + */ |
|
360 | + public function getUsers($search = '', $limit = null, $offset = null) { |
|
361 | + $users = $this->getDisplayNames($search, $limit, $offset); |
|
362 | + $userIds = array_map(function ($uid) { |
|
363 | + return (string)$uid; |
|
364 | + }, array_keys($users)); |
|
365 | + sort($userIds, SORT_STRING | SORT_FLAG_CASE); |
|
366 | + return $userIds; |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * check if a user exists |
|
371 | + * |
|
372 | + * @param string $uid the username |
|
373 | + * @return boolean |
|
374 | + */ |
|
375 | + public function userExists($uid) { |
|
376 | + $this->loadUser($uid); |
|
377 | + return $this->cache[$uid] !== false; |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * get the user's home directory |
|
382 | + * |
|
383 | + * @param string $uid the username |
|
384 | + * @return string|false |
|
385 | + */ |
|
386 | + public function getHome(string $uid) { |
|
387 | + if ($this->userExists($uid)) { |
|
388 | + return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $uid; |
|
389 | + } |
|
390 | + |
|
391 | + return false; |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * @return bool |
|
396 | + */ |
|
397 | + public function hasUserListings() { |
|
398 | + return true; |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * counts the users in the database |
|
403 | + * |
|
404 | + * @return int|bool |
|
405 | + */ |
|
406 | + public function countUsers() { |
|
407 | + $this->fixDI(); |
|
408 | + |
|
409 | + $query = \OC_DB::prepare('SELECT COUNT(*) FROM `*PREFIX*users`'); |
|
410 | + $result = $query->execute(); |
|
411 | + if ($result === false) { |
|
412 | + Util::writeLog('core', \OC_DB::getErrorMessage(), ILogger::ERROR); |
|
413 | + return false; |
|
414 | + } |
|
415 | + return $result->fetchOne(); |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * returns the username for the given login name in the correct casing |
|
420 | + * |
|
421 | + * @param string $loginName |
|
422 | + * @return string|false |
|
423 | + */ |
|
424 | + public function loginName2UserName($loginName) { |
|
425 | + if ($this->userExists($loginName)) { |
|
426 | + return $this->cache[$loginName]['uid']; |
|
427 | + } |
|
428 | + |
|
429 | + return false; |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Backend name to be shown in user management |
|
434 | + * |
|
435 | + * @return string the name of the backend to be shown |
|
436 | + */ |
|
437 | + public function getBackendName() { |
|
438 | + return 'Database'; |
|
439 | + } |
|
440 | + |
|
441 | + public static function preLoginNameUsedAsUserName($param) { |
|
442 | + if (!isset($param['uid'])) { |
|
443 | + throw new \Exception('key uid is expected to be set in $param'); |
|
444 | + } |
|
445 | + |
|
446 | + $backends = \OC::$server->getUserManager()->getBackends(); |
|
447 | + foreach ($backends as $backend) { |
|
448 | + if ($backend instanceof Database) { |
|
449 | + /** @var \OC\User\Database $backend */ |
|
450 | + $uid = $backend->loginName2UserName($param['uid']); |
|
451 | + if ($uid !== false) { |
|
452 | + $param['uid'] = $uid; |
|
453 | + return; |
|
454 | + } |
|
455 | + } |
|
456 | + } |
|
457 | + |
|
458 | + } |
|
459 | 459 | } |
@@ -52,552 +52,552 @@ |
||
52 | 52 | * This class provides the functionality needed to install, update and remove apps |
53 | 53 | */ |
54 | 54 | class Installer { |
55 | - /** @var AppFetcher */ |
|
56 | - private $appFetcher; |
|
57 | - /** @var IClientService */ |
|
58 | - private $clientService; |
|
59 | - /** @var ITempManager */ |
|
60 | - private $tempManager; |
|
61 | - /** @var ILogger */ |
|
62 | - private $logger; |
|
63 | - /** @var IConfig */ |
|
64 | - private $config; |
|
65 | - /** @var array - for caching the result of app fetcher */ |
|
66 | - private $apps = null; |
|
67 | - /** @var bool|null - for caching the result of the ready status */ |
|
68 | - private $isInstanceReadyForUpdates = null; |
|
69 | - |
|
70 | - /** |
|
71 | - * @param AppFetcher $appFetcher |
|
72 | - * @param IClientService $clientService |
|
73 | - * @param ITempManager $tempManager |
|
74 | - * @param ILogger $logger |
|
75 | - * @param IConfig $config |
|
76 | - */ |
|
77 | - public function __construct(AppFetcher $appFetcher, |
|
78 | - IClientService $clientService, |
|
79 | - ITempManager $tempManager, |
|
80 | - ILogger $logger, |
|
81 | - IConfig $config) { |
|
82 | - $this->appFetcher = $appFetcher; |
|
83 | - $this->clientService = $clientService; |
|
84 | - $this->tempManager = $tempManager; |
|
85 | - $this->logger = $logger; |
|
86 | - $this->config = $config; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Installs an app that is located in one of the app folders already |
|
91 | - * |
|
92 | - * @param string $appId App to install |
|
93 | - * @throws \Exception |
|
94 | - * @return string app ID |
|
95 | - */ |
|
96 | - public function installApp($appId) { |
|
97 | - $app = \OC_App::findAppInDirectories($appId); |
|
98 | - if($app === false) { |
|
99 | - throw new \Exception('App not found in any app directory'); |
|
100 | - } |
|
101 | - |
|
102 | - $basedir = $app['path'].'/'.$appId; |
|
103 | - $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
104 | - |
|
105 | - $l = \OC::$server->getL10N('core'); |
|
106 | - |
|
107 | - if(!is_array($info)) { |
|
108 | - throw new \Exception( |
|
109 | - $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
110 | - [$appId] |
|
111 | - ) |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - $version = implode('.', \OCP\Util::getVersion()); |
|
116 | - if (!\OC_App::isAppCompatible($version, $info)) { |
|
117 | - throw new \Exception( |
|
118 | - // TODO $l |
|
119 | - $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
120 | - [$info['name']] |
|
121 | - ) |
|
122 | - ); |
|
123 | - } |
|
124 | - |
|
125 | - // check for required dependencies |
|
126 | - \OC_App::checkAppDependencies($this->config, $l, $info); |
|
127 | - \OC_App::registerAutoloading($appId, $basedir); |
|
128 | - |
|
129 | - //install the database |
|
130 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
131 | - if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) { |
|
132 | - OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
133 | - } else { |
|
134 | - OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
135 | - } |
|
136 | - } else { |
|
137 | - $ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection()); |
|
138 | - $ms->migrate(); |
|
139 | - } |
|
140 | - |
|
141 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
142 | - |
|
143 | - //run appinfo/install.php |
|
144 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
145 | - |
|
146 | - $appData = OC_App::getAppInfo($appId); |
|
147 | - OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
148 | - |
|
149 | - //set the installed version |
|
150 | - \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
151 | - \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
152 | - |
|
153 | - //set remote/public handlers |
|
154 | - foreach($info['remote'] as $name=>$path) { |
|
155 | - \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
156 | - } |
|
157 | - foreach($info['public'] as $name=>$path) { |
|
158 | - \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
159 | - } |
|
160 | - |
|
161 | - OC_App::setAppTypes($info['id']); |
|
162 | - |
|
163 | - return $info['id']; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Updates the specified app from the appstore |
|
168 | - * |
|
169 | - * @param string $appId |
|
170 | - * @return bool |
|
171 | - */ |
|
172 | - public function updateAppstoreApp($appId) { |
|
173 | - if($this->isUpdateAvailable($appId)) { |
|
174 | - try { |
|
175 | - $this->downloadApp($appId); |
|
176 | - } catch (\Exception $e) { |
|
177 | - $this->logger->logException($e, [ |
|
178 | - 'level' => ILogger::ERROR, |
|
179 | - 'app' => 'core', |
|
180 | - ]); |
|
181 | - return false; |
|
182 | - } |
|
183 | - return OC_App::updateApp($appId); |
|
184 | - } |
|
185 | - |
|
186 | - return false; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Downloads an app and puts it into the app directory |
|
191 | - * |
|
192 | - * @param string $appId |
|
193 | - * |
|
194 | - * @throws \Exception If the installation was not successful |
|
195 | - */ |
|
196 | - public function downloadApp($appId) { |
|
197 | - $appId = strtolower($appId); |
|
198 | - |
|
199 | - $apps = $this->appFetcher->get(); |
|
200 | - foreach($apps as $app) { |
|
201 | - if($app['id'] === $appId) { |
|
202 | - // Load the certificate |
|
203 | - $certificate = new X509(); |
|
204 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
205 | - $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
206 | - |
|
207 | - // Verify if the certificate has been revoked |
|
208 | - $crl = new X509(); |
|
209 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
210 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
211 | - if($crl->validateSignature() !== true) { |
|
212 | - throw new \Exception('Could not validate CRL signature'); |
|
213 | - } |
|
214 | - $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
215 | - $revoked = $crl->getRevoked($csn); |
|
216 | - if ($revoked !== false) { |
|
217 | - throw new \Exception( |
|
218 | - sprintf( |
|
219 | - 'Certificate "%s" has been revoked', |
|
220 | - $csn |
|
221 | - ) |
|
222 | - ); |
|
223 | - } |
|
224 | - |
|
225 | - // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
226 | - if($certificate->validateSignature() !== true) { |
|
227 | - throw new \Exception( |
|
228 | - sprintf( |
|
229 | - 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
230 | - $appId |
|
231 | - ) |
|
232 | - ); |
|
233 | - } |
|
234 | - |
|
235 | - // Verify if the certificate is issued for the requested app id |
|
236 | - $certInfo = openssl_x509_parse($app['certificate']); |
|
237 | - if(!isset($certInfo['subject']['CN'])) { |
|
238 | - throw new \Exception( |
|
239 | - sprintf( |
|
240 | - 'App with id %s has a cert with no CN', |
|
241 | - $appId |
|
242 | - ) |
|
243 | - ); |
|
244 | - } |
|
245 | - if($certInfo['subject']['CN'] !== $appId) { |
|
246 | - throw new \Exception( |
|
247 | - sprintf( |
|
248 | - 'App with id %s has a cert issued to %s', |
|
249 | - $appId, |
|
250 | - $certInfo['subject']['CN'] |
|
251 | - ) |
|
252 | - ); |
|
253 | - } |
|
254 | - |
|
255 | - // Download the release |
|
256 | - $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
257 | - $client = $this->clientService->newClient(); |
|
258 | - $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
259 | - |
|
260 | - // Check if the signature actually matches the downloaded content |
|
261 | - $certificate = openssl_get_publickey($app['certificate']); |
|
262 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
263 | - openssl_free_key($certificate); |
|
264 | - |
|
265 | - if($verified === true) { |
|
266 | - // Seems to match, let's proceed |
|
267 | - $extractDir = $this->tempManager->getTemporaryFolder(); |
|
268 | - $archive = new TAR($tempFile); |
|
269 | - |
|
270 | - if($archive) { |
|
271 | - if (!$archive->extract($extractDir)) { |
|
272 | - throw new \Exception( |
|
273 | - sprintf( |
|
274 | - 'Could not extract app %s', |
|
275 | - $appId |
|
276 | - ) |
|
277 | - ); |
|
278 | - } |
|
279 | - $allFiles = scandir($extractDir); |
|
280 | - $folders = array_diff($allFiles, ['.', '..']); |
|
281 | - $folders = array_values($folders); |
|
282 | - |
|
283 | - if(count($folders) > 1) { |
|
284 | - throw new \Exception( |
|
285 | - sprintf( |
|
286 | - 'Extracted app %s has more than 1 folder', |
|
287 | - $appId |
|
288 | - ) |
|
289 | - ); |
|
290 | - } |
|
291 | - |
|
292 | - // Check if appinfo/info.xml has the same app ID as well |
|
293 | - $loadEntities = libxml_disable_entity_loader(false); |
|
294 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
295 | - libxml_disable_entity_loader($loadEntities); |
|
296 | - if((string)$xml->id !== $appId) { |
|
297 | - throw new \Exception( |
|
298 | - sprintf( |
|
299 | - 'App for id %s has a wrong app ID in info.xml: %s', |
|
300 | - $appId, |
|
301 | - (string)$xml->id |
|
302 | - ) |
|
303 | - ); |
|
304 | - } |
|
305 | - |
|
306 | - // Check if the version is lower than before |
|
307 | - $currentVersion = OC_App::getAppVersion($appId); |
|
308 | - $newVersion = (string)$xml->version; |
|
309 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
310 | - throw new \Exception( |
|
311 | - sprintf( |
|
312 | - 'App for id %s has version %s and tried to update to lower version %s', |
|
313 | - $appId, |
|
314 | - $currentVersion, |
|
315 | - $newVersion |
|
316 | - ) |
|
317 | - ); |
|
318 | - } |
|
319 | - |
|
320 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
321 | - // Remove old app with the ID if existent |
|
322 | - OC_Helper::rmdirr($baseDir); |
|
323 | - // Move to app folder |
|
324 | - if(@mkdir($baseDir)) { |
|
325 | - $extractDir .= '/' . $folders[0]; |
|
326 | - OC_Helper::copyr($extractDir, $baseDir); |
|
327 | - } |
|
328 | - OC_Helper::copyr($extractDir, $baseDir); |
|
329 | - OC_Helper::rmdirr($extractDir); |
|
330 | - return; |
|
331 | - } else { |
|
332 | - throw new \Exception( |
|
333 | - sprintf( |
|
334 | - 'Could not extract app with ID %s to %s', |
|
335 | - $appId, |
|
336 | - $extractDir |
|
337 | - ) |
|
338 | - ); |
|
339 | - } |
|
340 | - } else { |
|
341 | - // Signature does not match |
|
342 | - throw new \Exception( |
|
343 | - sprintf( |
|
344 | - 'App with id %s has invalid signature', |
|
345 | - $appId |
|
346 | - ) |
|
347 | - ); |
|
348 | - } |
|
349 | - } |
|
350 | - } |
|
351 | - |
|
352 | - throw new \Exception( |
|
353 | - sprintf( |
|
354 | - 'Could not download app %s', |
|
355 | - $appId |
|
356 | - ) |
|
357 | - ); |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Check if an update for the app is available |
|
362 | - * |
|
363 | - * @param string $appId |
|
364 | - * @return string|false false or the version number of the update |
|
365 | - */ |
|
366 | - public function isUpdateAvailable($appId) { |
|
367 | - if ($this->isInstanceReadyForUpdates === null) { |
|
368 | - $installPath = OC_App::getInstallPath(); |
|
369 | - if ($installPath === false || $installPath === null) { |
|
370 | - $this->isInstanceReadyForUpdates = false; |
|
371 | - } else { |
|
372 | - $this->isInstanceReadyForUpdates = true; |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - if ($this->isInstanceReadyForUpdates === false) { |
|
377 | - return false; |
|
378 | - } |
|
379 | - |
|
380 | - if ($this->isInstalledFromGit($appId) === true) { |
|
381 | - return false; |
|
382 | - } |
|
383 | - |
|
384 | - if ($this->apps === null) { |
|
385 | - $this->apps = $this->appFetcher->get(); |
|
386 | - } |
|
387 | - |
|
388 | - foreach($this->apps as $app) { |
|
389 | - if($app['id'] === $appId) { |
|
390 | - $currentVersion = OC_App::getAppVersion($appId); |
|
391 | - $newestVersion = $app['releases'][0]['version']; |
|
392 | - if (version_compare($newestVersion, $currentVersion, '>')) { |
|
393 | - return $newestVersion; |
|
394 | - } else { |
|
395 | - return false; |
|
396 | - } |
|
397 | - } |
|
398 | - } |
|
399 | - |
|
400 | - return false; |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Check if app has been installed from git |
|
405 | - * @param string $name name of the application to remove |
|
406 | - * @return boolean |
|
407 | - * |
|
408 | - * The function will check if the path contains a .git folder |
|
409 | - */ |
|
410 | - private function isInstalledFromGit($appId) { |
|
411 | - $app = \OC_App::findAppInDirectories($appId); |
|
412 | - if($app === false) { |
|
413 | - return false; |
|
414 | - } |
|
415 | - $basedir = $app['path'].'/'.$appId; |
|
416 | - return file_exists($basedir.'/.git/'); |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Check if app is already downloaded |
|
421 | - * @param string $name name of the application to remove |
|
422 | - * @return boolean |
|
423 | - * |
|
424 | - * The function will check if the app is already downloaded in the apps repository |
|
425 | - */ |
|
426 | - public function isDownloaded($name) { |
|
427 | - foreach(\OC::$APPSROOTS as $dir) { |
|
428 | - $dirToTest = $dir['path']; |
|
429 | - $dirToTest .= '/'; |
|
430 | - $dirToTest .= $name; |
|
431 | - $dirToTest .= '/'; |
|
432 | - |
|
433 | - if (is_dir($dirToTest)) { |
|
434 | - return true; |
|
435 | - } |
|
436 | - } |
|
437 | - |
|
438 | - return false; |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * Removes an app |
|
443 | - * @param string $appId ID of the application to remove |
|
444 | - * @return boolean |
|
445 | - * |
|
446 | - * |
|
447 | - * This function works as follows |
|
448 | - * -# call uninstall repair steps |
|
449 | - * -# removing the files |
|
450 | - * |
|
451 | - * The function will not delete preferences, tables and the configuration, |
|
452 | - * this has to be done by the function oc_app_uninstall(). |
|
453 | - */ |
|
454 | - public function removeApp($appId) { |
|
455 | - if($this->isDownloaded( $appId )) { |
|
456 | - if (\OC::$server->getAppManager()->isShipped($appId)) { |
|
457 | - return false; |
|
458 | - } |
|
459 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
460 | - OC_Helper::rmdirr($appDir); |
|
461 | - return true; |
|
462 | - }else{ |
|
463 | - \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', ILogger::ERROR); |
|
464 | - |
|
465 | - return false; |
|
466 | - } |
|
467 | - |
|
468 | - } |
|
469 | - |
|
470 | - /** |
|
471 | - * Installs the app within the bundle and marks the bundle as installed |
|
472 | - * |
|
473 | - * @param Bundle $bundle |
|
474 | - * @throws \Exception If app could not get installed |
|
475 | - */ |
|
476 | - public function installAppBundle(Bundle $bundle) { |
|
477 | - $appIds = $bundle->getAppIdentifiers(); |
|
478 | - foreach($appIds as $appId) { |
|
479 | - if(!$this->isDownloaded($appId)) { |
|
480 | - $this->downloadApp($appId); |
|
481 | - } |
|
482 | - $this->installApp($appId); |
|
483 | - $app = new OC_App(); |
|
484 | - $app->enable($appId); |
|
485 | - } |
|
486 | - $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true); |
|
487 | - $bundles[] = $bundle->getIdentifier(); |
|
488 | - $this->config->setAppValue('core', 'installed.bundles', json_encode($bundles)); |
|
489 | - } |
|
490 | - |
|
491 | - /** |
|
492 | - * Installs shipped apps |
|
493 | - * |
|
494 | - * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
495 | - * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
496 | - * working ownCloud at the end instead of an aborted update. |
|
497 | - * @return array Array of error messages (appid => Exception) |
|
498 | - */ |
|
499 | - public static function installShippedApps($softErrors = false) { |
|
500 | - $appManager = \OC::$server->getAppManager(); |
|
501 | - $config = \OC::$server->getConfig(); |
|
502 | - $errors = []; |
|
503 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
504 | - if($dir = opendir( $app_dir['path'] )) { |
|
505 | - while( false !== ( $filename = readdir( $dir ))) { |
|
506 | - if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) { |
|
507 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
508 | - if($config->getAppValue($filename, "installed_version", null) === null) { |
|
509 | - $info=OC_App::getAppInfo($filename); |
|
510 | - $enabled = isset($info['default_enable']); |
|
511 | - if (($enabled || in_array($filename, $appManager->getAlwaysEnabledApps())) |
|
512 | - && $config->getAppValue($filename, 'enabled') !== 'no') { |
|
513 | - if ($softErrors) { |
|
514 | - try { |
|
515 | - Installer::installShippedApp($filename); |
|
516 | - } catch (HintException $e) { |
|
517 | - if ($e->getPrevious() instanceof TableExistsException) { |
|
518 | - $errors[$filename] = $e; |
|
519 | - continue; |
|
520 | - } |
|
521 | - throw $e; |
|
522 | - } |
|
523 | - } else { |
|
524 | - Installer::installShippedApp($filename); |
|
525 | - } |
|
526 | - $config->setAppValue($filename, 'enabled', 'yes'); |
|
527 | - } |
|
528 | - } |
|
529 | - } |
|
530 | - } |
|
531 | - } |
|
532 | - closedir( $dir ); |
|
533 | - } |
|
534 | - } |
|
535 | - |
|
536 | - return $errors; |
|
537 | - } |
|
538 | - |
|
539 | - /** |
|
540 | - * install an app already placed in the app folder |
|
541 | - * @param string $app id of the app to install |
|
542 | - * @return integer |
|
543 | - */ |
|
544 | - public static function installShippedApp($app) { |
|
545 | - //install the database |
|
546 | - $appPath = OC_App::getAppPath($app); |
|
547 | - \OC_App::registerAutoloading($app, $appPath); |
|
548 | - |
|
549 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
550 | - try { |
|
551 | - OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
552 | - } catch (TableExistsException $e) { |
|
553 | - throw new HintException( |
|
554 | - 'Failed to enable app ' . $app, |
|
555 | - 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
|
556 | - 0, $e |
|
557 | - ); |
|
558 | - } |
|
559 | - } else { |
|
560 | - $ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection()); |
|
561 | - $ms->migrate(); |
|
562 | - } |
|
563 | - |
|
564 | - //run appinfo/install.php |
|
565 | - self::includeAppScript("$appPath/appinfo/install.php"); |
|
566 | - |
|
567 | - $info = OC_App::getAppInfo($app); |
|
568 | - if (is_null($info)) { |
|
569 | - return false; |
|
570 | - } |
|
571 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
572 | - |
|
573 | - OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
574 | - |
|
575 | - $config = \OC::$server->getConfig(); |
|
576 | - |
|
577 | - $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
578 | - if (array_key_exists('ocsid', $info)) { |
|
579 | - $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
580 | - } |
|
581 | - |
|
582 | - //set remote/public handlers |
|
583 | - foreach($info['remote'] as $name=>$path) { |
|
584 | - $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
585 | - } |
|
586 | - foreach($info['public'] as $name=>$path) { |
|
587 | - $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
588 | - } |
|
589 | - |
|
590 | - OC_App::setAppTypes($info['id']); |
|
591 | - |
|
592 | - return $info['id']; |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * @param string $script |
|
597 | - */ |
|
598 | - private static function includeAppScript($script) { |
|
599 | - if ( file_exists($script) ){ |
|
600 | - include $script; |
|
601 | - } |
|
602 | - } |
|
55 | + /** @var AppFetcher */ |
|
56 | + private $appFetcher; |
|
57 | + /** @var IClientService */ |
|
58 | + private $clientService; |
|
59 | + /** @var ITempManager */ |
|
60 | + private $tempManager; |
|
61 | + /** @var ILogger */ |
|
62 | + private $logger; |
|
63 | + /** @var IConfig */ |
|
64 | + private $config; |
|
65 | + /** @var array - for caching the result of app fetcher */ |
|
66 | + private $apps = null; |
|
67 | + /** @var bool|null - for caching the result of the ready status */ |
|
68 | + private $isInstanceReadyForUpdates = null; |
|
69 | + |
|
70 | + /** |
|
71 | + * @param AppFetcher $appFetcher |
|
72 | + * @param IClientService $clientService |
|
73 | + * @param ITempManager $tempManager |
|
74 | + * @param ILogger $logger |
|
75 | + * @param IConfig $config |
|
76 | + */ |
|
77 | + public function __construct(AppFetcher $appFetcher, |
|
78 | + IClientService $clientService, |
|
79 | + ITempManager $tempManager, |
|
80 | + ILogger $logger, |
|
81 | + IConfig $config) { |
|
82 | + $this->appFetcher = $appFetcher; |
|
83 | + $this->clientService = $clientService; |
|
84 | + $this->tempManager = $tempManager; |
|
85 | + $this->logger = $logger; |
|
86 | + $this->config = $config; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Installs an app that is located in one of the app folders already |
|
91 | + * |
|
92 | + * @param string $appId App to install |
|
93 | + * @throws \Exception |
|
94 | + * @return string app ID |
|
95 | + */ |
|
96 | + public function installApp($appId) { |
|
97 | + $app = \OC_App::findAppInDirectories($appId); |
|
98 | + if($app === false) { |
|
99 | + throw new \Exception('App not found in any app directory'); |
|
100 | + } |
|
101 | + |
|
102 | + $basedir = $app['path'].'/'.$appId; |
|
103 | + $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
104 | + |
|
105 | + $l = \OC::$server->getL10N('core'); |
|
106 | + |
|
107 | + if(!is_array($info)) { |
|
108 | + throw new \Exception( |
|
109 | + $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
110 | + [$appId] |
|
111 | + ) |
|
112 | + ); |
|
113 | + } |
|
114 | + |
|
115 | + $version = implode('.', \OCP\Util::getVersion()); |
|
116 | + if (!\OC_App::isAppCompatible($version, $info)) { |
|
117 | + throw new \Exception( |
|
118 | + // TODO $l |
|
119 | + $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
120 | + [$info['name']] |
|
121 | + ) |
|
122 | + ); |
|
123 | + } |
|
124 | + |
|
125 | + // check for required dependencies |
|
126 | + \OC_App::checkAppDependencies($this->config, $l, $info); |
|
127 | + \OC_App::registerAutoloading($appId, $basedir); |
|
128 | + |
|
129 | + //install the database |
|
130 | + if(is_file($basedir.'/appinfo/database.xml')) { |
|
131 | + if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) { |
|
132 | + OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
133 | + } else { |
|
134 | + OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
135 | + } |
|
136 | + } else { |
|
137 | + $ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection()); |
|
138 | + $ms->migrate(); |
|
139 | + } |
|
140 | + |
|
141 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
142 | + |
|
143 | + //run appinfo/install.php |
|
144 | + self::includeAppScript($basedir . '/appinfo/install.php'); |
|
145 | + |
|
146 | + $appData = OC_App::getAppInfo($appId); |
|
147 | + OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
148 | + |
|
149 | + //set the installed version |
|
150 | + \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
151 | + \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
152 | + |
|
153 | + //set remote/public handlers |
|
154 | + foreach($info['remote'] as $name=>$path) { |
|
155 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
156 | + } |
|
157 | + foreach($info['public'] as $name=>$path) { |
|
158 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
159 | + } |
|
160 | + |
|
161 | + OC_App::setAppTypes($info['id']); |
|
162 | + |
|
163 | + return $info['id']; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Updates the specified app from the appstore |
|
168 | + * |
|
169 | + * @param string $appId |
|
170 | + * @return bool |
|
171 | + */ |
|
172 | + public function updateAppstoreApp($appId) { |
|
173 | + if($this->isUpdateAvailable($appId)) { |
|
174 | + try { |
|
175 | + $this->downloadApp($appId); |
|
176 | + } catch (\Exception $e) { |
|
177 | + $this->logger->logException($e, [ |
|
178 | + 'level' => ILogger::ERROR, |
|
179 | + 'app' => 'core', |
|
180 | + ]); |
|
181 | + return false; |
|
182 | + } |
|
183 | + return OC_App::updateApp($appId); |
|
184 | + } |
|
185 | + |
|
186 | + return false; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Downloads an app and puts it into the app directory |
|
191 | + * |
|
192 | + * @param string $appId |
|
193 | + * |
|
194 | + * @throws \Exception If the installation was not successful |
|
195 | + */ |
|
196 | + public function downloadApp($appId) { |
|
197 | + $appId = strtolower($appId); |
|
198 | + |
|
199 | + $apps = $this->appFetcher->get(); |
|
200 | + foreach($apps as $app) { |
|
201 | + if($app['id'] === $appId) { |
|
202 | + // Load the certificate |
|
203 | + $certificate = new X509(); |
|
204 | + $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
205 | + $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
206 | + |
|
207 | + // Verify if the certificate has been revoked |
|
208 | + $crl = new X509(); |
|
209 | + $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
210 | + $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
211 | + if($crl->validateSignature() !== true) { |
|
212 | + throw new \Exception('Could not validate CRL signature'); |
|
213 | + } |
|
214 | + $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
215 | + $revoked = $crl->getRevoked($csn); |
|
216 | + if ($revoked !== false) { |
|
217 | + throw new \Exception( |
|
218 | + sprintf( |
|
219 | + 'Certificate "%s" has been revoked', |
|
220 | + $csn |
|
221 | + ) |
|
222 | + ); |
|
223 | + } |
|
224 | + |
|
225 | + // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
226 | + if($certificate->validateSignature() !== true) { |
|
227 | + throw new \Exception( |
|
228 | + sprintf( |
|
229 | + 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
230 | + $appId |
|
231 | + ) |
|
232 | + ); |
|
233 | + } |
|
234 | + |
|
235 | + // Verify if the certificate is issued for the requested app id |
|
236 | + $certInfo = openssl_x509_parse($app['certificate']); |
|
237 | + if(!isset($certInfo['subject']['CN'])) { |
|
238 | + throw new \Exception( |
|
239 | + sprintf( |
|
240 | + 'App with id %s has a cert with no CN', |
|
241 | + $appId |
|
242 | + ) |
|
243 | + ); |
|
244 | + } |
|
245 | + if($certInfo['subject']['CN'] !== $appId) { |
|
246 | + throw new \Exception( |
|
247 | + sprintf( |
|
248 | + 'App with id %s has a cert issued to %s', |
|
249 | + $appId, |
|
250 | + $certInfo['subject']['CN'] |
|
251 | + ) |
|
252 | + ); |
|
253 | + } |
|
254 | + |
|
255 | + // Download the release |
|
256 | + $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
257 | + $client = $this->clientService->newClient(); |
|
258 | + $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
259 | + |
|
260 | + // Check if the signature actually matches the downloaded content |
|
261 | + $certificate = openssl_get_publickey($app['certificate']); |
|
262 | + $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
263 | + openssl_free_key($certificate); |
|
264 | + |
|
265 | + if($verified === true) { |
|
266 | + // Seems to match, let's proceed |
|
267 | + $extractDir = $this->tempManager->getTemporaryFolder(); |
|
268 | + $archive = new TAR($tempFile); |
|
269 | + |
|
270 | + if($archive) { |
|
271 | + if (!$archive->extract($extractDir)) { |
|
272 | + throw new \Exception( |
|
273 | + sprintf( |
|
274 | + 'Could not extract app %s', |
|
275 | + $appId |
|
276 | + ) |
|
277 | + ); |
|
278 | + } |
|
279 | + $allFiles = scandir($extractDir); |
|
280 | + $folders = array_diff($allFiles, ['.', '..']); |
|
281 | + $folders = array_values($folders); |
|
282 | + |
|
283 | + if(count($folders) > 1) { |
|
284 | + throw new \Exception( |
|
285 | + sprintf( |
|
286 | + 'Extracted app %s has more than 1 folder', |
|
287 | + $appId |
|
288 | + ) |
|
289 | + ); |
|
290 | + } |
|
291 | + |
|
292 | + // Check if appinfo/info.xml has the same app ID as well |
|
293 | + $loadEntities = libxml_disable_entity_loader(false); |
|
294 | + $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
295 | + libxml_disable_entity_loader($loadEntities); |
|
296 | + if((string)$xml->id !== $appId) { |
|
297 | + throw new \Exception( |
|
298 | + sprintf( |
|
299 | + 'App for id %s has a wrong app ID in info.xml: %s', |
|
300 | + $appId, |
|
301 | + (string)$xml->id |
|
302 | + ) |
|
303 | + ); |
|
304 | + } |
|
305 | + |
|
306 | + // Check if the version is lower than before |
|
307 | + $currentVersion = OC_App::getAppVersion($appId); |
|
308 | + $newVersion = (string)$xml->version; |
|
309 | + if(version_compare($currentVersion, $newVersion) === 1) { |
|
310 | + throw new \Exception( |
|
311 | + sprintf( |
|
312 | + 'App for id %s has version %s and tried to update to lower version %s', |
|
313 | + $appId, |
|
314 | + $currentVersion, |
|
315 | + $newVersion |
|
316 | + ) |
|
317 | + ); |
|
318 | + } |
|
319 | + |
|
320 | + $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
321 | + // Remove old app with the ID if existent |
|
322 | + OC_Helper::rmdirr($baseDir); |
|
323 | + // Move to app folder |
|
324 | + if(@mkdir($baseDir)) { |
|
325 | + $extractDir .= '/' . $folders[0]; |
|
326 | + OC_Helper::copyr($extractDir, $baseDir); |
|
327 | + } |
|
328 | + OC_Helper::copyr($extractDir, $baseDir); |
|
329 | + OC_Helper::rmdirr($extractDir); |
|
330 | + return; |
|
331 | + } else { |
|
332 | + throw new \Exception( |
|
333 | + sprintf( |
|
334 | + 'Could not extract app with ID %s to %s', |
|
335 | + $appId, |
|
336 | + $extractDir |
|
337 | + ) |
|
338 | + ); |
|
339 | + } |
|
340 | + } else { |
|
341 | + // Signature does not match |
|
342 | + throw new \Exception( |
|
343 | + sprintf( |
|
344 | + 'App with id %s has invalid signature', |
|
345 | + $appId |
|
346 | + ) |
|
347 | + ); |
|
348 | + } |
|
349 | + } |
|
350 | + } |
|
351 | + |
|
352 | + throw new \Exception( |
|
353 | + sprintf( |
|
354 | + 'Could not download app %s', |
|
355 | + $appId |
|
356 | + ) |
|
357 | + ); |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Check if an update for the app is available |
|
362 | + * |
|
363 | + * @param string $appId |
|
364 | + * @return string|false false or the version number of the update |
|
365 | + */ |
|
366 | + public function isUpdateAvailable($appId) { |
|
367 | + if ($this->isInstanceReadyForUpdates === null) { |
|
368 | + $installPath = OC_App::getInstallPath(); |
|
369 | + if ($installPath === false || $installPath === null) { |
|
370 | + $this->isInstanceReadyForUpdates = false; |
|
371 | + } else { |
|
372 | + $this->isInstanceReadyForUpdates = true; |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + if ($this->isInstanceReadyForUpdates === false) { |
|
377 | + return false; |
|
378 | + } |
|
379 | + |
|
380 | + if ($this->isInstalledFromGit($appId) === true) { |
|
381 | + return false; |
|
382 | + } |
|
383 | + |
|
384 | + if ($this->apps === null) { |
|
385 | + $this->apps = $this->appFetcher->get(); |
|
386 | + } |
|
387 | + |
|
388 | + foreach($this->apps as $app) { |
|
389 | + if($app['id'] === $appId) { |
|
390 | + $currentVersion = OC_App::getAppVersion($appId); |
|
391 | + $newestVersion = $app['releases'][0]['version']; |
|
392 | + if (version_compare($newestVersion, $currentVersion, '>')) { |
|
393 | + return $newestVersion; |
|
394 | + } else { |
|
395 | + return false; |
|
396 | + } |
|
397 | + } |
|
398 | + } |
|
399 | + |
|
400 | + return false; |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Check if app has been installed from git |
|
405 | + * @param string $name name of the application to remove |
|
406 | + * @return boolean |
|
407 | + * |
|
408 | + * The function will check if the path contains a .git folder |
|
409 | + */ |
|
410 | + private function isInstalledFromGit($appId) { |
|
411 | + $app = \OC_App::findAppInDirectories($appId); |
|
412 | + if($app === false) { |
|
413 | + return false; |
|
414 | + } |
|
415 | + $basedir = $app['path'].'/'.$appId; |
|
416 | + return file_exists($basedir.'/.git/'); |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Check if app is already downloaded |
|
421 | + * @param string $name name of the application to remove |
|
422 | + * @return boolean |
|
423 | + * |
|
424 | + * The function will check if the app is already downloaded in the apps repository |
|
425 | + */ |
|
426 | + public function isDownloaded($name) { |
|
427 | + foreach(\OC::$APPSROOTS as $dir) { |
|
428 | + $dirToTest = $dir['path']; |
|
429 | + $dirToTest .= '/'; |
|
430 | + $dirToTest .= $name; |
|
431 | + $dirToTest .= '/'; |
|
432 | + |
|
433 | + if (is_dir($dirToTest)) { |
|
434 | + return true; |
|
435 | + } |
|
436 | + } |
|
437 | + |
|
438 | + return false; |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Removes an app |
|
443 | + * @param string $appId ID of the application to remove |
|
444 | + * @return boolean |
|
445 | + * |
|
446 | + * |
|
447 | + * This function works as follows |
|
448 | + * -# call uninstall repair steps |
|
449 | + * -# removing the files |
|
450 | + * |
|
451 | + * The function will not delete preferences, tables and the configuration, |
|
452 | + * this has to be done by the function oc_app_uninstall(). |
|
453 | + */ |
|
454 | + public function removeApp($appId) { |
|
455 | + if($this->isDownloaded( $appId )) { |
|
456 | + if (\OC::$server->getAppManager()->isShipped($appId)) { |
|
457 | + return false; |
|
458 | + } |
|
459 | + $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
460 | + OC_Helper::rmdirr($appDir); |
|
461 | + return true; |
|
462 | + }else{ |
|
463 | + \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', ILogger::ERROR); |
|
464 | + |
|
465 | + return false; |
|
466 | + } |
|
467 | + |
|
468 | + } |
|
469 | + |
|
470 | + /** |
|
471 | + * Installs the app within the bundle and marks the bundle as installed |
|
472 | + * |
|
473 | + * @param Bundle $bundle |
|
474 | + * @throws \Exception If app could not get installed |
|
475 | + */ |
|
476 | + public function installAppBundle(Bundle $bundle) { |
|
477 | + $appIds = $bundle->getAppIdentifiers(); |
|
478 | + foreach($appIds as $appId) { |
|
479 | + if(!$this->isDownloaded($appId)) { |
|
480 | + $this->downloadApp($appId); |
|
481 | + } |
|
482 | + $this->installApp($appId); |
|
483 | + $app = new OC_App(); |
|
484 | + $app->enable($appId); |
|
485 | + } |
|
486 | + $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true); |
|
487 | + $bundles[] = $bundle->getIdentifier(); |
|
488 | + $this->config->setAppValue('core', 'installed.bundles', json_encode($bundles)); |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * Installs shipped apps |
|
493 | + * |
|
494 | + * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
495 | + * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
496 | + * working ownCloud at the end instead of an aborted update. |
|
497 | + * @return array Array of error messages (appid => Exception) |
|
498 | + */ |
|
499 | + public static function installShippedApps($softErrors = false) { |
|
500 | + $appManager = \OC::$server->getAppManager(); |
|
501 | + $config = \OC::$server->getConfig(); |
|
502 | + $errors = []; |
|
503 | + foreach(\OC::$APPSROOTS as $app_dir) { |
|
504 | + if($dir = opendir( $app_dir['path'] )) { |
|
505 | + while( false !== ( $filename = readdir( $dir ))) { |
|
506 | + if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) { |
|
507 | + if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
508 | + if($config->getAppValue($filename, "installed_version", null) === null) { |
|
509 | + $info=OC_App::getAppInfo($filename); |
|
510 | + $enabled = isset($info['default_enable']); |
|
511 | + if (($enabled || in_array($filename, $appManager->getAlwaysEnabledApps())) |
|
512 | + && $config->getAppValue($filename, 'enabled') !== 'no') { |
|
513 | + if ($softErrors) { |
|
514 | + try { |
|
515 | + Installer::installShippedApp($filename); |
|
516 | + } catch (HintException $e) { |
|
517 | + if ($e->getPrevious() instanceof TableExistsException) { |
|
518 | + $errors[$filename] = $e; |
|
519 | + continue; |
|
520 | + } |
|
521 | + throw $e; |
|
522 | + } |
|
523 | + } else { |
|
524 | + Installer::installShippedApp($filename); |
|
525 | + } |
|
526 | + $config->setAppValue($filename, 'enabled', 'yes'); |
|
527 | + } |
|
528 | + } |
|
529 | + } |
|
530 | + } |
|
531 | + } |
|
532 | + closedir( $dir ); |
|
533 | + } |
|
534 | + } |
|
535 | + |
|
536 | + return $errors; |
|
537 | + } |
|
538 | + |
|
539 | + /** |
|
540 | + * install an app already placed in the app folder |
|
541 | + * @param string $app id of the app to install |
|
542 | + * @return integer |
|
543 | + */ |
|
544 | + public static function installShippedApp($app) { |
|
545 | + //install the database |
|
546 | + $appPath = OC_App::getAppPath($app); |
|
547 | + \OC_App::registerAutoloading($app, $appPath); |
|
548 | + |
|
549 | + if(is_file("$appPath/appinfo/database.xml")) { |
|
550 | + try { |
|
551 | + OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
552 | + } catch (TableExistsException $e) { |
|
553 | + throw new HintException( |
|
554 | + 'Failed to enable app ' . $app, |
|
555 | + 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', |
|
556 | + 0, $e |
|
557 | + ); |
|
558 | + } |
|
559 | + } else { |
|
560 | + $ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection()); |
|
561 | + $ms->migrate(); |
|
562 | + } |
|
563 | + |
|
564 | + //run appinfo/install.php |
|
565 | + self::includeAppScript("$appPath/appinfo/install.php"); |
|
566 | + |
|
567 | + $info = OC_App::getAppInfo($app); |
|
568 | + if (is_null($info)) { |
|
569 | + return false; |
|
570 | + } |
|
571 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
572 | + |
|
573 | + OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
574 | + |
|
575 | + $config = \OC::$server->getConfig(); |
|
576 | + |
|
577 | + $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
578 | + if (array_key_exists('ocsid', $info)) { |
|
579 | + $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
580 | + } |
|
581 | + |
|
582 | + //set remote/public handlers |
|
583 | + foreach($info['remote'] as $name=>$path) { |
|
584 | + $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
585 | + } |
|
586 | + foreach($info['public'] as $name=>$path) { |
|
587 | + $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
588 | + } |
|
589 | + |
|
590 | + OC_App::setAppTypes($info['id']); |
|
591 | + |
|
592 | + return $info['id']; |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * @param string $script |
|
597 | + */ |
|
598 | + private static function includeAppScript($script) { |
|
599 | + if ( file_exists($script) ){ |
|
600 | + include $script; |
|
601 | + } |
|
602 | + } |
|
603 | 603 | } |
@@ -57,505 +57,505 @@ |
||
57 | 57 | * @since 4.0.0 |
58 | 58 | */ |
59 | 59 | class Util { |
60 | - /** |
|
61 | - * @deprecated 14.0.0 use \OCP\ILogger::DEBUG |
|
62 | - */ |
|
63 | - const DEBUG=0; |
|
64 | - /** |
|
65 | - * @deprecated 14.0.0 use \OCP\ILogger::INFO |
|
66 | - */ |
|
67 | - const INFO=1; |
|
68 | - /** |
|
69 | - * @deprecated 14.0.0 use \OCP\ILogger::WARN |
|
70 | - */ |
|
71 | - const WARN=2; |
|
72 | - /** |
|
73 | - * @deprecated 14.0.0 use \OCP\ILogger::ERROR |
|
74 | - */ |
|
75 | - const ERROR=3; |
|
76 | - /** |
|
77 | - * @deprecated 14.0.0 use \OCP\ILogger::FATAL |
|
78 | - */ |
|
79 | - const FATAL=4; |
|
80 | - |
|
81 | - /** \OCP\Share\IManager */ |
|
82 | - private static $shareManager; |
|
83 | - |
|
84 | - /** |
|
85 | - * get the current installed version of ownCloud |
|
86 | - * @return array |
|
87 | - * @since 4.0.0 |
|
88 | - */ |
|
89 | - public static function getVersion() { |
|
90 | - return \OC_Util::getVersion(); |
|
91 | - } |
|
60 | + /** |
|
61 | + * @deprecated 14.0.0 use \OCP\ILogger::DEBUG |
|
62 | + */ |
|
63 | + const DEBUG=0; |
|
64 | + /** |
|
65 | + * @deprecated 14.0.0 use \OCP\ILogger::INFO |
|
66 | + */ |
|
67 | + const INFO=1; |
|
68 | + /** |
|
69 | + * @deprecated 14.0.0 use \OCP\ILogger::WARN |
|
70 | + */ |
|
71 | + const WARN=2; |
|
72 | + /** |
|
73 | + * @deprecated 14.0.0 use \OCP\ILogger::ERROR |
|
74 | + */ |
|
75 | + const ERROR=3; |
|
76 | + /** |
|
77 | + * @deprecated 14.0.0 use \OCP\ILogger::FATAL |
|
78 | + */ |
|
79 | + const FATAL=4; |
|
80 | + |
|
81 | + /** \OCP\Share\IManager */ |
|
82 | + private static $shareManager; |
|
83 | + |
|
84 | + /** |
|
85 | + * get the current installed version of ownCloud |
|
86 | + * @return array |
|
87 | + * @since 4.0.0 |
|
88 | + */ |
|
89 | + public static function getVersion() { |
|
90 | + return \OC_Util::getVersion(); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Set current update channel |
|
95 | - * @param string $channel |
|
96 | - * @since 8.1.0 |
|
97 | - */ |
|
98 | - public static function setChannel($channel) { |
|
99 | - \OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel); |
|
100 | - } |
|
93 | + /** |
|
94 | + * Set current update channel |
|
95 | + * @param string $channel |
|
96 | + * @since 8.1.0 |
|
97 | + */ |
|
98 | + public static function setChannel($channel) { |
|
99 | + \OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Get current update channel |
|
104 | - * @return string |
|
105 | - * @since 8.1.0 |
|
106 | - */ |
|
107 | - public static function getChannel() { |
|
108 | - return \OC_Util::getChannel(); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * write a message in the log |
|
113 | - * @param string $app |
|
114 | - * @param string $message |
|
115 | - * @param int $level |
|
116 | - * @since 4.0.0 |
|
117 | - * @deprecated 13.0.0 use log of \OCP\ILogger |
|
118 | - */ |
|
119 | - public static function writeLog( $app, $message, $level ) { |
|
120 | - $context = ['app' => $app]; |
|
121 | - \OC::$server->getLogger()->log($level, $message, $context); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * write exception into the log |
|
126 | - * @param string $app app name |
|
127 | - * @param \Exception $ex exception to log |
|
128 | - * @param int $level log level, defaults to \OCP\Util::FATAL |
|
129 | - * @since ....0.0 - parameter $level was added in 7.0.0 |
|
130 | - * @deprecated 8.2.0 use logException of \OCP\ILogger |
|
131 | - */ |
|
132 | - public static function logException( $app, \Exception $ex, $level = ILogger::FATAL) { |
|
133 | - \OC::$server->getLogger()->logException($ex, ['app' => $app]); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * check if sharing is disabled for the current user |
|
138 | - * |
|
139 | - * @return boolean |
|
140 | - * @since 7.0.0 |
|
141 | - * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser |
|
142 | - */ |
|
143 | - public static function isSharingDisabledForUser() { |
|
144 | - if (self::$shareManager === null) { |
|
145 | - self::$shareManager = \OC::$server->getShareManager(); |
|
146 | - } |
|
147 | - |
|
148 | - $user = \OC::$server->getUserSession()->getUser(); |
|
149 | - if ($user !== null) { |
|
150 | - $user = $user->getUID(); |
|
151 | - } |
|
152 | - |
|
153 | - return self::$shareManager->sharingDisabledForUser($user); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * get l10n object |
|
158 | - * @param string $application |
|
159 | - * @param string|null $language |
|
160 | - * @return \OCP\IL10N |
|
161 | - * @since 6.0.0 - parameter $language was added in 8.0.0 |
|
162 | - */ |
|
163 | - public static function getL10N($application, $language = null) { |
|
164 | - return \OC::$server->getL10N($application, $language); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * add a css file |
|
169 | - * @param string $application |
|
170 | - * @param string $file |
|
171 | - * @since 4.0.0 |
|
172 | - */ |
|
173 | - public static function addStyle( $application, $file = null ) { |
|
174 | - \OC_Util::addStyle( $application, $file ); |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * add a javascript file |
|
179 | - * @param string $application |
|
180 | - * @param string $file |
|
181 | - * @since 4.0.0 |
|
182 | - */ |
|
183 | - public static function addScript( $application, $file = null ) { |
|
184 | - \OC_Util::addScript( $application, $file ); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Add a translation JS file |
|
189 | - * @param string $application application id |
|
190 | - * @param string $languageCode language code, defaults to the current locale |
|
191 | - * @since 8.0.0 |
|
192 | - */ |
|
193 | - public static function addTranslations($application, $languageCode = null) { |
|
194 | - \OC_Util::addTranslations($application, $languageCode); |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Add a custom element to the header |
|
199 | - * If $text is null then the element will be written as empty element. |
|
200 | - * So use "" to get a closing tag. |
|
201 | - * @param string $tag tag name of the element |
|
202 | - * @param array $attributes array of attributes for the element |
|
203 | - * @param string $text the text content for the element |
|
204 | - * @since 4.0.0 |
|
205 | - */ |
|
206 | - public static function addHeader($tag, $attributes, $text=null) { |
|
207 | - \OC_Util::addHeader($tag, $attributes, $text); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Creates an absolute url to the given app and file. |
|
212 | - * @param string $app app |
|
213 | - * @param string $file file |
|
214 | - * @param array $args array with param=>value, will be appended to the returned url |
|
215 | - * The value of $args will be urlencoded |
|
216 | - * @return string the url |
|
217 | - * @since 4.0.0 - parameter $args was added in 4.5.0 |
|
218 | - */ |
|
219 | - public static function linkToAbsolute( $app, $file, $args = array() ) { |
|
220 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
221 | - return $urlGenerator->getAbsoluteURL( |
|
222 | - $urlGenerator->linkTo($app, $file, $args) |
|
223 | - ); |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Creates an absolute url for remote use. |
|
228 | - * @param string $service id |
|
229 | - * @return string the url |
|
230 | - * @since 4.0.0 |
|
231 | - */ |
|
232 | - public static function linkToRemote( $service ) { |
|
233 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
234 | - $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service; |
|
235 | - return $urlGenerator->getAbsoluteURL( |
|
236 | - $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '') |
|
237 | - ); |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * Creates an absolute url for public use |
|
242 | - * @param string $service id |
|
243 | - * @return string the url |
|
244 | - * @since 4.5.0 |
|
245 | - */ |
|
246 | - public static function linkToPublic($service) { |
|
247 | - return \OC_Helper::linkToPublic($service); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Returns the server host name without an eventual port number |
|
252 | - * @return string the server hostname |
|
253 | - * @since 5.0.0 |
|
254 | - */ |
|
255 | - public static function getServerHostName() { |
|
256 | - $host_name = \OC::$server->getRequest()->getServerHost(); |
|
257 | - // strip away port number (if existing) |
|
258 | - $colon_pos = strpos($host_name, ':'); |
|
259 | - if ($colon_pos != FALSE) { |
|
260 | - $host_name = substr($host_name, 0, $colon_pos); |
|
261 | - } |
|
262 | - return $host_name; |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Returns the default email address |
|
267 | - * @param string $user_part the user part of the address |
|
268 | - * @return string the default email address |
|
269 | - * |
|
270 | - * Assembles a default email address (using the server hostname |
|
271 | - * and the given user part, and returns it |
|
272 | - * Example: when given lostpassword-noreply as $user_part param, |
|
273 | - * and is currently accessed via http(s)://example.com/, |
|
274 | - * it would return '[email protected]' |
|
275 | - * |
|
276 | - * If the configuration value 'mail_from_address' is set in |
|
277 | - * config.php, this value will override the $user_part that |
|
278 | - * is passed to this function |
|
279 | - * @since 5.0.0 |
|
280 | - */ |
|
281 | - public static function getDefaultEmailAddress($user_part) { |
|
282 | - $config = \OC::$server->getConfig(); |
|
283 | - $user_part = $config->getSystemValue('mail_from_address', $user_part); |
|
284 | - $host_name = self::getServerHostName(); |
|
285 | - $host_name = $config->getSystemValue('mail_domain', $host_name); |
|
286 | - $defaultEmailAddress = $user_part.'@'.$host_name; |
|
287 | - |
|
288 | - $mailer = \OC::$server->getMailer(); |
|
289 | - if ($mailer->validateMailAddress($defaultEmailAddress)) { |
|
290 | - return $defaultEmailAddress; |
|
291 | - } |
|
292 | - |
|
293 | - // in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain' |
|
294 | - return $user_part.'@localhost.localdomain'; |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Make a human file size (2048 to 2 kB) |
|
299 | - * @param int $bytes file size in bytes |
|
300 | - * @return string a human readable file size |
|
301 | - * @since 4.0.0 |
|
302 | - */ |
|
303 | - public static function humanFileSize($bytes) { |
|
304 | - return \OC_Helper::humanFileSize($bytes); |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Make a computer file size (2 kB to 2048) |
|
309 | - * @param string $str file size in a fancy format |
|
310 | - * @return float a file size in bytes |
|
311 | - * |
|
312 | - * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418 |
|
313 | - * @since 4.0.0 |
|
314 | - */ |
|
315 | - public static function computerFileSize($str) { |
|
316 | - return \OC_Helper::computerFileSize($str); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * connects a function to a hook |
|
321 | - * |
|
322 | - * @param string $signalClass class name of emitter |
|
323 | - * @param string $signalName name of signal |
|
324 | - * @param string|object $slotClass class name of slot |
|
325 | - * @param string $slotName name of slot |
|
326 | - * @return bool |
|
327 | - * |
|
328 | - * This function makes it very easy to connect to use hooks. |
|
329 | - * |
|
330 | - * TODO: write example |
|
331 | - * @since 4.0.0 |
|
332 | - */ |
|
333 | - static public function connectHook($signalClass, $signalName, $slotClass, $slotName) { |
|
334 | - return \OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName); |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Emits a signal. To get data from the slot use references! |
|
339 | - * @param string $signalclass class name of emitter |
|
340 | - * @param string $signalname name of signal |
|
341 | - * @param array $params default: array() array with additional data |
|
342 | - * @return bool true if slots exists or false if not |
|
343 | - * |
|
344 | - * TODO: write example |
|
345 | - * @since 4.0.0 |
|
346 | - */ |
|
347 | - static public function emitHook($signalclass, $signalname, $params = array()) { |
|
348 | - return \OC_Hook::emit($signalclass, $signalname, $params); |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare |
|
353 | - * multiple OC_Template elements which invoke `callRegister`. If the value |
|
354 | - * would not be cached these unit-tests would fail. |
|
355 | - * @var string |
|
356 | - */ |
|
357 | - private static $token = ''; |
|
358 | - |
|
359 | - /** |
|
360 | - * Register an get/post call. This is important to prevent CSRF attacks |
|
361 | - * @since 4.5.0 |
|
362 | - */ |
|
363 | - public static function callRegister() { |
|
364 | - if(self::$token === '') { |
|
365 | - self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue(); |
|
366 | - } |
|
367 | - return self::$token; |
|
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * Check an ajax get/post call if the request token is valid. exit if not. |
|
372 | - * @since 4.5.0 |
|
373 | - * @deprecated 9.0.0 Use annotations based on the app framework. |
|
374 | - */ |
|
375 | - public static function callCheck() { |
|
376 | - if(!\OC::$server->getRequest()->passesStrictCookieCheck()) { |
|
377 | - header('Location: '.\OC::$WEBROOT); |
|
378 | - exit(); |
|
379 | - } |
|
380 | - |
|
381 | - if (!\OC::$server->getRequest()->passesCSRFCheck()) { |
|
382 | - exit(); |
|
383 | - } |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Used to sanitize HTML |
|
388 | - * |
|
389 | - * This function is used to sanitize HTML and should be applied on any |
|
390 | - * string or array of strings before displaying it on a web page. |
|
391 | - * |
|
392 | - * @param string|array $value |
|
393 | - * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
394 | - * @since 4.5.0 |
|
395 | - */ |
|
396 | - public static function sanitizeHTML($value) { |
|
397 | - return \OC_Util::sanitizeHTML($value); |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * Public function to encode url parameters |
|
402 | - * |
|
403 | - * This function is used to encode path to file before output. |
|
404 | - * Encoding is done according to RFC 3986 with one exception: |
|
405 | - * Character '/' is preserved as is. |
|
406 | - * |
|
407 | - * @param string $component part of URI to encode |
|
408 | - * @return string |
|
409 | - * @since 6.0.0 |
|
410 | - */ |
|
411 | - public static function encodePath($component) { |
|
412 | - return \OC_Util::encodePath($component); |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. |
|
417 | - * |
|
418 | - * @param array $input The array to work on |
|
419 | - * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default) |
|
420 | - * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 |
|
421 | - * @return array |
|
422 | - * @since 4.5.0 |
|
423 | - */ |
|
424 | - public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') { |
|
425 | - return \OC_Helper::mb_array_change_key_case($input, $case, $encoding); |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * replaces a copy of string delimited by the start and (optionally) length parameters with the string given in replacement. |
|
430 | - * |
|
431 | - * @param string $string The input string. Opposite to the PHP build-in function does not accept an array. |
|
432 | - * @param string $replacement The replacement string. |
|
433 | - * @param int $start If start is positive, the replacing will begin at the start'th offset into string. If start is negative, the replacing will begin at the start'th character from the end of string. |
|
434 | - * @param int $length Length of the part to be replaced |
|
435 | - * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 |
|
436 | - * @return string |
|
437 | - * @since 4.5.0 |
|
438 | - * @deprecated 8.2.0 Use substr_replace() instead. |
|
439 | - */ |
|
440 | - public static function mb_substr_replace($string, $replacement, $start, $length = null, $encoding = 'UTF-8') { |
|
441 | - return substr_replace($string, $replacement, $start, $length); |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * Replace all occurrences of the search string with the replacement string |
|
446 | - * |
|
447 | - * @param string $search The value being searched for, otherwise known as the needle. String. |
|
448 | - * @param string $replace The replacement string. |
|
449 | - * @param string $subject The string or array being searched and replaced on, otherwise known as the haystack. |
|
450 | - * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 |
|
451 | - * @param int $count If passed, this will be set to the number of replacements performed. |
|
452 | - * @return string |
|
453 | - * @since 4.5.0 |
|
454 | - * @deprecated 8.2.0 Use str_replace() instead. |
|
455 | - */ |
|
456 | - public static function mb_str_replace($search, $replace, $subject, $encoding = 'UTF-8', &$count = null) { |
|
457 | - return str_replace($search, $replace, $subject, $count); |
|
458 | - } |
|
459 | - |
|
460 | - /** |
|
461 | - * performs a search in a nested array |
|
462 | - * |
|
463 | - * @param array $haystack the array to be searched |
|
464 | - * @param string $needle the search string |
|
465 | - * @param mixed $index optional, only search this key name |
|
466 | - * @return mixed the key of the matching field, otherwise false |
|
467 | - * @since 4.5.0 |
|
468 | - */ |
|
469 | - public static function recursiveArraySearch($haystack, $needle, $index = null) { |
|
470 | - return \OC_Helper::recursiveArraySearch($haystack, $needle, $index); |
|
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * calculates the maximum upload size respecting system settings, free space and user quota |
|
475 | - * |
|
476 | - * @param string $dir the current folder where the user currently operates |
|
477 | - * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly |
|
478 | - * @return int number of bytes representing |
|
479 | - * @since 5.0.0 |
|
480 | - */ |
|
481 | - public static function maxUploadFilesize($dir, $free = null) { |
|
482 | - return \OC_Helper::maxUploadFilesize($dir, $free); |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * Calculate free space left within user quota |
|
487 | - * @param string $dir the current folder where the user currently operates |
|
488 | - * @return int number of bytes representing |
|
489 | - * @since 7.0.0 |
|
490 | - */ |
|
491 | - public static function freeSpace($dir) { |
|
492 | - return \OC_Helper::freeSpace($dir); |
|
493 | - } |
|
494 | - |
|
495 | - /** |
|
496 | - * Calculate PHP upload limit |
|
497 | - * |
|
498 | - * @return int number of bytes representing |
|
499 | - * @since 7.0.0 |
|
500 | - */ |
|
501 | - public static function uploadLimit() { |
|
502 | - return \OC_Helper::uploadLimit(); |
|
503 | - } |
|
504 | - |
|
505 | - /** |
|
506 | - * Returns whether the given file name is valid |
|
507 | - * @param string $file file name to check |
|
508 | - * @return bool true if the file name is valid, false otherwise |
|
509 | - * @deprecated 8.1.0 use \OC\Files\View::verifyPath() |
|
510 | - * @since 7.0.0 |
|
511 | - * @suppress PhanDeprecatedFunction |
|
512 | - */ |
|
513 | - public static function isValidFileName($file) { |
|
514 | - return \OC_Util::isValidFileName($file); |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * Compare two strings to provide a natural sort |
|
519 | - * @param string $a first string to compare |
|
520 | - * @param string $b second string to compare |
|
521 | - * @return int -1 if $b comes before $a, 1 if $a comes before $b |
|
522 | - * or 0 if the strings are identical |
|
523 | - * @since 7.0.0 |
|
524 | - */ |
|
525 | - public static function naturalSortCompare($a, $b) { |
|
526 | - return \OC\NaturalSort::getInstance()->compare($a, $b); |
|
527 | - } |
|
528 | - |
|
529 | - /** |
|
530 | - * check if a password is required for each public link |
|
531 | - * @return boolean |
|
532 | - * @since 7.0.0 |
|
533 | - */ |
|
534 | - public static function isPublicLinkPasswordRequired() { |
|
535 | - return \OC_Util::isPublicLinkPasswordRequired(); |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * check if share API enforces a default expire date |
|
540 | - * @return boolean |
|
541 | - * @since 8.0.0 |
|
542 | - */ |
|
543 | - public static function isDefaultExpireDateEnforced() { |
|
544 | - return \OC_Util::isDefaultExpireDateEnforced(); |
|
545 | - } |
|
546 | - |
|
547 | - protected static $needUpgradeCache = null; |
|
548 | - |
|
549 | - /** |
|
550 | - * Checks whether the current version needs upgrade. |
|
551 | - * |
|
552 | - * @return bool true if upgrade is needed, false otherwise |
|
553 | - * @since 7.0.0 |
|
554 | - */ |
|
555 | - public static function needUpgrade() { |
|
556 | - if (!isset(self::$needUpgradeCache)) { |
|
557 | - self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig()); |
|
558 | - } |
|
559 | - return self::$needUpgradeCache; |
|
560 | - } |
|
102 | + /** |
|
103 | + * Get current update channel |
|
104 | + * @return string |
|
105 | + * @since 8.1.0 |
|
106 | + */ |
|
107 | + public static function getChannel() { |
|
108 | + return \OC_Util::getChannel(); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * write a message in the log |
|
113 | + * @param string $app |
|
114 | + * @param string $message |
|
115 | + * @param int $level |
|
116 | + * @since 4.0.0 |
|
117 | + * @deprecated 13.0.0 use log of \OCP\ILogger |
|
118 | + */ |
|
119 | + public static function writeLog( $app, $message, $level ) { |
|
120 | + $context = ['app' => $app]; |
|
121 | + \OC::$server->getLogger()->log($level, $message, $context); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * write exception into the log |
|
126 | + * @param string $app app name |
|
127 | + * @param \Exception $ex exception to log |
|
128 | + * @param int $level log level, defaults to \OCP\Util::FATAL |
|
129 | + * @since ....0.0 - parameter $level was added in 7.0.0 |
|
130 | + * @deprecated 8.2.0 use logException of \OCP\ILogger |
|
131 | + */ |
|
132 | + public static function logException( $app, \Exception $ex, $level = ILogger::FATAL) { |
|
133 | + \OC::$server->getLogger()->logException($ex, ['app' => $app]); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * check if sharing is disabled for the current user |
|
138 | + * |
|
139 | + * @return boolean |
|
140 | + * @since 7.0.0 |
|
141 | + * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser |
|
142 | + */ |
|
143 | + public static function isSharingDisabledForUser() { |
|
144 | + if (self::$shareManager === null) { |
|
145 | + self::$shareManager = \OC::$server->getShareManager(); |
|
146 | + } |
|
147 | + |
|
148 | + $user = \OC::$server->getUserSession()->getUser(); |
|
149 | + if ($user !== null) { |
|
150 | + $user = $user->getUID(); |
|
151 | + } |
|
152 | + |
|
153 | + return self::$shareManager->sharingDisabledForUser($user); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * get l10n object |
|
158 | + * @param string $application |
|
159 | + * @param string|null $language |
|
160 | + * @return \OCP\IL10N |
|
161 | + * @since 6.0.0 - parameter $language was added in 8.0.0 |
|
162 | + */ |
|
163 | + public static function getL10N($application, $language = null) { |
|
164 | + return \OC::$server->getL10N($application, $language); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * add a css file |
|
169 | + * @param string $application |
|
170 | + * @param string $file |
|
171 | + * @since 4.0.0 |
|
172 | + */ |
|
173 | + public static function addStyle( $application, $file = null ) { |
|
174 | + \OC_Util::addStyle( $application, $file ); |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * add a javascript file |
|
179 | + * @param string $application |
|
180 | + * @param string $file |
|
181 | + * @since 4.0.0 |
|
182 | + */ |
|
183 | + public static function addScript( $application, $file = null ) { |
|
184 | + \OC_Util::addScript( $application, $file ); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Add a translation JS file |
|
189 | + * @param string $application application id |
|
190 | + * @param string $languageCode language code, defaults to the current locale |
|
191 | + * @since 8.0.0 |
|
192 | + */ |
|
193 | + public static function addTranslations($application, $languageCode = null) { |
|
194 | + \OC_Util::addTranslations($application, $languageCode); |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Add a custom element to the header |
|
199 | + * If $text is null then the element will be written as empty element. |
|
200 | + * So use "" to get a closing tag. |
|
201 | + * @param string $tag tag name of the element |
|
202 | + * @param array $attributes array of attributes for the element |
|
203 | + * @param string $text the text content for the element |
|
204 | + * @since 4.0.0 |
|
205 | + */ |
|
206 | + public static function addHeader($tag, $attributes, $text=null) { |
|
207 | + \OC_Util::addHeader($tag, $attributes, $text); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Creates an absolute url to the given app and file. |
|
212 | + * @param string $app app |
|
213 | + * @param string $file file |
|
214 | + * @param array $args array with param=>value, will be appended to the returned url |
|
215 | + * The value of $args will be urlencoded |
|
216 | + * @return string the url |
|
217 | + * @since 4.0.0 - parameter $args was added in 4.5.0 |
|
218 | + */ |
|
219 | + public static function linkToAbsolute( $app, $file, $args = array() ) { |
|
220 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
221 | + return $urlGenerator->getAbsoluteURL( |
|
222 | + $urlGenerator->linkTo($app, $file, $args) |
|
223 | + ); |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Creates an absolute url for remote use. |
|
228 | + * @param string $service id |
|
229 | + * @return string the url |
|
230 | + * @since 4.0.0 |
|
231 | + */ |
|
232 | + public static function linkToRemote( $service ) { |
|
233 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
234 | + $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service; |
|
235 | + return $urlGenerator->getAbsoluteURL( |
|
236 | + $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '') |
|
237 | + ); |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * Creates an absolute url for public use |
|
242 | + * @param string $service id |
|
243 | + * @return string the url |
|
244 | + * @since 4.5.0 |
|
245 | + */ |
|
246 | + public static function linkToPublic($service) { |
|
247 | + return \OC_Helper::linkToPublic($service); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Returns the server host name without an eventual port number |
|
252 | + * @return string the server hostname |
|
253 | + * @since 5.0.0 |
|
254 | + */ |
|
255 | + public static function getServerHostName() { |
|
256 | + $host_name = \OC::$server->getRequest()->getServerHost(); |
|
257 | + // strip away port number (if existing) |
|
258 | + $colon_pos = strpos($host_name, ':'); |
|
259 | + if ($colon_pos != FALSE) { |
|
260 | + $host_name = substr($host_name, 0, $colon_pos); |
|
261 | + } |
|
262 | + return $host_name; |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Returns the default email address |
|
267 | + * @param string $user_part the user part of the address |
|
268 | + * @return string the default email address |
|
269 | + * |
|
270 | + * Assembles a default email address (using the server hostname |
|
271 | + * and the given user part, and returns it |
|
272 | + * Example: when given lostpassword-noreply as $user_part param, |
|
273 | + * and is currently accessed via http(s)://example.com/, |
|
274 | + * it would return '[email protected]' |
|
275 | + * |
|
276 | + * If the configuration value 'mail_from_address' is set in |
|
277 | + * config.php, this value will override the $user_part that |
|
278 | + * is passed to this function |
|
279 | + * @since 5.0.0 |
|
280 | + */ |
|
281 | + public static function getDefaultEmailAddress($user_part) { |
|
282 | + $config = \OC::$server->getConfig(); |
|
283 | + $user_part = $config->getSystemValue('mail_from_address', $user_part); |
|
284 | + $host_name = self::getServerHostName(); |
|
285 | + $host_name = $config->getSystemValue('mail_domain', $host_name); |
|
286 | + $defaultEmailAddress = $user_part.'@'.$host_name; |
|
287 | + |
|
288 | + $mailer = \OC::$server->getMailer(); |
|
289 | + if ($mailer->validateMailAddress($defaultEmailAddress)) { |
|
290 | + return $defaultEmailAddress; |
|
291 | + } |
|
292 | + |
|
293 | + // in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain' |
|
294 | + return $user_part.'@localhost.localdomain'; |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Make a human file size (2048 to 2 kB) |
|
299 | + * @param int $bytes file size in bytes |
|
300 | + * @return string a human readable file size |
|
301 | + * @since 4.0.0 |
|
302 | + */ |
|
303 | + public static function humanFileSize($bytes) { |
|
304 | + return \OC_Helper::humanFileSize($bytes); |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Make a computer file size (2 kB to 2048) |
|
309 | + * @param string $str file size in a fancy format |
|
310 | + * @return float a file size in bytes |
|
311 | + * |
|
312 | + * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418 |
|
313 | + * @since 4.0.0 |
|
314 | + */ |
|
315 | + public static function computerFileSize($str) { |
|
316 | + return \OC_Helper::computerFileSize($str); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * connects a function to a hook |
|
321 | + * |
|
322 | + * @param string $signalClass class name of emitter |
|
323 | + * @param string $signalName name of signal |
|
324 | + * @param string|object $slotClass class name of slot |
|
325 | + * @param string $slotName name of slot |
|
326 | + * @return bool |
|
327 | + * |
|
328 | + * This function makes it very easy to connect to use hooks. |
|
329 | + * |
|
330 | + * TODO: write example |
|
331 | + * @since 4.0.0 |
|
332 | + */ |
|
333 | + static public function connectHook($signalClass, $signalName, $slotClass, $slotName) { |
|
334 | + return \OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName); |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Emits a signal. To get data from the slot use references! |
|
339 | + * @param string $signalclass class name of emitter |
|
340 | + * @param string $signalname name of signal |
|
341 | + * @param array $params default: array() array with additional data |
|
342 | + * @return bool true if slots exists or false if not |
|
343 | + * |
|
344 | + * TODO: write example |
|
345 | + * @since 4.0.0 |
|
346 | + */ |
|
347 | + static public function emitHook($signalclass, $signalname, $params = array()) { |
|
348 | + return \OC_Hook::emit($signalclass, $signalname, $params); |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare |
|
353 | + * multiple OC_Template elements which invoke `callRegister`. If the value |
|
354 | + * would not be cached these unit-tests would fail. |
|
355 | + * @var string |
|
356 | + */ |
|
357 | + private static $token = ''; |
|
358 | + |
|
359 | + /** |
|
360 | + * Register an get/post call. This is important to prevent CSRF attacks |
|
361 | + * @since 4.5.0 |
|
362 | + */ |
|
363 | + public static function callRegister() { |
|
364 | + if(self::$token === '') { |
|
365 | + self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue(); |
|
366 | + } |
|
367 | + return self::$token; |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * Check an ajax get/post call if the request token is valid. exit if not. |
|
372 | + * @since 4.5.0 |
|
373 | + * @deprecated 9.0.0 Use annotations based on the app framework. |
|
374 | + */ |
|
375 | + public static function callCheck() { |
|
376 | + if(!\OC::$server->getRequest()->passesStrictCookieCheck()) { |
|
377 | + header('Location: '.\OC::$WEBROOT); |
|
378 | + exit(); |
|
379 | + } |
|
380 | + |
|
381 | + if (!\OC::$server->getRequest()->passesCSRFCheck()) { |
|
382 | + exit(); |
|
383 | + } |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Used to sanitize HTML |
|
388 | + * |
|
389 | + * This function is used to sanitize HTML and should be applied on any |
|
390 | + * string or array of strings before displaying it on a web page. |
|
391 | + * |
|
392 | + * @param string|array $value |
|
393 | + * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
394 | + * @since 4.5.0 |
|
395 | + */ |
|
396 | + public static function sanitizeHTML($value) { |
|
397 | + return \OC_Util::sanitizeHTML($value); |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * Public function to encode url parameters |
|
402 | + * |
|
403 | + * This function is used to encode path to file before output. |
|
404 | + * Encoding is done according to RFC 3986 with one exception: |
|
405 | + * Character '/' is preserved as is. |
|
406 | + * |
|
407 | + * @param string $component part of URI to encode |
|
408 | + * @return string |
|
409 | + * @since 6.0.0 |
|
410 | + */ |
|
411 | + public static function encodePath($component) { |
|
412 | + return \OC_Util::encodePath($component); |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. |
|
417 | + * |
|
418 | + * @param array $input The array to work on |
|
419 | + * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default) |
|
420 | + * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 |
|
421 | + * @return array |
|
422 | + * @since 4.5.0 |
|
423 | + */ |
|
424 | + public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') { |
|
425 | + return \OC_Helper::mb_array_change_key_case($input, $case, $encoding); |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * replaces a copy of string delimited by the start and (optionally) length parameters with the string given in replacement. |
|
430 | + * |
|
431 | + * @param string $string The input string. Opposite to the PHP build-in function does not accept an array. |
|
432 | + * @param string $replacement The replacement string. |
|
433 | + * @param int $start If start is positive, the replacing will begin at the start'th offset into string. If start is negative, the replacing will begin at the start'th character from the end of string. |
|
434 | + * @param int $length Length of the part to be replaced |
|
435 | + * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 |
|
436 | + * @return string |
|
437 | + * @since 4.5.0 |
|
438 | + * @deprecated 8.2.0 Use substr_replace() instead. |
|
439 | + */ |
|
440 | + public static function mb_substr_replace($string, $replacement, $start, $length = null, $encoding = 'UTF-8') { |
|
441 | + return substr_replace($string, $replacement, $start, $length); |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * Replace all occurrences of the search string with the replacement string |
|
446 | + * |
|
447 | + * @param string $search The value being searched for, otherwise known as the needle. String. |
|
448 | + * @param string $replace The replacement string. |
|
449 | + * @param string $subject The string or array being searched and replaced on, otherwise known as the haystack. |
|
450 | + * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 |
|
451 | + * @param int $count If passed, this will be set to the number of replacements performed. |
|
452 | + * @return string |
|
453 | + * @since 4.5.0 |
|
454 | + * @deprecated 8.2.0 Use str_replace() instead. |
|
455 | + */ |
|
456 | + public static function mb_str_replace($search, $replace, $subject, $encoding = 'UTF-8', &$count = null) { |
|
457 | + return str_replace($search, $replace, $subject, $count); |
|
458 | + } |
|
459 | + |
|
460 | + /** |
|
461 | + * performs a search in a nested array |
|
462 | + * |
|
463 | + * @param array $haystack the array to be searched |
|
464 | + * @param string $needle the search string |
|
465 | + * @param mixed $index optional, only search this key name |
|
466 | + * @return mixed the key of the matching field, otherwise false |
|
467 | + * @since 4.5.0 |
|
468 | + */ |
|
469 | + public static function recursiveArraySearch($haystack, $needle, $index = null) { |
|
470 | + return \OC_Helper::recursiveArraySearch($haystack, $needle, $index); |
|
471 | + } |
|
472 | + |
|
473 | + /** |
|
474 | + * calculates the maximum upload size respecting system settings, free space and user quota |
|
475 | + * |
|
476 | + * @param string $dir the current folder where the user currently operates |
|
477 | + * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly |
|
478 | + * @return int number of bytes representing |
|
479 | + * @since 5.0.0 |
|
480 | + */ |
|
481 | + public static function maxUploadFilesize($dir, $free = null) { |
|
482 | + return \OC_Helper::maxUploadFilesize($dir, $free); |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * Calculate free space left within user quota |
|
487 | + * @param string $dir the current folder where the user currently operates |
|
488 | + * @return int number of bytes representing |
|
489 | + * @since 7.0.0 |
|
490 | + */ |
|
491 | + public static function freeSpace($dir) { |
|
492 | + return \OC_Helper::freeSpace($dir); |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * Calculate PHP upload limit |
|
497 | + * |
|
498 | + * @return int number of bytes representing |
|
499 | + * @since 7.0.0 |
|
500 | + */ |
|
501 | + public static function uploadLimit() { |
|
502 | + return \OC_Helper::uploadLimit(); |
|
503 | + } |
|
504 | + |
|
505 | + /** |
|
506 | + * Returns whether the given file name is valid |
|
507 | + * @param string $file file name to check |
|
508 | + * @return bool true if the file name is valid, false otherwise |
|
509 | + * @deprecated 8.1.0 use \OC\Files\View::verifyPath() |
|
510 | + * @since 7.0.0 |
|
511 | + * @suppress PhanDeprecatedFunction |
|
512 | + */ |
|
513 | + public static function isValidFileName($file) { |
|
514 | + return \OC_Util::isValidFileName($file); |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * Compare two strings to provide a natural sort |
|
519 | + * @param string $a first string to compare |
|
520 | + * @param string $b second string to compare |
|
521 | + * @return int -1 if $b comes before $a, 1 if $a comes before $b |
|
522 | + * or 0 if the strings are identical |
|
523 | + * @since 7.0.0 |
|
524 | + */ |
|
525 | + public static function naturalSortCompare($a, $b) { |
|
526 | + return \OC\NaturalSort::getInstance()->compare($a, $b); |
|
527 | + } |
|
528 | + |
|
529 | + /** |
|
530 | + * check if a password is required for each public link |
|
531 | + * @return boolean |
|
532 | + * @since 7.0.0 |
|
533 | + */ |
|
534 | + public static function isPublicLinkPasswordRequired() { |
|
535 | + return \OC_Util::isPublicLinkPasswordRequired(); |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * check if share API enforces a default expire date |
|
540 | + * @return boolean |
|
541 | + * @since 8.0.0 |
|
542 | + */ |
|
543 | + public static function isDefaultExpireDateEnforced() { |
|
544 | + return \OC_Util::isDefaultExpireDateEnforced(); |
|
545 | + } |
|
546 | + |
|
547 | + protected static $needUpgradeCache = null; |
|
548 | + |
|
549 | + /** |
|
550 | + * Checks whether the current version needs upgrade. |
|
551 | + * |
|
552 | + * @return bool true if upgrade is needed, false otherwise |
|
553 | + * @since 7.0.0 |
|
554 | + */ |
|
555 | + public static function needUpgrade() { |
|
556 | + if (!isset(self::$needUpgradeCache)) { |
|
557 | + self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig()); |
|
558 | + } |
|
559 | + return self::$needUpgradeCache; |
|
560 | + } |
|
561 | 561 | } |
@@ -36,134 +36,134 @@ |
||
36 | 36 | * https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#3-psrlogloggerinterface |
37 | 37 | */ |
38 | 38 | interface ILogger { |
39 | - /** |
|
40 | - * @since 14.0.0 |
|
41 | - */ |
|
42 | - const DEBUG=0; |
|
43 | - /** |
|
44 | - * @since 14.0.0 |
|
45 | - */ |
|
46 | - const INFO=1; |
|
47 | - /** |
|
48 | - * @since 14.0.0 |
|
49 | - */ |
|
50 | - const WARN=2; |
|
51 | - /** |
|
52 | - * @since 14.0.0 |
|
53 | - */ |
|
54 | - const ERROR=3; |
|
55 | - /** |
|
56 | - * @since 14.0.0 |
|
57 | - */ |
|
58 | - const FATAL=4; |
|
39 | + /** |
|
40 | + * @since 14.0.0 |
|
41 | + */ |
|
42 | + const DEBUG=0; |
|
43 | + /** |
|
44 | + * @since 14.0.0 |
|
45 | + */ |
|
46 | + const INFO=1; |
|
47 | + /** |
|
48 | + * @since 14.0.0 |
|
49 | + */ |
|
50 | + const WARN=2; |
|
51 | + /** |
|
52 | + * @since 14.0.0 |
|
53 | + */ |
|
54 | + const ERROR=3; |
|
55 | + /** |
|
56 | + * @since 14.0.0 |
|
57 | + */ |
|
58 | + const FATAL=4; |
|
59 | 59 | |
60 | - /** |
|
61 | - * System is unusable. |
|
62 | - * |
|
63 | - * @param string $message |
|
64 | - * @param array $context |
|
65 | - * @return null |
|
66 | - * @since 7.0.0 |
|
67 | - */ |
|
68 | - public function emergency(string $message, array $context = []); |
|
60 | + /** |
|
61 | + * System is unusable. |
|
62 | + * |
|
63 | + * @param string $message |
|
64 | + * @param array $context |
|
65 | + * @return null |
|
66 | + * @since 7.0.0 |
|
67 | + */ |
|
68 | + public function emergency(string $message, array $context = []); |
|
69 | 69 | |
70 | - /** |
|
71 | - * Action must be taken immediately. |
|
72 | - * |
|
73 | - * @param string $message |
|
74 | - * @param array $context |
|
75 | - * @return null |
|
76 | - * @since 7.0.0 |
|
77 | - */ |
|
78 | - public function alert(string $message, array $context = []); |
|
70 | + /** |
|
71 | + * Action must be taken immediately. |
|
72 | + * |
|
73 | + * @param string $message |
|
74 | + * @param array $context |
|
75 | + * @return null |
|
76 | + * @since 7.0.0 |
|
77 | + */ |
|
78 | + public function alert(string $message, array $context = []); |
|
79 | 79 | |
80 | - /** |
|
81 | - * Critical conditions. |
|
82 | - * |
|
83 | - * @param string $message |
|
84 | - * @param array $context |
|
85 | - * @return null |
|
86 | - * @since 7.0.0 |
|
87 | - */ |
|
88 | - public function critical(string $message, array $context = []); |
|
80 | + /** |
|
81 | + * Critical conditions. |
|
82 | + * |
|
83 | + * @param string $message |
|
84 | + * @param array $context |
|
85 | + * @return null |
|
86 | + * @since 7.0.0 |
|
87 | + */ |
|
88 | + public function critical(string $message, array $context = []); |
|
89 | 89 | |
90 | - /** |
|
91 | - * Runtime errors that do not require immediate action but should typically |
|
92 | - * be logged and monitored. |
|
93 | - * |
|
94 | - * @param string $message |
|
95 | - * @param array $context |
|
96 | - * @return null |
|
97 | - * @since 7.0.0 |
|
98 | - */ |
|
99 | - public function error(string $message, array $context = []); |
|
90 | + /** |
|
91 | + * Runtime errors that do not require immediate action but should typically |
|
92 | + * be logged and monitored. |
|
93 | + * |
|
94 | + * @param string $message |
|
95 | + * @param array $context |
|
96 | + * @return null |
|
97 | + * @since 7.0.0 |
|
98 | + */ |
|
99 | + public function error(string $message, array $context = []); |
|
100 | 100 | |
101 | - /** |
|
102 | - * Exceptional occurrences that are not errors. |
|
103 | - * |
|
104 | - * @param string $message |
|
105 | - * @param array $context |
|
106 | - * @return null |
|
107 | - * @since 7.0.0 |
|
108 | - */ |
|
109 | - public function warning(string $message, array $context = []); |
|
101 | + /** |
|
102 | + * Exceptional occurrences that are not errors. |
|
103 | + * |
|
104 | + * @param string $message |
|
105 | + * @param array $context |
|
106 | + * @return null |
|
107 | + * @since 7.0.0 |
|
108 | + */ |
|
109 | + public function warning(string $message, array $context = []); |
|
110 | 110 | |
111 | - /** |
|
112 | - * Normal but significant events. |
|
113 | - * |
|
114 | - * @param string $message |
|
115 | - * @param array $context |
|
116 | - * @return null |
|
117 | - * @since 7.0.0 |
|
118 | - */ |
|
119 | - public function notice(string $message, array $context = []); |
|
111 | + /** |
|
112 | + * Normal but significant events. |
|
113 | + * |
|
114 | + * @param string $message |
|
115 | + * @param array $context |
|
116 | + * @return null |
|
117 | + * @since 7.0.0 |
|
118 | + */ |
|
119 | + public function notice(string $message, array $context = []); |
|
120 | 120 | |
121 | - /** |
|
122 | - * Interesting events. |
|
123 | - * |
|
124 | - * @param string $message |
|
125 | - * @param array $context |
|
126 | - * @return null |
|
127 | - * @since 7.0.0 |
|
128 | - */ |
|
129 | - public function info(string $message, array $context = []); |
|
121 | + /** |
|
122 | + * Interesting events. |
|
123 | + * |
|
124 | + * @param string $message |
|
125 | + * @param array $context |
|
126 | + * @return null |
|
127 | + * @since 7.0.0 |
|
128 | + */ |
|
129 | + public function info(string $message, array $context = []); |
|
130 | 130 | |
131 | - /** |
|
132 | - * Detailed debug information. |
|
133 | - * |
|
134 | - * @param string $message |
|
135 | - * @param array $context |
|
136 | - * @return null |
|
137 | - * @since 7.0.0 |
|
138 | - */ |
|
139 | - public function debug(string $message, array $context = []); |
|
131 | + /** |
|
132 | + * Detailed debug information. |
|
133 | + * |
|
134 | + * @param string $message |
|
135 | + * @param array $context |
|
136 | + * @return null |
|
137 | + * @since 7.0.0 |
|
138 | + */ |
|
139 | + public function debug(string $message, array $context = []); |
|
140 | 140 | |
141 | - /** |
|
142 | - * Logs with an arbitrary level. |
|
143 | - * |
|
144 | - * @param int $level |
|
145 | - * @param string $message |
|
146 | - * @param array $context |
|
147 | - * @return mixed |
|
148 | - * @since 7.0.0 |
|
149 | - */ |
|
150 | - public function log(int $level, string $message, array $context = []); |
|
141 | + /** |
|
142 | + * Logs with an arbitrary level. |
|
143 | + * |
|
144 | + * @param int $level |
|
145 | + * @param string $message |
|
146 | + * @param array $context |
|
147 | + * @return mixed |
|
148 | + * @since 7.0.0 |
|
149 | + */ |
|
150 | + public function log(int $level, string $message, array $context = []); |
|
151 | 151 | |
152 | - /** |
|
153 | - * Logs an exception very detailed |
|
154 | - * An additional message can we written to the log by adding it to the |
|
155 | - * context. |
|
156 | - * |
|
157 | - * <code> |
|
158 | - * $logger->logException($ex, [ |
|
159 | - * 'message' => 'Exception during background job execution' |
|
160 | - * ]); |
|
161 | - * </code> |
|
162 | - * |
|
163 | - * @param \Exception|\Throwable $exception |
|
164 | - * @param array $context |
|
165 | - * @return void |
|
166 | - * @since 8.2.0 |
|
167 | - */ |
|
168 | - public function logException(\Throwable $exception, array $context = []); |
|
152 | + /** |
|
153 | + * Logs an exception very detailed |
|
154 | + * An additional message can we written to the log by adding it to the |
|
155 | + * context. |
|
156 | + * |
|
157 | + * <code> |
|
158 | + * $logger->logException($ex, [ |
|
159 | + * 'message' => 'Exception during background job execution' |
|
160 | + * ]); |
|
161 | + * </code> |
|
162 | + * |
|
163 | + * @param \Exception|\Throwable $exception |
|
164 | + * @param array $context |
|
165 | + * @return void |
|
166 | + * @since 8.2.0 |
|
167 | + */ |
|
168 | + public function logException(\Throwable $exception, array $context = []); |
|
169 | 169 | } |
@@ -32,30 +32,30 @@ |
||
32 | 32 | |
33 | 33 | $lastConfirm = (int) \OC::$server->getSession()->get('last-password-confirm'); |
34 | 34 | if ($lastConfirm < (time() - 30 * 60 + 15)) { // allow 15 seconds delay |
35 | - $l = \OC::$server->getL10N('core'); |
|
36 | - OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required')))); |
|
37 | - exit(); |
|
35 | + $l = \OC::$server->getL10N('core'); |
|
36 | + OC_JSON::error(array( 'data' => array( 'message' => $l->t('Password confirmation is required')))); |
|
37 | + exit(); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | $groups = isset($_POST['groups']) ? (array)$_POST['groups'] : []; |
41 | 41 | $appIds = isset($_POST['appIds']) ? (array)$_POST['appIds'] : []; |
42 | 42 | |
43 | 43 | try { |
44 | - $updateRequired = false; |
|
45 | - foreach($appIds as $appId) { |
|
46 | - $app = new OC_App(); |
|
47 | - $appId = OC_App::cleanAppId($appId); |
|
48 | - $app->enable($appId, $groups); |
|
49 | - if(\OC_App::shouldUpgrade($appId)) { |
|
50 | - $updateRequired = true; |
|
51 | - } |
|
52 | - } |
|
44 | + $updateRequired = false; |
|
45 | + foreach($appIds as $appId) { |
|
46 | + $app = new OC_App(); |
|
47 | + $appId = OC_App::cleanAppId($appId); |
|
48 | + $app->enable($appId, $groups); |
|
49 | + if(\OC_App::shouldUpgrade($appId)) { |
|
50 | + $updateRequired = true; |
|
51 | + } |
|
52 | + } |
|
53 | 53 | |
54 | - OC_JSON::success(['data' => ['update_required' => $updateRequired]]); |
|
54 | + OC_JSON::success(['data' => ['update_required' => $updateRequired]]); |
|
55 | 55 | } catch (Exception $e) { |
56 | - \OC::$server->getLogger()->logException($e, [ |
|
57 | - 'level' => ILogger::DEBUG, |
|
58 | - 'app' => 'core', |
|
59 | - ]); |
|
60 | - OC_JSON::error(array("data" => array("message" => $e->getMessage()) )); |
|
56 | + \OC::$server->getLogger()->logException($e, [ |
|
57 | + 'level' => ILogger::DEBUG, |
|
58 | + 'app' => 'core', |
|
59 | + ]); |
|
60 | + OC_JSON::error(array("data" => array("message" => $e->getMessage()) )); |
|
61 | 61 | } |