Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions apps/user_status/lib/Service/StatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function setStatus(string $userId,
$userStatus->setIsBackup(false);

if ($userStatus->getId() === null) {
return $this->mapper->insert($userStatus);
return $this->insertWithoutThrowingUniqueConstrain($userStatus);
}

return $this->mapper->update($userStatus);
Expand Down Expand Up @@ -211,7 +211,7 @@ public function setPredefinedMessage(string $userId,
$userStatus->setStatusMessageTimestamp($this->timeFactory->now()->getTimestamp());

if ($userStatus->getId() === null) {
return $this->mapper->insert($userStatus);
return $this->insertWithoutThrowingUniqueConstrain($userStatus);
}

return $this->mapper->update($userStatus);
Expand Down Expand Up @@ -313,7 +313,7 @@ public function setUserStatus(string $userId,
if ($userStatus->getId() !== null) {
return $this->mapper->update($userStatus);
}
return $this->mapper->insert($userStatus);
return $this->insertWithoutThrowingUniqueConstrain($userStatus);
}

/**
Expand Down Expand Up @@ -360,7 +360,7 @@ public function setCustomMessage(string $userId,
$userStatus->setStatusMessageTimestamp($this->timeFactory->now()->getTimestamp());

if ($userStatus->getId() === null) {
return $this->mapper->insert($userStatus);
return $this->insertWithoutThrowingUniqueConstrain($userStatus);
}

return $this->mapper->update($userStatus);
Expand Down Expand Up @@ -584,4 +584,16 @@ public function revertMultipleUserStatus(array $userIds, string $messageId): voi
// 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;
}
}
Loading