aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_status
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-02-10 16:51:30 +0100
committerJoas Schilling <coding@schilljs.com>2022-02-15 16:06:32 +0100
commit194338cca3823ec4e1f1f473e278bdb26fb229fa (patch)
treee242b7e8f6dd8f24d22d23749af1ac450882ce6f /apps/user_status
parentc5d11abff9b46cfee186f68f1d9ee575db41ce5e (diff)
downloadnextcloud-server-194338cca3823ec4e1f1f473e278bdb26fb229fa.tar.gz
nextcloud-server-194338cca3823ec4e1f1f473e278bdb26fb229fa.zip
Delete the user status without loading it first
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/user_status')
-rw-r--r--apps/user_status/lib/Db/UserStatusMapper.php19
-rw-r--r--apps/user_status/lib/Service/StatusService.php15
2 files changed, 25 insertions, 9 deletions
diff --git a/apps/user_status/lib/Db/UserStatusMapper.php b/apps/user_status/lib/Db/UserStatusMapper.php
index 51f1b270b45..1bb4ad11be8 100644
--- a/apps/user_status/lib/Db/UserStatusMapper.php
+++ b/apps/user_status/lib/Db/UserStatusMapper.php
@@ -158,4 +158,23 @@ class UserStatusMapper extends QBMapper {
$qb->execute();
}
+
+
+ /**
+ * Deletes a user status so we can restore the backup
+ *
+ * @param string $userId
+ * @param string $messageId
+ * @param string $status
+ * @return bool True if an entry was deleted
+ */
+ public function deleteCurrentStatusToRestoreBackup(string $userId, string $messageId, string $status): bool {
+ $qb = $this->db->getQueryBuilder();
+ $qb->delete($this->tableName)
+ ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)))
+ ->andWhere($qb->expr()->eq('message_id', $qb->createNamedParameter($messageId)))
+ ->andWhere($qb->expr()->eq('status', $qb->createNamedParameter($status)))
+ ->andWhere($qb->expr()->eq('is_backup', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL)));
+ return $qb->executeStatement() > 0;
+ }
}
diff --git a/apps/user_status/lib/Service/StatusService.php b/apps/user_status/lib/Service/StatusService.php
index 1f72fd8a21b..e31b1772c4d 100644
--- a/apps/user_status/lib/Service/StatusService.php
+++ b/apps/user_status/lib/Service/StatusService.php
@@ -468,16 +468,13 @@ class StatusService {
// No user status to revert, do nothing
return;
}
- try {
- $userStatus = $this->mapper->findByUserId($userId);
- if ($userStatus->getMessageId() !== $messageId || $userStatus->getStatus() !== $status) {
- // Another status is set automatically, do nothing
- return;
- }
- $this->mapper->delete($userStatus);
- } catch (DoesNotExistException $ex) {
- // No current status => nothing to delete
+
+ $deleted = $this->mapper->deleteCurrentStatusToRestoreBackup($userId, $messageId ?? '', $status);
+ if (!$deleted) {
+ // Another status is set automatically or no status, do nothing
+ return;
}
+
$backupUserStatus->setIsBackup(false);
// Remove the underscore prefix added when creating the backup
$backupUserStatus->setUserId(substr($backupUserStatus->getUserId(), 1));