From 1f4ab912311a9a5c78e54acbeb8c692e86ae71c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 2 Jun 2020 14:53:02 +0200 Subject: [PATCH] Delete boards that users own once they are deleted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/AppInfo/Application.php | 8 ++++++++ lib/Db/BoardMapper.php | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 7d39ad127..74aa858f4 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -32,6 +32,7 @@ use OCA\Deck\Db\Acl; use OCA\Deck\Db\AclMapper; use OCA\Deck\Db\AssignedUsersMapper; +use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\CardMapper; use OCA\Deck\Middleware\DefaultBoardMiddleware; use OCA\Deck\Middleware\ExceptionMiddleware; @@ -128,6 +129,13 @@ private function registerUserGroupHooks(): void { foreach ($assignments as $assignment) { $assignmentMapper->delete($assignment); } + + /** @var BoardMapper $boardMapper */ + $boardMapper = $container->query(BoardMapper::class); + $boards = $boardMapper->findAllByOwner($user->getUID()); + foreach ($boards as $board) { + $boardMapper->delete($board); + } }); /** @var IUserManager $userManager */ diff --git a/lib/Db/BoardMapper.php b/lib/Db/BoardMapper.php index 43e070a6b..f122e05a4 100644 --- a/lib/Db/BoardMapper.php +++ b/lib/Db/BoardMapper.php @@ -106,6 +106,11 @@ public function findAllByUser($userId, $limit = null, $offset = null, $since = - return $entries; } + public function findAllByOwner(string $userId, int $limit = null, int $offset = null) { + $sql = 'SELECT * FROM `*PREFIX*deck_boards` WHERE owner = ?'; + return $this->findEntities($sql, [$userId], $limit, $offset); + } + /** * Find all boards for a given user *