diff options
author | Joas Schilling <coding@schilljs.com> | 2022-03-31 20:13:08 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-03-31 20:18:58 +0300 |
commit | 7fe2cf5c54b2f9b4584d639ab66d89d36b28bc76 (patch) | |
tree | 87722a2c37e27dcc556433754460cc3c19cedae9 /lib/Model | |
parent | e9c6de6a94635bd249fdaa407120e6db4b9da865 (diff) |
Handle deleting
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Model')
-rw-r--r-- | lib/Model/AttachmentMapper.php | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/Model/AttachmentMapper.php b/lib/Model/AttachmentMapper.php index 039d7c1c1..484239483 100644 --- a/lib/Model/AttachmentMapper.php +++ b/lib/Model/AttachmentMapper.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace OCA\Talk\Model; use OCP\AppFramework\Db\QBMapper; +use OCP\AppFramework\Db\TTransactional; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; @@ -33,6 +34,7 @@ use OCP\IDBConnection; * @method Attachment[] findEntities(IQueryBuilder $query) */ class AttachmentMapper extends QBMapper { + use TTransactional; /** * @param IDBConnection $db @@ -76,4 +78,22 @@ class AttachmentMapper extends QBMapper { return $this->findEntities($query); } + + public function deleteByMessageId(int $messageId): void { + $query = $this->db->getQueryBuilder(); + $query->delete($this->getTableName()) + ->where($query->expr()->eq('message_id', $query->createNamedParameter($messageId, IQueryBuilder::PARAM_INT))); + + $query->executeStatement(); + } + + public function deleteByRoomId(int $roomId): void { + $query = $this->db->getQueryBuilder(); + $query->delete($this->getTableName()) + ->where($query->expr()->eq('room_id', $query->createNamedParameter($roomId, IQueryBuilder::PARAM_INT))); + + $this->atomic(static function () use ($query) { + $query->executeStatement(); + }, $this->db); + } } |