From 4d0f0095eafe53f275e3a39b857212d89461f8e9 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Fri, 2 Jul 2021 17:45:03 +0200 Subject: Add logging to external shares manager Instead of just returning false, also log the exception to make debugging database issues easier. Signed-off-by: Vincent Petry --- .../lib/OCM/CloudFederationProviderFiles.php | 3 +- apps/files_sharing/lib/AppInfo/Application.php | 3 +- apps/files_sharing/lib/External/Manager.php | 37 ++++++++++++++-------- apps/files_sharing/lib/Hooks.php | 3 +- apps/files_sharing/tests/External/ManagerTest.php | 2 ++ 5 files changed, 32 insertions(+), 16 deletions(-) (limited to 'apps') diff --git a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php index 26b0288c354..d9ae9f6d733 100644 --- a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php +++ b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php @@ -251,7 +251,8 @@ class CloudFederationProviderFiles implements ICloudFederationProvider { \OC::$server->getGroupManager(), \OC::$server->getUserManager(), $shareWith, - \OC::$server->query(IEventDispatcher::class) + \OC::$server->query(IEventDispatcher::class), + \OC::$server->getLogger() ); try { diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index 7f234e63660..3975a8a3bde 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -98,7 +98,8 @@ class Application extends App { $server->getGroupManager(), $server->getUserManager(), $uid, - $server->query(IEventDispatcher::class) + $server->query(IEventDispatcher::class), + $server->getLogger() ); }); diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php index 247be47ac90..de566692d6b 100644 --- a/apps/files_sharing/lib/External/Manager.php +++ b/apps/files_sharing/lib/External/Manager.php @@ -14,6 +14,7 @@ * @author Robin Appelman * @author Roeland Jago Douma * @author Stefan Weil + * @author Vincent Petry * * @license AGPL-3.0 * @@ -44,6 +45,7 @@ use OCP\Files\Storage\IStorageFactory; use OCP\Http\Client\IClientService; use OCP\IDBConnection; use OCP\IGroupManager; +use OCP\ILogger; use OCP\IUserManager; use OCP\Notification\IManager; use OCP\OCS\IDiscoveryService; @@ -89,18 +91,24 @@ class Manager { /** @var IEventDispatcher */ private $eventDispatcher; - public function __construct(IDBConnection $connection, - \OC\Files\Mount\Manager $mountManager, - IStorageFactory $storageLoader, - IClientService $clientService, - IManager $notificationManager, - IDiscoveryService $discoveryService, - ICloudFederationProviderManager $cloudFederationProviderManager, - ICloudFederationFactory $cloudFederationFactory, - IGroupManager $groupManager, - IUserManager $userManager, - ?string $uid, - IEventDispatcher $eventDispatcher) { + /** @var ILogger */ + private $logger; + + public function __construct( + IDBConnection $connection, + \OC\Files\Mount\Manager $mountManager, + IStorageFactory $storageLoader, + IClientService $clientService, + IManager $notificationManager, + IDiscoveryService $discoveryService, + ICloudFederationProviderManager $cloudFederationProviderManager, + ICloudFederationFactory $cloudFederationFactory, + IGroupManager $groupManager, + IUserManager $userManager, + ?string $uid, + IEventDispatcher $eventDispatcher, + ILogger $logger + ) { $this->connection = $connection; $this->mountManager = $mountManager; $this->storageLoader = $storageLoader; @@ -113,6 +121,7 @@ class Manager { $this->groupManager = $groupManager; $this->userManager = $userManager; $this->eventDispatcher = $eventDispatcher; + $this->logger = $logger; } /** @@ -535,6 +544,7 @@ class Manager { $this->removeReShares($id); } catch (\Doctrine\DBAL\Exception $ex) { + $this->logger->logException($ex); return false; } @@ -606,6 +616,7 @@ class Manager { $deleteResult->closeCursor(); } } catch (\Doctrine\DBAL\Exception $ex) { + $this->logger->logException($ex); return false; } @@ -677,7 +688,7 @@ class Manager { } return array_values($shares); } catch (\Doctrine\DBAL\Exception $e) { - // FIXME + $this->logger->logException($e); return []; } } diff --git a/apps/files_sharing/lib/Hooks.php b/apps/files_sharing/lib/Hooks.php index ff4ca59339a..26e799297ff 100644 --- a/apps/files_sharing/lib/Hooks.php +++ b/apps/files_sharing/lib/Hooks.php @@ -43,7 +43,8 @@ class Hooks { \OC::$server->getGroupManager(), \OC::$server->getUserManager(), $params['uid'], - \OC::$server->query(IEventDispatcher::class) + \OC::$server->query(IEventDispatcher::class), + \OC::$server->getLogger() ); $manager->removeUserShares($params['uid']); diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php index 850265cb9de..b80b9d04e18 100644 --- a/apps/files_sharing/tests/External/ManagerTest.php +++ b/apps/files_sharing/tests/External/ManagerTest.php @@ -43,6 +43,7 @@ use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\IGroup; use OCP\IGroupManager; +use OCP\ILogger; use OCP\IUserManager; use OCP\Share\IShare; use Test\Traits\UserTrait; @@ -127,6 +128,7 @@ class ManagerTest extends TestCase { $this->userManager, $this->uid, $this->eventDispatcher, + $this->createMock(ILogger::class), ] )->setMethods(['tryOCMEndPoint'])->getMock(); -- cgit v1.2.3