diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-07-25 20:30:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-25 20:30:00 +0200 |
commit | 61397ee091287e983d0ff345b0e43fb4a3329f19 (patch) | |
tree | 2a04e9f5076d351dc7884c6ba946c80bf002d147 /lib | |
parent | 8255faada4101b91b342bcf929d9a0e4c759cf34 (diff) | |
parent | 2dd55b0550c42355a6188554c3e217870ce37eb5 (diff) | |
download | nextcloud-server-61397ee091287e983d0ff345b0e43fb4a3329f19.tar.gz nextcloud-server-61397ee091287e983d0ff345b0e43fb4a3329f19.zip |
Merge pull request #9222 from nextcloud/feature/noid/search-for-files-by-comments
Allow to search files by comments
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Comments/Manager.php | 48 | ||||
-rw-r--r-- | lib/public/Comments/ICommentsManager.php | 14 |
2 files changed, 62 insertions, 0 deletions
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index d96c22aad51..8f76d49b192 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -494,6 +494,54 @@ class Manager implements ICommentsManager { } /** + * Search for comments with a given content + * + * @param string $search content to search for + * @param string $objectType Limit the search by object type + * @param string $objectId Limit the search by object id + * @param string $verb Limit the verb of the comment + * @param int $offset + * @param int $limit + * @return IComment[] + */ + public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array { + $query = $this->dbConn->getQueryBuilder(); + + $query->select('*') + ->from('comments') + ->where($query->expr()->iLike('message', $query->createNamedParameter( + '%' . $this->dbConn->escapeLikeParameter($search). '%' + ))) + ->orderBy('creation_timestamp', 'DESC') + ->addOrderBy('id', 'DESC') + ->setMaxResults($limit); + + if ($objectType !== '') { + $query->andWhere($query->expr()->eq('object_type', $query->createNamedParameter($objectType))); + } + if ($objectId !== '') { + $query->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId))); + } + if ($verb !== '') { + $query->andWhere($query->expr()->eq('verb', $query->createNamedParameter($verb))); + } + if ($offset !== 0) { + $query->setFirstResult($offset); + } + + $comments = []; + $result = $query->execute(); + while ($data = $result->fetch()) { + $comment = new Comment($this->normalizeDatabaseData($data)); + $this->cache($comment); + $comments[] = $comment; + } + $result->closeCursor(); + + return $comments; + } + + /** * @param $objectType string the object type, e.g. 'files' * @param $objectId string the id of the object * @param \DateTime $notOlderThan optional, timestamp of the oldest comments diff --git a/lib/public/Comments/ICommentsManager.php b/lib/public/Comments/ICommentsManager.php index b3ed176b3b5..ca98214cd72 100644 --- a/lib/public/Comments/ICommentsManager.php +++ b/lib/public/Comments/ICommentsManager.php @@ -139,6 +139,20 @@ interface ICommentsManager { ): array; /** + * Search for comments with a given content + * + * @param string $search content to search for + * @param string $objectType Limit the search by object type + * @param string $objectId Limit the search by object id + * @param string $verb Limit the verb of the comment + * @param int $offset + * @param int $limit + * @return IComment[] + * @since 14.0.0 + */ + public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array; + + /** * @param $objectType string the object type, e.g. 'files' * @param $objectId string the id of the object * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments |