aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_status/lib/Service/StatusService.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_status/lib/Service/StatusService.php')
-rw-r--r--apps/user_status/lib/Service/StatusService.php24
1 files changed, 18 insertions, 6 deletions
diff --git a/apps/user_status/lib/Service/StatusService.php b/apps/user_status/lib/Service/StatusService.php
index 2a761a0f304..188eb26d1d7 100644
--- a/apps/user_status/lib/Service/StatusService.php
+++ b/apps/user_status/lib/Service/StatusService.php
@@ -167,7 +167,7 @@ class StatusService {
$userStatus->setIsBackup(false);
if ($userStatus->getId() === null) {
- return $this->mapper->insert($userStatus);
+ return $this->insertWithoutThrowingUniqueConstrain($userStatus);
}
return $this->mapper->update($userStatus);
@@ -211,7 +211,7 @@ class StatusService {
$userStatus->setStatusMessageTimestamp($this->timeFactory->now()->getTimestamp());
if ($userStatus->getId() === null) {
- return $this->mapper->insert($userStatus);
+ return $this->insertWithoutThrowingUniqueConstrain($userStatus);
}
return $this->mapper->update($userStatus);
@@ -313,7 +313,7 @@ class StatusService {
if ($userStatus->getId() !== null) {
return $this->mapper->update($userStatus);
}
- return $this->mapper->insert($userStatus);
+ return $this->insertWithoutThrowingUniqueConstrain($userStatus);
}
/**
@@ -360,7 +360,7 @@ class StatusService {
$userStatus->setStatusMessageTimestamp($this->timeFactory->now()->getTimestamp());
if ($userStatus->getId() === null) {
- return $this->mapper->insert($userStatus);
+ return $this->insertWithoutThrowingUniqueConstrain($userStatus);
}
return $this->mapper->update($userStatus);
@@ -499,10 +499,10 @@ class StatusService {
return;
}
// If there is a custom message, don't overwrite it
- if(empty($status->getCustomMessage())) {
+ if (empty($status->getCustomMessage())) {
$status->setCustomMessage($predefinedMessage['message']);
}
- if(empty($status->getCustomIcon())) {
+ if (empty($status->getCustomIcon())) {
$status->setCustomIcon($predefinedMessage['icon']);
}
}
@@ -584,4 +584,16 @@ class StatusService {
// For users that matched restore the previous status
$this->mapper->restoreBackupStatuses($restoreIds);
}
+
+ protected function insertWithoutThrowingUniqueConstrain(UserStatus $userStatus): UserStatus {
+ try {
+ return $this->mapper->insert($userStatus);
+ } catch (Exception $e) {
+ // Ignore if a parallel request already set the status
+ if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
+ throw $e;
+ }
+ }
+ return $userStatus;
+ }
}