From 8f060dacf2835f26e4d60bad1e7bceca6ac26c1a Mon Sep 17 00:00:00 2001 From: r0xd4n3t <125836836+r0xd4n3t@users.noreply.github.com> Date: Wed, 16 Apr 2025 13:34:51 +0800 Subject: [PATCH] Fix logging calls: replace deprecated getLogger() with PSR-3 LoggerInterface This patch updates the `OCA\UserExternal\IMAP` class to use the modern PSR-3 LoggerInterface via dependency injection container instead of the deprecated `OC::$server->getLogger()` call. The change ensures compatibility with Nextcloud 21+ and avoids runtime exceptions like: Call to undefined method OC\Server::getLogger() The following lines were updated: - All instances of `\OC::$server->getLogger()->error(...)` are now replaced with `\OC::$server->get(\Psr\Log\LoggerInterface::class)->error(...)` This update resolves login failures due to outdated method calls and restores correct logging behavior for IMAP authentication failures. Tested successfully on Nextcloud 31.0.3. Signed-off-by: r0xd4n3t <125836836+r0xd4n3t@users.noreply.github.com> --- lib/IMAP.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/IMAP.php b/lib/IMAP.php index 2ad784f..b4d8e6a 100644 --- a/lib/IMAP.php +++ b/lib/IMAP.php @@ -71,7 +71,7 @@ public function checkPassword($uid, $password) { $uid = $pieces[0]; } } else { - \OC::$server->getLogger()->error( + \OC::$server->get(\Psr\Log\LoggerInterface::class)->error( 'ERROR: User has a wrong domain! Expecting: '.$this->domain, ['app' => 'user_external'] ); @@ -111,7 +111,7 @@ public function checkPassword($uid, $password) { $errorcode === 28) { # This is not defined in PHP-8.x # 28: CURLE_OPERATION_TIMEDOUT - \OC::$server->getLogger()->error( + \OC::$server->get(\Psr\Log\LoggerInterface::class)->error( 'ERROR: Could not connect to imap server via curl: ' . curl_strerror($errorcode), ['app' => 'user_external'] ); @@ -122,12 +122,12 @@ public function checkPassword($uid, $password) { # 9: CURLE_REMOTE_ACCESS_DENIED # 67: CURLE_LOGIN_DENIED # 94: CURLE_AUTH_ERROR) - \OC::$server->getLogger()->error( + \OC::$server->get(\Psr\Log\LoggerInterface::class)->error( 'ERROR: IMAP Login failed via curl: ' . curl_strerror($errorcode), ['app' => 'user_external'] ); } else { - \OC::$server->getLogger()->error( + \OC::$server->get(\Psr\Log\LoggerInterface::class)->error( 'ERROR: IMAP server returned an error: ' . $errorcode . ' / ' . curl_strerror($errorcode), ['app' => 'user_external'] );