From ff7bf7d0cca6b8d599b5a7b218191bb7d38fe6e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 3 May 2021 08:07:58 +0200 Subject: [PATCH] Catch any error during circle detail fetching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Db/BoardMapper.php | 15 ++++++++++----- tests/unit/Db/BoardMapperTest.php | 4 +++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/Db/BoardMapper.php b/lib/Db/BoardMapper.php index 3553be9f8..0eb83b668 100644 --- a/lib/Db/BoardMapper.php +++ b/lib/Db/BoardMapper.php @@ -28,6 +28,7 @@ use OCP\ILogger; use OCP\IUserManager; use OCP\IGroupManager; +use Psr\Log\LoggerInterface; class BoardMapper extends DeckMapper implements IPermissionMapper { private $labelMapper; @@ -35,6 +36,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { private $stackMapper; private $userManager; private $groupManager; + private $logger; private $circlesEnabled; @@ -44,7 +46,8 @@ public function __construct( AclMapper $aclMapper, StackMapper $stackMapper, IUserManager $userManager, - IGroupManager $groupManager + IGroupManager $groupManager, + LoggerInterface $logger ) { parent::__construct($db, 'deck_boards', Board::class); $this->labelMapper = $labelMapper; @@ -52,6 +55,7 @@ public function __construct( $this->stackMapper = $stackMapper; $this->userManager = $userManager; $this->groupManager = $groupManager; + $this->logger = $logger; $this->circlesEnabled = \OC::$server->getAppManager()->isEnabledForUser('circles'); } @@ -238,7 +242,7 @@ public function mapAcl(Acl &$acl) { if ($user !== null) { return new User($user); } - \OC::$server->getLogger()->debug('User ' . $acl->getId() . ' not found when mapping acl ' . $acl->getParticipant()); + $this->logger->debug('User ' . $acl->getId() . ' not found when mapping acl ' . $acl->getParticipant()); return null; } if ($acl->getType() === Acl::PERMISSION_TYPE_GROUP) { @@ -246,7 +250,7 @@ public function mapAcl(Acl &$acl) { if ($group !== null) { return new Group($group); } - \OC::$server->getLogger()->debug('Group ' . $acl->getId() . ' not found when mapping acl ' . $acl->getParticipant()); + $this->logger->debug('Group ' . $acl->getId() . ' not found when mapping acl ' . $acl->getParticipant()); return null; } if ($acl->getType() === Acl::PERMISSION_TYPE_CIRCLE) { @@ -258,11 +262,12 @@ public function mapAcl(Acl &$acl) { if ($circle) { return new Circle($circle); } - } catch (\Exception $e) { + } catch (\Throwable $e) { + $this->logger->error('Failed to get circle details when building ACL', ['exception' => $e]); } return null; } - \OC::$server->getLogger()->log(ILogger::WARN, 'Unknown permission type for mapping acl ' . $acl->getId()); + $this->logger->warning('Unknown permission type for mapping acl ' . $acl->getId()); return null; }); } diff --git a/tests/unit/Db/BoardMapperTest.php b/tests/unit/Db/BoardMapperTest.php index b34f92b93..3d0b0049a 100644 --- a/tests/unit/Db/BoardMapperTest.php +++ b/tests/unit/Db/BoardMapperTest.php @@ -26,6 +26,7 @@ use OCP\IDBConnection; use OCP\IGroupManager; use OCP\IUserManager; +use Psr\Log\LoggerInterface; use Test\AppFramework\Db\MapperTestUtility; /** @@ -61,7 +62,8 @@ public function setUp(): void { \OC::$server->query(AclMapper::class), \OC::$server->query(StackMapper::class), $this->userManager, - $this->groupManager + $this->groupManager, + $this->createMock(LoggerInterface::class) ); $this->aclMapper = \OC::$server->query(AclMapper::class); $this->labelMapper = \OC::$server->query(LabelMapper::class);