diff options
author | René Gieling <github@dartcafe.de> | 2021-01-31 00:59:40 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-31 00:59:40 +0300 |
commit | d2e3dee23b721eed70449530628aba13da3c3fe0 (patch) | |
tree | 4ee406c1ff718a1c44af4223cc4855e2dd89f98d /lib/Service/OptionService.php | |
parent | 726906a68bcbba3efa440c065e72e23501f3d219 (diff) |
Watch events (#1367)
Watch current poll for updates an apply immediately
Diffstat (limited to 'lib/Service/OptionService.php')
-rw-r--r-- | lib/Service/OptionService.php | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/lib/Service/OptionService.php b/lib/Service/OptionService.php index 4e09440a..51bf2c98 100644 --- a/lib/Service/OptionService.php +++ b/lib/Service/OptionService.php @@ -34,32 +34,38 @@ use OCA\Polls\Db\OptionMapper; use OCA\Polls\Db\Option; use OCA\Polls\Db\PollMapper; use OCA\Polls\Db\Poll; +use OCA\Polls\Db\Watch; use OCA\Polls\Model\Acl; class OptionService { - /** @var OptionMapper */ - private $optionMapper; + /** @var Acl */ + private $acl; /** @var Option */ private $option; + /** @var OptionMapper */ + private $optionMapper; + /** @var PollMapper */ private $pollMapper; - /** @var Acl */ - private $acl; + /** @var WatchService */ + private $watchService; public function __construct( - OptionMapper $optionMapper, + Acl $acl, Option $option, + OptionMapper $optionMapper, PollMapper $pollMapper, - Acl $acl + WatchService $watchService ) { - $this->optionMapper = $optionMapper; + $this->acl = $acl; $this->option = $option; + $this->optionMapper = $optionMapper; $this->pollMapper = $pollMapper; - $this->acl = $acl; + $this->watchService = $watchService; } /** @@ -116,10 +122,12 @@ class OptionService { $this->setOption($timestamp, $pollOptionText); try { - return $this->optionMapper->insert($this->option); + $this->option = $this->optionMapper->insert($this->option); + $this->watchService->writeUpdate($this->option->getPollId(), Watch::OBJECT_OPTIONS); } catch (UniqueConstraintViolationException $e) { throw new DuplicateEntryException('This option already exists'); } + return $this->option; } /** @@ -132,7 +140,9 @@ class OptionService { $this->acl->setPollId($this->option->getPollId())->request(Acl::PERMISSION_EDIT); $this->setOption($timestamp, $pollOptionText); - return $this->optionMapper->update($this->option); + $this->option = $this->optionMapper->update($this->option); + $this->watchService->writeUpdate($this->option->getPollId(), Watch::OBJECT_OPTIONS); + return $this->option; } /** @@ -144,6 +154,7 @@ class OptionService { $this->option = $this->optionMapper->find($optionId); $this->acl->setPollId($this->option->getPollId())->request(Acl::PERMISSION_EDIT); $this->optionMapper->delete($this->option); + $this->watchService->writeUpdate($this->option->getPollId(), Watch::OBJECT_OPTIONS); return $this->option; } @@ -163,7 +174,9 @@ class OptionService { $this->option->setConfirmed(time()); } - return $this->optionMapper->update($this->option); + $this->option = $this->optionMapper->update($this->option); + $this->watchService->writeUpdate($this->option->getPollId(), Watch::OBJECT_OPTIONS); + return $this->option; } /** @@ -197,6 +210,7 @@ class OptionService { \OC::$server->getLogger()->warning('skip adding ' . $baseDate->format('c') . 'for pollId' . $this->option->getPollId() . '. Option alredy exists.'); } } + $this->watchService->writeUpdate($this->option->getPollId(), Watch::OBJECT_OPTIONS); return $this->optionMapper->findByPoll($this->option->getPollId()); } @@ -251,6 +265,7 @@ class OptionService { } } + $this->watchService->writeUpdate($pollId, Watch::OBJECT_OPTIONS); return $this->optionMapper->findByPoll($pollId); } @@ -287,6 +302,7 @@ class OptionService { $this->optionMapper->update($option); } + $this->watchService->writeUpdate($this->option->getPollId(), Watch::OBJECT_OPTIONS); return $this->optionMapper->findByPoll($this->option->getPollId()); } |