Skip to content

Commit

Permalink
Basic support for Nextcloud 31
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
paulijar committed Jan 26, 2025
1 parent bd302fd commit 8c24894
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [Unreleased]

### Added
- Support for Nextcloud 31

### Changed

Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<dependencies>
<php min-version="7.4" max-version="8.3"/>
<owncloud min-version="10.5" max-version="10" />
<nextcloud min-version="20" max-version="30" />
<nextcloud min-version="20" max-version="31" />
</dependencies>
<types>
<!-- update metadata cache when create/update/delete a file -->
Expand Down
12 changes: 7 additions & 5 deletions lib/AppFramework/Core/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@
* @author Pauli Järvinen <pauli.jarvinen@gmail.com>
* @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;
}
Expand Down
10 changes: 8 additions & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author Morris Jobke <hey@morrisjobke.de>
* @author Pauli Järvinen <pauli.jarvinen@gmail.com>
* @copyright Morris Jobke 2014
* @copyright Pauli Järvinen 2017 - 2024
* @copyright Pauli Järvinen 2017 - 2025
*/

namespace OCA\Music\AppInfo;
Expand Down Expand Up @@ -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
);
});

Expand Down

0 comments on commit 8c24894

Please sign in to comment.