aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2024-04-26 14:05:38 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2024-05-29 10:31:14 +0200
commit9bea6eca981df9b386c212b6678f3c9be7d43672 (patch)
tree981ad7d6c2ee7113b7f4e8d379e49133cf505e48 /apps/dav
parentb3341a17dc7f34e5fb6fe8c83e6de2d97318d4e9 (diff)
downloadnextcloud-server-9bea6eca981df9b386c212b6678f3c9be7d43672.tar.gz
nextcloud-server-9bea6eca981df9b386c212b6678f3c9be7d43672.zip
fix(userstatus): catch unique constrain violation on revert
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/CalDAV/Status/StatusService.php27
1 files changed, 25 insertions, 2 deletions
diff --git a/apps/dav/lib/CalDAV/Status/StatusService.php b/apps/dav/lib/CalDAV/Status/StatusService.php
index 29129a3b073..ed2c233055c 100644
--- a/apps/dav/lib/CalDAV/Status/StatusService.php
+++ b/apps/dav/lib/CalDAV/Status/StatusService.php
@@ -32,6 +32,7 @@ use OCA\UserStatus\Service\StatusService as UserStatusService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Calendar\IManager;
+use OCP\DB\Exception;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IUser as User;
@@ -72,7 +73,18 @@ class StatusService {
}
if(empty($calendarEvents)) {
- $this->userStatusService->revertUserStatus($userId, IUserStatus::MESSAGE_CALENDAR_BUSY);
+ try {
+ $this->userStatusService->revertUserStatus($userId, IUserStatus::MESSAGE_CALENDAR_BUSY);
+ } 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 cannot safely restore the status as we don't know which one is valid at this point
+ // So let's silently log this one and exit
+ $this->logger->debug('Unique constraint violation for live user status', ['exception' => $e]);
+ return;
+ }
+ }
$this->logger->debug('No calendar events found for status check', ['user' => $userId]);
return;
}
@@ -118,7 +130,18 @@ class StatusService {
});
if(empty($applicableEvents)) {
- $this->userStatusService->revertUserStatus($userId, IUserStatus::MESSAGE_CALENDAR_BUSY);
+ try {
+ $this->userStatusService->revertUserStatus($userId, IUserStatus::MESSAGE_CALENDAR_BUSY);
+ } 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 cannot safely restore the status as we don't know which one is valid at this point
+ // So let's silently log this one and exit
+ $this->logger->debug('Unique constraint violation for live user status', ['exception' => $e]);
+ return;
+ }
+ }
$this->logger->debug('No status relevant events found, skipping calendar status change', ['user' => $userId]);
return;
}