Adjust apps' code to use the ContainerInterface

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2020-07-16 17:08:03 +02:00 committed by Morris Jobke
parent e029055e76
commit 91e7f12088
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
14 changed files with 212 additions and 185 deletions

View File

@ -59,11 +59,12 @@ use OCP\IConfig;
use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IPreview;
use OCP\IServerContainer;
use OCP\IUserSession;
use OCP\Log\ILogFactory;
use OCP\Share;
use OCP\Util;
use Psr\Container\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class Application extends App implements IBootstrap {
@ -107,25 +108,25 @@ class Application extends App implements IBootstrap {
* Register hooks in order to log them
*/
private function registerHooks(ILogger $logger,
IServerContainer $serverContainer) {
$this->userManagementHooks($logger, $serverContainer);
$this->groupHooks($logger, $serverContainer);
ContainerInterface $container) {
$this->userManagementHooks($logger, $container);
$this->groupHooks($logger, $container);
$this->authHooks($logger);
$this->consoleHooks($logger, $serverContainer);
$this->appHooks($logger, $serverContainer);
$this->consoleHooks($logger, $container);
$this->appHooks($logger, $container);
$this->sharingHooks($logger);
$this->fileHooks($logger, $serverContainer);
$this->fileHooks($logger, $container);
$this->trashbinHooks($logger);
$this->versionsHooks($logger);
$this->securityHooks($logger, $serverContainer);
$this->securityHooks($logger, $container);
}
private function userManagementHooks(ILogger $logger,
IServerContainer $serverContainer) {
ContainerInterface $container) {
$userActions = new UserManagement($logger);
Util::connectHook('OC_User', 'post_createUser', $userActions, 'create');
@ -133,18 +134,18 @@ class Application extends App implements IBootstrap {
Util::connectHook('OC_User', 'changeUser', $userActions, 'change');
/** @var IUserSession|Session $userSession */
$userSession = $serverContainer->getUserSession();
$userSession = $container->get(IUserSession::class);
$userSession->listen('\OC\User', 'postSetPassword', [$userActions, 'setPassword']);
$userSession->listen('\OC\User', 'assignedUserId', [$userActions, 'assign']);
$userSession->listen('\OC\User', 'postUnassignedUserId', [$userActions, 'unassign']);
}
private function groupHooks(ILogger $logger,
IServerContainer $serverContainer) {
ContainerInterface $container) {
$groupActions = new GroupManagement($logger);
/** @var IGroupManager|Manager $groupManager */
$groupManager = $serverContainer->getGroupManager();
$groupManager = $container->getGroupManager(IGroupManager::class);
$groupManager->listen('\OC\Group', 'postRemoveUser', [$groupActions, 'removeUser']);
$groupManager->listen('\OC\Group', 'postAddUser', [$groupActions, 'addUser']);
$groupManager->listen('\OC\Group', 'postDelete', [$groupActions, 'deleteGroup']);
@ -172,8 +173,8 @@ class Application extends App implements IBootstrap {
}
private function appHooks(ILogger $logger,
IServerContainer $serverContainer) {
$eventDispatcher = $serverContainer->getEventDispatcher();
ContainerInterface $container) {
$eventDispatcher = $container->get(EventDispatcherInterface::class);
$eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) use ($logger) {
$appActions = new AppManagement($logger);
$appActions->enableApp($event->getAppID());
@ -189,8 +190,8 @@ class Application extends App implements IBootstrap {
}
private function consoleHooks(ILogger $logger,
IServerContainer $serverContainer) {
$eventDispatcher = $serverContainer->getEventDispatcher();
ContainerInterface $container) {
$eventDispatcher = $container->get(EventDispatcherInterface::class);
$eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) use ($logger) {
$appActions = new Console($logger);
$appActions->runCommand($event->getArguments());
@ -198,9 +199,9 @@ class Application extends App implements IBootstrap {
}
private function fileHooks(ILogger $logger,
IServerContainer $serverContainer) {
ContainerInterface $container) {
$fileActions = new Files($logger);
$eventDispatcher = $serverContainer->getEventDispatcher();
$eventDispatcher = $container->get(EventDispatcherInterface::class);
$eventDispatcher->addListener(
IPreview::EVENT,
function (GenericEvent $event) use ($fileActions) {
@ -273,8 +274,8 @@ class Application extends App implements IBootstrap {
}
private function securityHooks(ILogger $logger,
IServerContainer $serverContainer) {
$eventDispatcher = $serverContainer->getEventDispatcher();
ContainerInterface $container) {
$eventDispatcher = $container->get(EventDispatcherInterface::class);
$eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) use ($logger) {
$security = new Security($logger);
$security->twofactorSuccess($event->getSubject(), $event->getArguments());

View File

@ -27,6 +27,7 @@
namespace OCA\Comments\AppInfo;
use Closure;
use OCA\Comments\Capabilities;
use OCA\Comments\Controller\Notifications;
use OCA\Comments\EventHandler;
@ -44,6 +45,8 @@ use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Comments\CommentsEntityEvent;
use OCP\IConfig;
use OCP\ISearch;
use OCP\IServerContainer;
use OCP\Util;
@ -75,13 +78,13 @@ class Application extends App implements IBootstrap {
}
public function boot(IBootContext $context): void {
$this->registerNotifier($context->getServerContainer());
$this->registerCommentsEventHandler($context->getServerContainer());
$context->injectFn(Closure::fromCallable([$this, 'registerNotifier']));
$context->injectFn(Closure::fromCallable([$this, 'registerCommentsEventHandler']));
$jsSettingsHelper = new JSSettingsHelper($context->getServerContainer());
$jsSettingsHelper = new JSSettingsHelper($context->getAppContainer()->get(IConfig::class));
Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend');
$context->getServerContainer()->getSearch()->registerProvider(LegacyProvider::class, ['apps' => ['files']]);
$context->getServerContainer()->get(ISearch::class)->registerProvider(LegacyProvider::class, ['apps' => ['files']]);
}
protected function registerNotifier(IServerContainer $container) {

View File

@ -23,20 +23,20 @@
namespace OCA\Comments;
use OCP\IServerContainer;
use OCP\IConfig;
class JSSettingsHelper {
/** @var IServerContainer */
/** @var IConfig */
private $c;
public function __construct(IServerContainer $c) {
public function __construct(IConfig $c) {
$this->c = $c;
}
public function extend(array $settings) {
$appConfig = json_decode($settings['array']['oc_appconfig'], true);
$value = (int)$this->c->getConfig()->getAppValue('comments', 'maxAutoCompleteResults', 10);
$value = (int)$this->c->getAppValue('comments', 'maxAutoCompleteResults', 10);
$appConfig['comments']['maxAutoCompleteResults'] = $value;
$settings['array']['oc_appconfig'] = json_encode($appConfig);

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
@ -26,11 +29,11 @@ namespace OCA\Comments\Tests\Unit;
use OCA\Comments\JSSettingsHelper;
use OCP\IConfig;
use OCP\IServerContainer;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class JSSettingsHelperTest extends TestCase {
/** @var IServerContainer|\PHPUnit_Framework_MockObject_MockObject */
/** @var IConfig|MockObject */
protected $c;
/** @var JSSettingsHelper */
protected $helper;
@ -38,22 +41,17 @@ class JSSettingsHelperTest extends TestCase {
protected function setUp(): void {
parent::setUp();
$this->c = $this->createMock(IServerContainer::class);
$this->c = $this->createMock(IConfig::class);
$this->helper = new JSSettingsHelper($this->c);
}
public function testExtend() {
$config = $this->createMock(IConfig::class);
$config->expects($this->once())
$this->c->expects($this->once())
->method('getAppValue')
->with('comments', 'maxAutoCompleteResults')
->willReturn(13);
$this->c->expects($this->once())
->method('getConfig')
->willReturn($config);
$config = [
'oc_appconfig' => json_encode([
'anotherapp' => [

View File

@ -28,6 +28,7 @@
namespace OCA\FederatedFileSharing\AppInfo;
use Closure;
use OCA\FederatedFileSharing\Listeners\LoadAdditionalScriptsListener;
use OCA\FederatedFileSharing\Notifier;
use OCA\FederatedFileSharing\OCM\CloudFederationProviderFiles;
@ -36,6 +37,9 @@ use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Federation\ICloudFederationProviderManager;
use OCP\Notification\IManager as INotifiactionManager;
use Psr\Container\ContainerInterface;
class Application extends App implements IBootstrap {
public function __construct() {
@ -47,16 +51,20 @@ class Application extends App implements IBootstrap {
}
public function boot(IBootContext $context): void {
$server = $context->getServerContainer();
$context->injectFn(Closure::fromCallable([$this, 'registerCloudFederationProvider']));
$context->injectFn(Closure::fromCallable([$this, 'registerNotificationManager']));
}
$cloudFederationManager = $server->getCloudFederationProviderManager();
$cloudFederationManager->addCloudFederationProvider('file',
private function registerCloudFederationProvider(ICloudFederationProviderManager $manager,
ContainerInterface $container): void {
$manager->addCloudFederationProvider('file',
'Federated Files Sharing',
function () use ($server) {
return $server->query(CloudFederationProviderFiles::class);
function () use ($container) {
return $container->get(CloudFederationProviderFiles::class);
});
}
$manager = $server->getNotificationManager();
private function registerNotificationManager(INotifiactionManager $manager): void {
$manager->registerNotifierService(Notifier::class);
}
}

View File

@ -34,6 +34,7 @@ declare(strict_types=1);
namespace OCA\Files\AppInfo;
use Closure;
use OC\Search\Provider\File;
use OCA\Files\Capabilities;
use OCA\Files\Collaboration\Resources\Listener;
@ -53,6 +54,7 @@ use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Collaboration\Resources\IProviderManager;
use OCP\IContainer;
use OCP\IL10N;
use OCP\ISearch;
use OCP\IServerContainer;
use OCP\Notification\IManager;
use OCP\Util;
@ -112,35 +114,25 @@ class Application extends App implements IBootstrap {
}
public function boot(IBootContext $context): void {
$this->registerCollaboration($context);
Listener::register($context->getServerContainer()->getEventDispatcher());
$this->registerNotification($context);
$this->registerSearchProvider($context);
$context->injectFn(Closure::fromCallable([$this, 'registerCollaboration']));
$context->injectFn([Listener::class, 'register']);
$context->injectFn(Closure::fromCallable([$this, 'registerNotification']));
$context->injectFn(Closure::fromCallable([$this, 'registerSearchProvider']));
$this->registerTemplates();
$this->registerNavigation($context);
$context->injectFn(Closure::fromCallable([$this, 'registerNavigation']));
$this->registerHooks();
}
/**
* Register Collaboration ResourceProvider
*/
private function registerCollaboration(IBootContext $context): void {
/** @var IProviderManager $providerManager */
$providerManager = $context->getAppContainer()->query(IProviderManager::class);
private function registerCollaboration(IProviderManager $providerManager): void {
$providerManager->registerResourceProvider(ResourceProvider::class);
}
private function registerNotification(IBootContext $context): void {
/** @var IManager $notifications */
$notifications = $context->getAppContainer()->query(IManager::class);
private function registerNotification(IManager $notifications): void {
$notifications->registerNotifierService(Notifier::class);
}
/**
* @param IBootContext $context
*/
private function registerSearchProvider(IBootContext $context): void {
$context->getServerContainer()->getSearch()->registerProvider(File::class, ['apps' => ['files']]);
private function registerSearchProvider(ISearch $search): void {
$search->registerProvider(File::class, ['apps' => ['files']]);
}
private function registerTemplates(): void {
@ -150,9 +142,7 @@ class Application extends App implements IBootstrap {
$templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods');
}
private function registerNavigation(IBootContext $context): void {
/** @var IL10N $l10n */
$l10n = $context->getAppContainer()->query(IL10N::class);
private function registerNavigation(IL10N $l10n): void {
\OCA\Files\App::getNavigationManager()->add(function () use ($l10n) {
return [
'id' => 'files',

View File

@ -28,12 +28,15 @@ declare(strict_types=1);
namespace OCA\LookupServerConnector\AppInfo;
use Closure;
use OCA\LookupServerConnector\UpdateLookupServer;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUser;
use Psr\Container\ContainerInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class Application extends App implements IBootstrap {
@ -47,16 +50,20 @@ class Application extends App implements IBootstrap {
}
public function boot(IBootContext $context): void {
/*
* @todo move the OCP events and then move the registration to `register`
*/
$dispatcher = $context->getServerContainer()->getEventDispatcher();
$dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) use ($context) {
$context->injectFn(Closure::fromCallable([$this, 'registerEventListeners']));
}
/**
* @todo move the OCP events and then move the registration to `register`
*/
private function registerEventListeners(IEventDispatcher $dispatcher,
ContainerInterface $container): void {
$dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) use ($container) {
/** @var IUser $user */
$user = $event->getSubject();
/** @var UpdateLookupServer $updateLookupServer */
$updateLookupServer = $context->getServerContainer()->query(UpdateLookupServer::class);
$updateLookupServer = $container->get(UpdateLookupServer::class);
$updateLookupServer->userUpdated($user);
});
}

View File

@ -40,6 +40,7 @@ use BadMethodCallException;
use OC\AppFramework\Utility\TimeFactory;
use OC\Authentication\Token\IProvider;
use OC\Authentication\Token\IToken;
use OC\Group\Manager;
use OC\Server;
use OCA\Settings\Activity\Provider;
use OCA\Settings\Hooks;
@ -52,6 +53,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Defaults;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IServerContainer;
use OCP\IUser;
@ -134,38 +136,39 @@ class Application extends App implements IBootstrap {
}
public function boot(IBootContext $context): void {
/** @var EventDispatcherInterface $eventDispatcher */
$eventDispatcher = $context->getServerContainer()->getEventDispatcher();
$container = $context->getAppContainer();
$eventDispatcher->addListener('app_password_created', function (GenericEvent $event) use ($container) {
if (($token = $event->getSubject()) instanceof IToken) {
/** @var IActivityManager $activityManager */
$activityManager = $container->query(IActivityManager::class);
/** @var ILogger $logger */
$logger = $container->query(ILogger::class);
$context->injectFn(function (EventDispatcherInterface $dispatcher, ContainerInterface $container) {
$dispatcher->addListener('app_password_created', function (GenericEvent $event) use ($container) {
if (($token = $event->getSubject()) instanceof IToken) {
/** @var IActivityManager $activityManager */
$activityManager = $container->get(IActivityManager::class);
/** @var ILogger $logger */
$logger = $container->get(ILogger::class);
$activity = $activityManager->generateEvent();
$activity->setApp('settings')
->setType('security')
->setAffectedUser($token->getUID())
->setAuthor($token->getUID())
->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $token->getName()])
->setObject('app_token', $token->getId());
$activity = $activityManager->generateEvent();
$activity->setApp('settings')
->setType('security')
->setAffectedUser($token->getUID())
->setAuthor($token->getUID())
->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $token->getName()])
->setObject('app_token', $token->getId());
try {
$activityManager->publish($activity);
} catch (BadMethodCallException $e) {
$logger->logException($e, ['message' => 'could not publish activity', 'level' => ILogger::WARN]);
try {
$activityManager->publish($activity);
} catch (BadMethodCallException $e) {
$logger->logException($e, ['message' => 'could not publish activity', 'level' => ILogger::WARN]);
}
}
}
});
});
Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword');
Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo');
$groupManager = $context->getServerContainer()->getGroupManager();
$groupManager->listen('\OC\Group', 'postRemoveUser', [$this, 'removeUserFromGroup']);
$groupManager->listen('\OC\Group', 'postAddUser', [$this, 'addUserToGroup']);
$context->injectFn(function (IGroupManager $groupManager) {
/** @var IGroupManager|Manager $groupManager */
$groupManager->listen('\OC\Group', 'postRemoveUser', [$this, 'removeUserFromGroup']);
$groupManager->listen('\OC\Group', 'postAddUser', [$this, 'addUserToGroup']);
});
Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig');
}

View File

@ -32,6 +32,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\SystemTag\ManagerEvent;
use OCP\SystemTag\MapperEvent;
use Symfony\Component\EventDispatcher\EventDispatcher;
class Application extends App implements IBootstrap {
public const APP_ID = 'systemtags';
@ -44,35 +45,36 @@ class Application extends App implements IBootstrap {
}
public function boot(IBootContext $context): void {
/*
* @todo move the OCP events and then move the registration to `register`
*/
$eventDispatcher = $context->getServerContainer()->getEventDispatcher();
$eventDispatcher->addListener(
'OCA\Files::loadAdditionalScripts',
function () {
// FIXME: no public API for these ?
\OCP\Util::addScript('dist/systemtags');
\OCP\Util::addScript(self::APP_ID, 'systemtags');
}
);
$context->injectFn(function (EventDispatcher $dispatcher) use ($context) {
/*
* @todo move the OCP events and then move the registration to `register`
*/
$dispatcher->addListener(
'OCA\Files::loadAdditionalScripts',
function () {
// FIXME: no public API for these ?
\OCP\Util::addScript('dist/systemtags');
\OCP\Util::addScript(self::APP_ID, 'systemtags');
}
);
$managerListener = function (ManagerEvent $event) use ($context) {
/** @var \OCA\SystemTags\Activity\Listener $listener */
$listener = $context->getServerContainer()->query(Listener::class);
$listener->event($event);
};
$eventDispatcher->addListener(ManagerEvent::EVENT_CREATE, $managerListener);
$eventDispatcher->addListener(ManagerEvent::EVENT_DELETE, $managerListener);
$eventDispatcher->addListener(ManagerEvent::EVENT_UPDATE, $managerListener);
$managerListener = function (ManagerEvent $event) use ($context) {
/** @var \OCA\SystemTags\Activity\Listener $listener */
$listener = $context->getServerContainer()->query(Listener::class);
$listener->event($event);
};
$dispatcher->addListener(ManagerEvent::EVENT_CREATE, $managerListener);
$dispatcher->addListener(ManagerEvent::EVENT_DELETE, $managerListener);
$dispatcher->addListener(ManagerEvent::EVENT_UPDATE, $managerListener);
$mapperListener = function (MapperEvent $event) use ($context) {
/** @var \OCA\SystemTags\Activity\Listener $listener */
$listener = $context->getServerContainer()->query(Listener::class);
$listener->mapperEvent($event);
};
$eventDispatcher->addListener(MapperEvent::EVENT_ASSIGN, $mapperListener);
$eventDispatcher->addListener(MapperEvent::EVENT_UNASSIGN, $mapperListener);
$mapperListener = function (MapperEvent $event) use ($context) {
/** @var \OCA\SystemTags\Activity\Listener $listener */
$listener = $context->getServerContainer()->query(Listener::class);
$listener->mapperEvent($event);
};
$dispatcher->addListener(MapperEvent::EVENT_ASSIGN, $mapperListener);
$dispatcher->addListener(MapperEvent::EVENT_UNASSIGN, $mapperListener);
});
\OCA\Files\App::getNavigationManager()->add(function () {
$l = \OC::$server->getL10N(self::APP_ID);

View File

@ -28,6 +28,7 @@ declare(strict_types=1);
namespace OCA\TwoFactorBackupCodes\AppInfo;
use Closure;
use OCA\TwoFactorBackupCodes\Db\BackupCodeMapper;
use OCA\TwoFactorBackupCodes\Event\CodesGenerated;
use OCA\TwoFactorBackupCodes\Listener\ActivityPublisher;
@ -58,9 +59,7 @@ class Application extends App implements IBootstrap {
public function boot(IBootContext $context): void {
Util::connectHook('OC_User', 'post_deleteUser', $this, 'deleteUser');
$this->registerNotification(
$context->getAppContainer()->query(IManager::class)
);
$context->injectFn(Closure::fromCallable([$this, 'registerNotification']));
}
/**

View File

@ -30,13 +30,20 @@ namespace OCA\UpdateNotification\AppInfo;
use OCA\UpdateNotification\Notification\Notifier;
use OCA\UpdateNotification\UpdateChecker;
use OCP\App\IAppManager;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\QueryException;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Notification\IManager as INotificationManager;
use OCP\Util;
use Psr\Container\ContainerInterface;
class Application extends App implements IBootstrap {
public function __construct() {
@ -47,36 +54,41 @@ class Application extends App implements IBootstrap {
}
public function boot(IBootContext $context): void {
$server = $context->getServerContainer();
if ($server->getConfig()->getSystemValue('updatechecker', true) !== true) {
// Updater check is disabled
return;
}
// Always register the notifier, so background jobs (without a user) can send push notifications
$notificationsManager = $server->getNotificationManager();
$notificationsManager->registerNotifierService(Notifier::class);
$user = $server->getUserSession()->getUser();
if (!$user instanceof IUser) {
// Nothing to do for guests
return;
}
if (!$server->getAppManager()->isEnabledForUser('notifications') &&
$server->getGroupManager()->isAdmin($user->getUID())) {
try {
$updateChecker = $server->query(UpdateChecker::class);
} catch (QueryException $e) {
$server->getLogger()->logException($e);
$context->injectFn(function (IConfig $config,
INotificationManager $notificationsManager,
IUserSession $userSession,
IAppManager $appManager,
IGroupManager $groupManager,
ContainerInterface $container,
ILogger $logger) {
if ($config->getSystemValue('updatechecker', true) !== true) {
// Updater check is disabled
return;
}
if ($updateChecker->getUpdateState() !== []) {
Util::addScript('updatenotification', 'legacy-notification');
\OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'populateJavaScriptVariables');
// Always register the notifier, so background jobs (without a user) can send push notifications
$notificationsManager->registerNotifierService(Notifier::class);
$user = $userSession->getUser();
if (!$user instanceof IUser) {
// Nothing to do for guests
return;
}
}
if (!$appManager->isEnabledForUser('notifications') &&
$groupManager->isAdmin($user->getUID())) {
try {
$updateChecker = $container->get(UpdateChecker::class);
} catch (QueryException $e) {
$logger->logException($e);
return;
}
if ($updateChecker->getUpdateState() !== []) {
Util::addScript('updatenotification', 'legacy-notification');
\OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'populateJavaScriptVariables');
}
}
});
}
}

View File

@ -26,6 +26,7 @@
namespace OCA\User_LDAP\AppInfo;
use Closure;
use OCA\Files_External\Service\BackendService;
use OCA\User_LDAP\Controller\RenewPasswordController;
use OCA\User_LDAP\Group_Proxy;
@ -41,9 +42,14 @@ use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IServerContainer;
use OCP\IUserSession;
use OCP\Notification\IManager as INotificationManager;
use Psr\Container\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class Application extends App implements IBootstrap {
public function __construct() {
@ -77,35 +83,37 @@ class Application extends App implements IBootstrap {
}
public function boot(IBootContext $context): void {
$server = $context->getServerContainer();
$config = $server->getConfig();
$context->injectFn(function (IConfig $config,
INotificationManager $notificationManager,
IUserSession $userSession,
ContainerInterface $container,
EventDispatcherInterface $dispatcher,
IGroupManager $groupManager) {
$helper = new Helper($config);
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
if (count($configPrefixes) > 0) {
$ldapWrapper = new LDAP();
$helper = new Helper($config);
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
if (count($configPrefixes) > 0) {
$ldapWrapper = new LDAP();
$notificationManager->registerNotifierService(Notifier::class);
$notificationManager = $server->getNotificationManager();
$notificationManager->registerNotifierService(Notifier::class);
$userSession = $server->getUserSession();
$userPluginManager = $container->get(UserPluginManager::class);
$groupPluginManager = $container->get(GroupPluginManager::class);
$userPluginManager = $server->query(UserPluginManager::class);
$groupPluginManager = $server->query(GroupPluginManager::class);
$userBackend = new User_Proxy(
$configPrefixes, $ldapWrapper, $config, $notificationManager, $userSession, $userPluginManager
);
$groupBackend = new Group_Proxy($configPrefixes, $ldapWrapper, $groupPluginManager);
// register user backend
\OC_User::useBackend($userBackend);
$userBackend = new User_Proxy(
$configPrefixes, $ldapWrapper, $config, $notificationManager, $userSession, $userPluginManager
);
$groupBackend = new Group_Proxy($configPrefixes, $ldapWrapper, $groupPluginManager);
// register user backend
\OC_User::useBackend($userBackend);
// Hook to allow plugins to work on registered backends
$dispatcher->dispatch('OCA\\User_LDAP\\User\\User::postLDAPBackendAdded');
// Hook to allow plugins to work on registered backends
$server->getEventDispatcher()->dispatch('OCA\\User_LDAP\\User\\User::postLDAPBackendAdded');
$groupManager->addBackend($groupBackend);
}
});
$server->getGroupManager()->addBackend($groupBackend);
$this->registerBackendDependents($context->getAppContainer());
}
$context->injectFn(Closure::fromCallable([$this, 'registerBackendDependents']));
\OCP\Util::connectHook(
'\OCA\Files_Sharing\API\Server2Server',
@ -115,10 +123,8 @@ class Application extends App implements IBootstrap {
);
}
public function registerBackendDependents(ContainerInterface $appContainer) {
/** @var IServerContainer $serverContainer */
$serverContainer = $appContainer->get(IServerContainer::class);
$serverContainer->getEventDispatcher()->addListener(
private function registerBackendDependents(ContainerInterface $appContainer, EventDispatcherInterface $dispatcher) {
$dispatcher->addListener(
'OCA\\Files_External::loadAdditionalBackends',
function () use ($appContainer) {
$storagesBackendService = $appContainer->get(BackendService::class);

View File

@ -21,6 +21,7 @@
namespace OCA\WorkflowEngine\AppInfo;
use Closure;
use OCA\WorkflowEngine\Controller\RequestTime;
use OCA\WorkflowEngine\Helper\LogContext;
use OCA\WorkflowEngine\Listener\LoadAdditionalSettingsScriptsListener;
@ -57,11 +58,7 @@ class Application extends App implements IBootstrap {
}
public function boot(IBootContext $context): void {
$this->registerRuleListeners(
$context->getAppContainer()->query(IEventDispatcher::class),
$context->getServerContainer(),
$context->getAppContainer()->query(ILogger::class)
);
$context->injectFn(Closure::fromCallable([$this, 'registerRuleListeners']));
}
private function registerRuleListeners(IEventDispatcher $dispatcher,

View File

@ -57,7 +57,8 @@ class BootContextTest extends TestCase {
public function testGetServerContainer(): void {
$serverContainer = $this->createMock(IServerContainer::class);
$this->appContainer->method('getServer')
$this->appContainer->method('get')
->with(IServerContainer::class)
->willReturn($serverContainer);
$container = $this->context->getServerContainer();