From 434539c68330470b646277e184ccd24c6ddfa8a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pauli=20J=C3=A4rvinen?= Date: Sun, 26 Jan 2025 17:32:28 +0200 Subject: [PATCH] Basic support for Nextcloud 31 NC 31 has removed the method Server::getLogger() as well as all methods from the ILogger interface. The new alternative for this has existed since NC 20 but it's not there in ownCloud. Hence, we need to be prepared to two different environments. With this change, at least the basic functionality of the Music app works. Everything has not been tested yet. refs https://github.com/owncloud/music/issues/1198 --- CHANGELOG.md | 2 ++ appinfo/info.xml | 2 +- lib/AppFramework/Core/Logger.php | 12 +++++++----- lib/AppInfo/Application.php | 10 ++++++++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69edc55bc..ba8d5a3e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## [Unreleased] ### Added +- Support for Nextcloud 31 + [#1198](https://github.com/owncloud/music/issues/1198) ### Changed diff --git a/appinfo/info.xml b/appinfo/info.xml index a616e25f2..4ed22c647 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -33,7 +33,7 @@ - + diff --git a/lib/AppFramework/Core/Logger.php b/lib/AppFramework/Core/Logger.php index f673ab5e9..c5e9c7275 100644 --- a/lib/AppFramework/Core/Logger.php +++ b/lib/AppFramework/Core/Logger.php @@ -10,18 +10,20 @@ * @author Pauli Järvinen * @copyright Alessandro Cosentino 2012 * @copyright Bernhard Posselt 2012, 2014 - * @copyright Pauli Järvinen 2018 - 2024 + * @copyright Pauli Järvinen 2018 - 2025 */ namespace OCA\Music\AppFramework\Core; -use OCP\ILogger; - class Logger { protected string $appName; - protected ILogger $logger; + /** @var \OCP\ILogger|\Psr\Log\LoggerInterface $logger */ + protected $logger; - public function __construct(string $appName, ILogger $logger) { + /** + * @param \OCP\ILogger|\Psr\Log\LoggerInterface $logger + */ + public function __construct(string $appName, $logger) { $this->appName = $appName; $this->logger = $logger; } diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 73aa9c227..7c17f7528 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -9,7 +9,7 @@ * @author Morris Jobke * @author Pauli Järvinen * @copyright Morris Jobke 2014 - * @copyright Pauli Järvinen 2017 - 2024 + * @copyright Pauli Järvinen 2017 - 2025 */ namespace OCA\Music\AppInfo; @@ -563,9 +563,15 @@ private function registerServices($context) : void { }); $context->registerService('Logger', function (IAppContainer $c) { + // NC 31 removed the getLogger method but the Psr alternative is not available on OC + if (\method_exists($c->getServer(), 'getLogger')) { + $innerLogger = $c->getServer()->getLogger(); + } else { + $innerLogger = $c->query(\Psr\Log\LoggerInterface::class); + } return new Logger( $c->query('AppName'), - $c->getServer()->getLogger() + $innerLogger ); });