From 05577b535fd85f6a1d6ca4434e48f2bf7ed71b1e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 6 Dec 2024 08:04:45 +0100 Subject: [PATCH] fix(chat): Add a repair-step to handle the last-read-message=0 case Signed-off-by: Joas Schilling --- appinfo/info.xml | 1 + lib/Migration/FixLastReadMessageZero.php | 51 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 lib/Migration/FixLastReadMessageZero.php diff --git a/appinfo/info.xml b/appinfo/info.xml index 7daa6c6eb73..d4aafa346cf 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -79,6 +79,7 @@ OCA\Talk\Migration\ClearResourceAccessCache OCA\Talk\Migration\CacheUserDisplayNames + OCA\Talk\Migration\FixLastReadMessageZero diff --git a/lib/Migration/FixLastReadMessageZero.php b/lib/Migration/FixLastReadMessageZero.php new file mode 100644 index 00000000000..23023f63ed1 --- /dev/null +++ b/lib/Migration/FixLastReadMessageZero.php @@ -0,0 +1,51 @@ +connection->getQueryBuilder(); + $update->update('talk_attendees') + /** + * -2 is {@see ChatManager::UNREAD_FIRST_MESSAGE}, but we can't use + * it in update code, because ChatManager is already loaded with the + * previous implementation. + */ + ->set('last_read_message', $update->createNamedParameter(-2, IQueryBuilder::PARAM_INT)) + ->where($update->expr()->eq('last_read_message', $update->createNamedParameter(0, IQueryBuilder::PARAM_INT))); + $updatedEntries = $update->executeStatement(); + if ($updatedEntries) { + $output->info($updatedEntries . ' attendees have been updated.'); + } + } +}