From dac676c14ef7a3bd866a674c2ced666435d977c6 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 20 Jul 2021 20:36:26 +0200 Subject: [PATCH] Replace ILogger with LoggerInterface in remote share manager Signed-off-by: Vincent Petry Co-authored-by: Carl Schwan --- .../lib/OCM/CloudFederationProviderFiles.php | 3 ++- .../files_sharing/lib/AppInfo/Application.php | 3 ++- apps/files_sharing/lib/External/Manager.php | 20 +++++++++---------- apps/files_sharing/lib/Hooks.php | 3 ++- .../tests/External/ManagerTest.php | 6 +++--- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php index 94fbb7870d5..916a8538c6e 100644 --- a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php +++ b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php @@ -59,6 +59,7 @@ use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IManager; use OCP\Share\IShare; use OCP\Util; +use Psr\Log\LoggerInterface; class CloudFederationProviderFiles implements ICloudFederationProvider { @@ -251,7 +252,7 @@ class CloudFederationProviderFiles implements ICloudFederationProvider { \OC::$server->getUserManager(), $shareWith, \OC::$server->query(IEventDispatcher::class), - \OC::$server->getLogger() + \OC::$server->get(LoggerInterface::class) ); try { diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index 3975a8a3bde..2dfbe4d86a5 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -60,6 +60,7 @@ use OCP\Share\Events\ShareCreatedEvent; use OCP\Share\IManager; use OCP\Util; use Psr\Container\ContainerInterface; +use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; @@ -99,7 +100,7 @@ class Application extends App { $server->getUserManager(), $uid, $server->query(IEventDispatcher::class), - $server->getLogger() + $server->get(LoggerInterface::class) ); }); diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php index b74198c8793..a8b01a74464 100644 --- a/apps/files_sharing/lib/External/Manager.php +++ b/apps/files_sharing/lib/External/Manager.php @@ -46,12 +46,12 @@ 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; use OCP\Share; use OCP\Share\IShare; +use Psr\Log\LoggerInterface; class Manager { public const STORAGE = '\OCA\Files_Sharing\External\Storage'; @@ -92,7 +92,7 @@ class Manager { /** @var IEventDispatcher */ private $eventDispatcher; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; public function __construct( @@ -108,7 +108,7 @@ class Manager { IUserManager $userManager, ?string $uid, IEventDispatcher $eventDispatcher, - ILogger $logger + LoggerInterface $logger ) { $this->connection = $connection; $this->mountManager = $mountManager; @@ -343,7 +343,7 @@ class Manager { $acceptShare->execute([1, $mountPoint, $hash, $subshare['id'], $this->uid]); $result = true; } catch (Exception $e) { - $this->logger->logException($e); + $this->logger->emergency('Could not update share', ['exception' => $e]); $result = false; } } else { @@ -361,7 +361,7 @@ class Manager { $share['share_type']); $result = true; } catch (Exception $e) { - $this->logger->logException($e); + $this->logger->emergency('Could not create share', ['exception' => $e]); $result = false; } } @@ -412,7 +412,7 @@ class Manager { $this->updateAccepted((int)$subshare['id'], false); $result = true; } catch (Exception $e) { - $this->logger->logException($e); + $this->logger->emergency('Could not update share', ['exception' => $e]); $result = false; } } else { @@ -432,7 +432,7 @@ class Manager { $share['share_type']); $result = true; } catch (Exception $e) { - $this->logger->logException($e); + $this->logger->emergency('Could not create share', ['exception' => $e]); $result = false; } } @@ -634,7 +634,7 @@ class Manager { $this->removeReShares($id); } catch (\Doctrine\DBAL\Exception $ex) { - $this->logger->logException($ex); + $this->logger->emergency('Could not update share', ['exception' => $ex]); return false; } @@ -706,7 +706,7 @@ class Manager { $deleteResult->closeCursor(); } } catch (\Doctrine\DBAL\Exception $ex) { - $this->logger->logException($ex); + $this->logger->emergency('Could not get shares', ['exception' => $ex]); return false; } @@ -784,7 +784,7 @@ class Manager { } return array_values($shares); } catch (\Doctrine\DBAL\Exception $e) { - $this->logger->logException($e); + $this->logger->emergency('Error when retrieving shares', ['exception' => $e]); return []; } } diff --git a/apps/files_sharing/lib/Hooks.php b/apps/files_sharing/lib/Hooks.php index 26e799297ff..f28f6910abd 100644 --- a/apps/files_sharing/lib/Hooks.php +++ b/apps/files_sharing/lib/Hooks.php @@ -28,6 +28,7 @@ namespace OCA\Files_Sharing; use OC\Files\Filesystem; use OCP\EventDispatcher\IEventDispatcher; +use Psr\Log\LoggerInterface; class Hooks { public static function deleteUser($params) { @@ -44,7 +45,7 @@ class Hooks { \OC::$server->getUserManager(), $params['uid'], \OC::$server->query(IEventDispatcher::class), - \OC::$server->getLogger() + \OC::$server->get(LoggerInterface::class) ); $manager->removeUserShares($params['uid']); diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php index 86b05f6d2ad..f0e6a0e843b 100644 --- a/apps/files_sharing/tests/External/ManagerTest.php +++ b/apps/files_sharing/tests/External/ManagerTest.php @@ -44,9 +44,9 @@ use OCP\Http\Client\IResponse; use OCP\IGroup; use OCP\IGroupManager; use OCP\IURLGenerator; -use OCP\ILogger; use OCP\IUserManager; use OCP\Share\IShare; +use Psr\Log\LoggerInterface; use Test\Traits\UserTrait; /** @@ -114,8 +114,8 @@ class ManagerTest extends TestCase { ->method('search') ->willReturn([]); - $logger = $this->createMock(ILogger::class); - $logger->expects($this->never())->method('logException'); + $logger = $this->createMock(LoggerInterface::class); + $logger->expects($this->never())->method('emergency'); $this->manager = $this->getMockBuilder(Manager::class) ->setConstructorArgs( -- 2.39.5