Skip to content

Commit

Permalink
Fix Ampache API not working on ownCloud 10.14.0
Browse files Browse the repository at this point in the history
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 #1138
  • Loading branch information
paulijar committed Apr 8, 2024
1 parent 597e170 commit 81d0515
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 16 additions & 29 deletions lib/Controller/AmpacheController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 81d0515

Please sign in to comment.