diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-11-20 14:22:00 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-12-03 08:03:57 +0100 |
commit | cc80339b39d998c615a5648d2c86b1e431a8b023 (patch) | |
tree | 3fed2c67f37db1e9746bc79013f17a2463896d73 /lib/private/User/Manager.php | |
parent | e5c95eed69a1d5e96b69147e4e7f6e40d21c8f9b (diff) | |
download | nextcloud-server-cc80339b39d998c615a5648d2c86b1e431a8b023.tar.gz nextcloud-server-cc80339b39d998c615a5648d2c86b1e431a8b023.zip |
Add typed create user events
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/User/Manager.php')
-rw-r--r-- | lib/private/User/Manager.php | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index da2d354b7ef..29cae3da79b 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -33,12 +33,15 @@ namespace OC\User; use OC\Hooks\PublicEmitter; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IGroup; use OCP\IUser; use OCP\IUserBackend; use OCP\IUserManager; use OCP\User\Backend\IGetRealUIDBackend; +use OCP\User\Events\CreateUserEvent; +use OCP\User\Events\UserCreatedEvent; use OCP\UserInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -72,17 +75,24 @@ class Manager extends PublicEmitter implements IUserManager { /** @var IConfig */ private $config; + /** @var EventDispatcherInterface */ private $dispatcher; - public function __construct(IConfig $config, EventDispatcherInterface $dispatcher) { + /** @var IEventDispatcher */ + private $eventDispatcher; + + public function __construct(IConfig $config, + EventDispatcherInterface $oldDispatcher, + IEventDispatcher $eventDispatcher) { $this->config = $config; - $this->dispatcher = $dispatcher; + $this->dispatcher = $oldDispatcher; $cachedUsers = &$this->cachedUsers; $this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) { /** @var \OC\User\User $user */ unset($cachedUsers[$user->getUID()]); }); + $this->eventDispatcher = $eventDispatcher; } /** @@ -349,6 +359,7 @@ class Manager extends PublicEmitter implements IUserManager { } $this->emit('\OC\User', 'preCreateUser', [$uid, $password]); + $this->eventDispatcher->dispatchTyped(new CreateUserEvent($uid, $password)); $state = $backend->createUser($uid, $password); if($state === false) { throw new \InvalidArgumentException($l->t('Could not create user')); @@ -356,6 +367,7 @@ class Manager extends PublicEmitter implements IUserManager { $user = $this->getUserObject($uid, $backend); if ($user instanceof IUser) { $this->emit('\OC\User', 'postCreateUser', [$user, $password]); + $this->eventDispatcher->dispatchTyped(new UserCreatedEvent($user, $password)); } return $user; } @@ -460,11 +472,11 @@ class Manager extends PublicEmitter implements IUserManager { ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled'))) ->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR)); - + $result = $queryBuilder->execute(); $count = $result->fetchColumn(); $result->closeCursor(); - + if ($count !== false) { $count = (int)$count; } else { @@ -494,7 +506,7 @@ class Manager extends PublicEmitter implements IUserManager { $result = $queryBuilder->execute(); $count = $result->fetchColumn(); $result->closeCursor(); - + if ($count !== false) { $count = (int)$count; } else { |