diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2022-01-05 13:44:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-05 13:44:07 +0100 |
commit | 773c4079653e3ce804d19de0261037405c7756e6 (patch) | |
tree | 3204294065236fbf8623340b252d4cc374ddb1f5 /lib | |
parent | f9b06def78c60e92c2128a9e1b38074986ff78c6 (diff) | |
parent | 03abaaaee5759e7e01e414fcbab106c7983a6221 (diff) | |
download | nextcloud-server-773c4079653e3ce804d19de0261037405c7756e6.tar.gz nextcloud-server-773c4079653e3ce804d19de0261037405c7756e6.zip |
Merge pull request #29921 from nextcloud/feature/noid/allow-to-count-commments-with-multiple-verbs
Allow to count comments with multiple verbs
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Comments/Manager.php | 32 | ||||
-rw-r--r-- | lib/public/Comments/ICommentsManager.php | 11 |
2 files changed, 39 insertions, 4 deletions
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index 21caf6823f8..d62db2926fb 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -677,6 +677,10 @@ class Manager implements ICommentsManager { * @since 21.0.0 */ public function getNumberOfCommentsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, string $verb = ''): int { + if ($verb !== '') { + return $this->getNumberOfCommentsWithVerbsForObjectSinceComment($objectType, $objectId, $lastRead, [$verb]); + } + $query = $this->dbConn->getQueryBuilder(); $query->select($query->func()->count('id', 'num_messages')) ->from('comments') @@ -684,11 +688,31 @@ class Manager implements ICommentsManager { ->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId))) ->andWhere($query->expr()->gt('id', $query->createNamedParameter($lastRead))); - if ($verb !== '') { - $query->andWhere($query->expr()->eq('verb', $query->createNamedParameter($verb))); - } + $result = $query->executeQuery(); + $data = $result->fetch(); + $result->closeCursor(); - $result = $query->execute(); + return (int) ($data['num_messages'] ?? 0); + } + + /** + * @param string $objectType + * @param string $objectId + * @param int $lastRead + * @param string[] $verbs + * @return int + * @since 24.0.0 + */ + public function getNumberOfCommentsWithVerbsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, array $verbs): int { + $query = $this->dbConn->getQueryBuilder(); + $query->select($query->func()->count('id', 'num_messages')) + ->from('comments') + ->where($query->expr()->eq('object_type', $query->createNamedParameter($objectType))) + ->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId))) + ->andWhere($query->expr()->gt('id', $query->createNamedParameter($lastRead))) + ->andWhere($query->expr()->in('verb', $query->createNamedParameter($verbs, IQueryBuilder::PARAM_STR_ARRAY))); + + $result = $query->executeQuery(); $data = $result->fetch(); $result->closeCursor(); diff --git a/lib/public/Comments/ICommentsManager.php b/lib/public/Comments/ICommentsManager.php index 64bb98db478..9aacf028b4e 100644 --- a/lib/public/Comments/ICommentsManager.php +++ b/lib/public/Comments/ICommentsManager.php @@ -201,6 +201,17 @@ interface ICommentsManager { */ public function getNumberOfCommentsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, string $verb = ''): int; + + /** + * @param string $objectType + * @param string $objectId + * @param int $lastRead + * @param string[] $verbs + * @return int + * @since 24.0.0 + */ + public function getNumberOfCommentsWithVerbsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, array $verbs): int; + /** * @param string $objectType * @param string $objectId |