From 81d05153a8e23fee836c9d27cb912bd4661bbc2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pauli=20J=C3=A4rvinen?= Date: Mon, 8 Apr 2024 22:43:59 +0300 Subject: [PATCH] Fix Ampache API not working on ownCloud 10.14.0 The ownCloud version 10.14.0 has changed the Entity base class and any classes (indirectly) inheriting it are no longer allowed to have a constructor taking arguments. Hence, we need to construct our "All Tracks adapter" playlist in the Ampache API a bit differently. refs https://github.com/owncloud/music/issues/1138 --- CHANGELOG.md | 2 ++ lib/Controller/AmpacheController.php | 45 ++++++++++------------------ 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29b9428ad..db97855c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ - Error "Cannot set response code - headers already sent" logged on each played song on PHP 8.3 [#1133](https://github.com/owncloud/music/issues/1133) - Ampache: + * API not working on ownCloud 10.14.0 (HTTP error 500 on all Ampache API calls) + [#1138](https://github.com/owncloud/music/issues/1138) * Advanced search rule `playlist_name` not being case insensitive like the other string rules * Advanced search rules `playlist` and `playlist_name` not working with SQLite * Advanced search operator `does not sound like` not working diff --git a/lib/Controller/AmpacheController.php b/lib/Controller/AmpacheController.php index 0e2149485..fdb4c941e 100644 --- a/lib/Controller/AmpacheController.php +++ b/lib/Controller/AmpacheController.php @@ -659,7 +659,7 @@ protected function playlists( $allTracksIndex = $this->playlistBusinessLayer->count($userId); if (!$hide_search && empty($filter) && empty($add) && empty($update) && self::indexIsWithinOffsetAndLimit($allTracksIndex, $offset, $limit)) { - $playlists[] = new AmpacheController_AllTracksPlaylist($userId, $this->trackBusinessLayer, $this->l10n); + $playlists[] = $this->getAllTracksPlaylist(); } return $this->renderPlaylists($playlists); @@ -671,7 +671,7 @@ protected function playlists( protected function playlist(int $filter) : array { $userId = $this->session->getUserId(); if ($filter == self::ALL_TRACKS_PLAYLIST_ID) { - $playlist = new AmpacheController_AllTracksPlaylist($userId, $this->trackBusinessLayer, $this->l10n); + $playlist = $this->getAllTracksPlaylist(); } else { $playlist = $this->playlistBusinessLayer->find($filter, $userId); } @@ -1576,6 +1576,20 @@ private static function advSearchConvertInput(string $input, string $rule) { } } + private function getAllTracksPlaylist() : Playlist { + $pl = new class extends Playlist { + public $trackCount; + public function getTrackCount() : int { + return $this->trackCount; + } + }; + $pl->id = self::ALL_TRACKS_PLAYLIST_ID; + $pl->name = $this->l10n->t('All tracks'); + $pl->trackCount = $this->trackBusinessLayer->count($this->session->getUserId()); + + return $pl; + } + private function getCover(int $entityId, BusinessLayer $businessLayer) : Response { $userId = $this->session->getUserId(); $userFolder = $this->librarySettings->getFolder($userId); @@ -2160,30 +2174,3 @@ private function mapApiV4ErrorToV5(int $code) : int { } } } - -/** - * Adapter class which acts like the Playlist class for the purpose of - * AmpacheController::renderPlaylists but contains all the track of the user. - */ -class AmpacheController_AllTracksPlaylist extends Playlist { - private $trackBusinessLayer; - private $l10n; - - public function __construct(string $userId, TrackBusinessLayer $trackBusinessLayer, IL10N $l10n) { - $this->userId = $userId; - $this->trackBusinessLayer = $trackBusinessLayer; - $this->l10n = $l10n; - } - - public function getId() : int { - return AmpacheController::ALL_TRACKS_PLAYLIST_ID; - } - - public function getName() : string { - return $this->l10n->t('All tracks'); - } - - public function getTrackCount() : int { - return $this->trackBusinessLayer->count($this->userId); - } -}