Skip to content

Commit

Permalink
migrate away from removed event dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Aug 9, 2023
1 parent 62aea2d commit 5e0391c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@

namespace OCA\User_SAML\AppInfo;

use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\User_SAML\DavPlugin;
use OCA\User_SAML\Middleware\OnlyLoggedInMiddleware;
use OCA\User_SAML\SAMLSettings;
use OCP\AppFramework\App;
use OCP\AppFramework\IAppContainer;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\SabrePluginEvent;

class Application extends App {
Expand Down Expand Up @@ -61,7 +63,8 @@ public function __construct(array $urlParams = []) {
public function registerDavAuth() {
$container = $this->getContainer();

$dispatcher = $container->getServer()->getEventDispatcher();
/** @var IEventDispatcher $dispatcher */
$dispatcher = $container->getServer()->get(IEventDispatcher::class);
$dispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) use ($container) {
$event->getServer()->addPlugin($container->query(DavPlugin::class));
});
Expand All @@ -74,8 +77,9 @@ private function timezoneHandling() {
$session = $container->getServer()->getSession();
$config = $container->getServer()->getConfig();

$dispatcher = $container->getServer()->getEventDispatcher();
$dispatcher->addListener('OCA\Files::loadAdditionalScripts', function () use ($session, $config, $userSession) {
/** @var IEventDispatcher $dispatcher */
$dispatcher = $container->getServer()->get(IEventDispatcher::class);
$dispatcher->addListener(LoadAdditionalScriptsEvent::class, function (LoadAdditionalScriptsEvent $event) use ($session, $config, $userSession) {
if (!$userSession->isLoggedIn()) {
return;
}
Expand Down
6 changes: 4 additions & 2 deletions lib/UserBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
use OCP\IUserBackend;
use OCP\IUserManager;
use OCP\User\Events\UserChangedEvent;
use OCP\User\Events\UserFirstTimeLoggedInEvent;
use OCP\UserInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

class UserBackend implements IApacheBackend, UserInterface, IUserBackend {
/** @var IConfig */
Expand Down Expand Up @@ -168,7 +168,9 @@ public function initializeHomeDir($uid) {
}
// trigger any other initialization
$user = $this->userManager->get($uid);
\OC::$server->getEventDispatcher()->dispatch(IUser::class . '::firstLogin', new GenericEvent($user));
/** @var IEventDispatcher $dispatcher */
$dispatcher = \OC::$server->get(IEventDispatcher::class);
$dispatcher->dispatchTyped(new UserFirstTimeLoggedInEvent($user));
}

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/stub.phpstub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace OCA\Files\Event {
use OCP\EventDispatcher\Event;
class LoadAdditionalScriptsEvent extends Event {
}
}

0 comments on commit 5e0391c

Please sign in to comment.