aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_status/lib
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2024-01-15 15:13:26 +0100
committerAnna <anna@nextcloud.com>2024-01-16 15:38:13 +0100
commit02d077bd494f4fff6a92bcc1e0381636074fbac4 (patch)
treeab8d2e2c280cc9245040d761f843823e0cf68308 /apps/user_status/lib
parent5f0c406e42ee7e8eb3da4a53e324eb166a968047 (diff)
downloadnextcloud-server-02d077bd494f4fff6a92bcc1e0381636074fbac4.tar.gz
nextcloud-server-02d077bd494f4fff6a92bcc1e0381636074fbac4.zip
fix(userstatus): catch unique constraint violation
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'apps/user_status/lib')
-rw-r--r--apps/user_status/lib/Listener/UserLiveStatusListener.php19
1 files changed, 17 insertions, 2 deletions
diff --git a/apps/user_status/lib/Listener/UserLiveStatusListener.php b/apps/user_status/lib/Listener/UserLiveStatusListener.php
index b999c51d72f..d8485a6d0cb 100644
--- a/apps/user_status/lib/Listener/UserLiveStatusListener.php
+++ b/apps/user_status/lib/Listener/UserLiveStatusListener.php
@@ -32,10 +32,12 @@ use OCA\UserStatus\Db\UserStatusMapper;
use OCA\UserStatus\Service\StatusService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\DB\Exception;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\User\Events\UserLiveStatusEvent;
use OCP\UserStatus\IUserStatus;
+use Psr\Log\LoggerInterface;
/**
* Class UserDeletedListener
@@ -50,7 +52,8 @@ class UserLiveStatusListener implements IEventListener {
public function __construct(UserStatusMapper $mapper,
StatusService $statusService,
ITimeFactory $timeFactory,
- private CalendarStatusService $calendarStatusService) {
+ private CalendarStatusService $calendarStatusService,
+ private LoggerInterface $logger) {
$this->mapper = $mapper;
$this->statusService = $statusService;
$this->timeFactory = $timeFactory;
@@ -110,7 +113,19 @@ class UserLiveStatusListener implements IEventListener {
$userStatus->setIsUserDefined(false);
if ($userStatus->getId() === null) {
- $this->mapper->insert($userStatus);
+ try {
+ $this->mapper->insert($userStatus);
+ } catch (Exception $e) {
+ if ($e->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
+ // A different process might have written another status
+ // update to the DB while we're processing our stuff.
+ // We can safely ignore it as we're only changing between AWAY and ONLINE
+ // and not doing anything with the message or icon.
+ $this->logger->debug('Unique constraint violation for live user status', ['exception' => $e]);
+ return;
+ }
+ throw $e;
+ }
} else {
$this->mapper->update($userStatus);
}