diff options
author | dartcafe <github@dartcafe.de> | 2021-05-24 20:48:35 +0300 |
---|---|---|
committer | dartcafe <github@dartcafe.de> | 2021-06-15 11:42:26 +0300 |
commit | b95e380b971c5602a11db6ec040626aab6ca58d8 (patch) | |
tree | d49a884ee7c265daf789553cdcf550be59e415ed /lib/Service/ShareService.php | |
parent | cbff872dddf7f0e8ec07a33560541c4395f72147 (diff) |
Use events for watch and nofication events
Signed-off-by: dartcafe <github@dartcafe.de>
Diffstat (limited to 'lib/Service/ShareService.php')
-rw-r--r-- | lib/Service/ShareService.php | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index 9ad3c3e6..3d571786 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -26,15 +26,18 @@ namespace OCA\Polls\Service; use Psr\Log\LoggerInterface; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\MultipleObjectsReturnedException; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\IGroupManager; +use OCP\Security\ISecureRandom; + use OCA\Polls\Exceptions\NotAuthorizedException; use OCA\Polls\Exceptions\InvalidShareTypeException; use OCA\Polls\Exceptions\ShareAlreadyExistsException; use OCA\Polls\Exceptions\NotFoundException; -use OCP\Security\ISecureRandom; -use OCP\IGroupManager; use OCA\Polls\Db\ShareMapper; use OCA\Polls\Db\Share; +use OCA\Polls\Event\ShareEvent; use OCA\Polls\Model\Acl; use OCA\Polls\Model\UserGroupClass; @@ -49,6 +52,9 @@ class ShareService { /** @var string|null */ private $userId; + /** @var IEventDispatcher */ + private $eventDispatcher; + /** @var IGroupManager */ private $groupManager; @@ -74,6 +80,7 @@ class ShareService { string $AppName, LoggerInterface $logger, ?string $UserId, + IEventDispatcher $eventDispatcher, IGroupManager $groupManager, SystemService $systemService, ShareMapper $shareMapper, @@ -85,6 +92,7 @@ class ShareService { $this->appName = $AppName; $this->logger = $logger; $this->userId = $UserId; + $this->eventDispatcher = $eventDispatcher; $this->groupManager = $groupManager; $this->systemService = $systemService; $this->shareMapper = $shareMapper; @@ -221,7 +229,11 @@ class ShareService { $this->share->setDisplayName($userGroup->getDisplayName()); $this->share->setEmailAddress($userGroup->getEmailAddress()); - return $this->shareMapper->insert($this->share); + $this->share = $this->shareMapper->insert($this->share); + + $this->eventDispatcher->dispatchTyped(new ShareEvent($this->share)); + + return $this->share; } /** @@ -243,8 +255,9 @@ class ShareService { } } - $userGroup = UserGroupClass::getUserGroupChild($type, $userId); - return $this->create($pollId, $userGroup); + $this->create($pollId, UserGroupClass::getUserGroupChild($type, $userId)); + + return $this->share; } /** @@ -264,10 +277,14 @@ class ShareService { $this->systemService->validateEmailAddress($emailAddress, $emptyIsValid); $this->share->setEmailAddress($emailAddress); // TODO: Send confirmation - return $this->shareMapper->update($this->share); + $this->share = $this->shareMapper->update($this->share); } else { throw new InvalidShareTypeException('Email address can only be set in external shares.'); } + + $this->eventDispatcher->dispatchTyped(new ShareEvent($this->share)); + + return $this->share; } /** @@ -327,6 +344,9 @@ class ShareService { } $this->share->setEmailAddress($emailAddress); $this->shareMapper->update($this->share); + + $this->eventDispatcher->dispatchTyped(new ShareEvent($this->share)); + } else { throw new NotAuthorizedException; } @@ -354,6 +374,9 @@ class ShareService { } catch (DoesNotExistException $e) { // silently catch } + + $this->eventDispatcher->dispatchTyped(new ShareEvent($this->share)); + return $token; } |