|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* ownCloud - Music app |
|
5
|
|
|
* |
|
6
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
7
|
|
|
* later. See the COPYING file. |
|
8
|
|
|
* |
|
9
|
|
|
* @author Pauli Järvinen <[email protected]> |
|
10
|
|
|
* @copyright Pauli Järvinen 2018 - 2020 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace OCA\Music\BusinessLayer; |
|
14
|
|
|
|
|
15
|
|
|
use \OCA\Music\AppFramework\Core\Logger; |
|
16
|
|
|
use \OCA\Music\Utility\CoverHelper; |
|
17
|
|
|
use \OCA\Music\Utility\Util; |
|
18
|
|
|
|
|
19
|
|
|
use \OCP\IL10N; |
|
|
|
|
|
|
20
|
|
|
use \OCP\IURLGenerator; |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
class Library { |
|
23
|
|
|
private $albumBusinessLayer; |
|
24
|
|
|
private $artistBusinessLayer; |
|
25
|
|
|
private $trackBusinessLayer; |
|
26
|
|
|
private $coverHelper; |
|
27
|
|
|
private $urlGenerator; |
|
28
|
|
|
private $l10n; |
|
29
|
|
|
private $logger; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct( |
|
32
|
|
|
AlbumBusinessLayer $albumBusinessLayer, |
|
33
|
|
|
ArtistBusinessLayer $artistBusinessLayer, |
|
34
|
|
|
TrackBusinessLayer $trackBusinessLayer, |
|
35
|
|
|
CoverHelper $coverHelper, |
|
36
|
|
|
IURLGenerator $urlGenerator, |
|
37
|
|
|
IL10N $l10n, |
|
38
|
|
|
Logger $logger) { |
|
39
|
|
|
$this->albumBusinessLayer = $albumBusinessLayer; |
|
40
|
|
|
$this->artistBusinessLayer = $artistBusinessLayer; |
|
41
|
|
|
$this->trackBusinessLayer = $trackBusinessLayer; |
|
42
|
|
|
$this->coverHelper = $coverHelper; |
|
43
|
|
|
$this->urlGenerator = $urlGenerator; |
|
44
|
|
|
$this->l10n = $l10n; |
|
45
|
|
|
$this->logger = $logger; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getTracksAlbumsAndArtists($userId) { |
|
49
|
|
|
// Get all the entities from the DB first. The order of queries is important if we are in |
|
50
|
|
|
// the middle of a scanning process: we don't want to get tracks which do not yet have |
|
51
|
|
|
// an album entry or albums which do not yet have artist entry. |
|
52
|
|
|
/** @var Track[] $allTracks */ |
|
53
|
|
|
$tracks = $this->trackBusinessLayer->findAll($userId); |
|
54
|
|
|
/** @var Album[] $allAlbums */ |
|
55
|
|
|
$albums = $this->albumBusinessLayer->findAll($userId); |
|
56
|
|
|
/** @var Artist[] $allArtists */ |
|
57
|
|
|
$artists = $this->artistBusinessLayer->findAll($userId); |
|
58
|
|
|
|
|
59
|
|
|
$artistsById = Util::createIdLookupTable($artists); |
|
60
|
|
|
$albumsById = Util::createIdLookupTable($albums); |
|
61
|
|
|
|
|
62
|
|
|
foreach ($tracks as $idx => $track) { |
|
63
|
|
|
$album = $albumsById[$track->getAlbumId()]; |
|
64
|
|
|
|
|
65
|
|
|
if (empty($album)) { |
|
66
|
|
|
$this->logger->log("DB error on track {$track->id} '{$track->title}': ". |
|
67
|
|
|
"album with ID {$track->albumId} not found. Skipping the track.", 'warn'); |
|
68
|
|
|
unset($tracks[$idx]); |
|
69
|
|
|
} |
|
70
|
|
|
else { |
|
71
|
|
|
$track->setAlbum($album); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return [ |
|
76
|
|
|
'tracks' => $tracks, |
|
77
|
|
|
'albums' => $albumsById, |
|
78
|
|
|
'artists' => $artistsById |
|
79
|
|
|
]; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function toCollection($userId) { |
|
83
|
|
|
$entities = $this->getTracksAlbumsAndArtists($userId); |
|
84
|
|
|
$coverHashes = $this->coverHelper->getAllCachedAlbumCoverHashes($userId); |
|
85
|
|
|
|
|
86
|
|
|
// Create a multi-level dictionary of tracks where each track can be found |
|
87
|
|
|
// by addressing like $trackDict[artistId][albumId][ordinal]. The tracks are |
|
88
|
|
|
// in the dictionary in the "toCollection" format. |
|
89
|
|
|
$trackDict = []; |
|
90
|
|
|
foreach ($entities['tracks'] as $track) { |
|
91
|
|
|
$trackDict[$track->getAlbum()->getAlbumArtistId()][$track->getAlbumId()][] |
|
92
|
|
|
= $track->toCollection($this->l10n); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
// Then create the actual collection by iterating over the previusly created |
|
96
|
|
|
// dictionary and creating artists and albums in the "toCollection" format. |
|
97
|
|
|
$collection = []; |
|
98
|
|
|
foreach ($trackDict as $artistId => $artistTracksByAlbum) { |
|
99
|
|
|
|
|
100
|
|
|
$artistAlbums = []; |
|
101
|
|
|
foreach ($artistTracksByAlbum as $albumId => $albumTracks) { |
|
102
|
|
|
$coverHash = isset($coverHashes[$albumId]) ? $coverHashes[$albumId] : null; |
|
103
|
|
|
$artistAlbums[] = $entities['albums'][$albumId]->toCollection( |
|
104
|
|
|
$this->urlGenerator, $this->l10n, $coverHash, $albumTracks); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
$collection[] = $entities['artists'][$artistId]->toCollection($this->l10n, $artistAlbums); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
return $collection; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths