Commit d298ff7b authored by Matthieu Gallien's avatar Matthieu Gallien 🎵

partial fix for the failing DB automated tests

still some problems and tests errors
parent 6336cb6c
......@@ -1211,8 +1211,8 @@ private Q_SLOTS:
QCOMPARE(musicDbArtistRemovedSpy.count(), 0);
QCOMPARE(musicDbAlbumRemovedSpy.count(), 0);
QCOMPARE(musicDbTrackRemovedSpy.count(), 0);
QCOMPARE(musicDbAlbumModifiedSpy.count(), 2);
QCOMPARE(musicDbTrackModifiedSpy.count(), 2);
QCOMPARE(musicDbAlbumModifiedSpy.count(), 0);
QCOMPARE(musicDbTrackModifiedSpy.count(), 1);
QCOMPARE(musicDbDatabaseErrorSpy.count(), 0);
QCOMPARE(musicDb.allAlbumsData().count(), 5);
......@@ -2223,7 +2223,7 @@ private Q_SLOTS:
QCOMPARE(musicDbAlbumRemovedSpy.count(), 0);
QCOMPARE(musicDbTrackRemovedSpy.count(), 1);
QCOMPARE(musicDbAlbumModifiedSpy.count(), 2);
QCOMPARE(musicDbTrackModifiedSpy.count(), 3);
QCOMPARE(musicDbTrackModifiedSpy.count(), 0);
QCOMPARE(musicDbDatabaseErrorSpy.count(), 0);
auto allAlbums3 = musicDb.allAlbumsData();
......@@ -2509,7 +2509,7 @@ private Q_SLOTS:
QCOMPARE(musicDbAlbumRemovedSpy.count(), 0);
QCOMPARE(musicDbTrackRemovedSpy.count(), 0);
QCOMPARE(musicDbAlbumModifiedSpy.count(), 1);
QCOMPARE(musicDbTrackModifiedSpy.count(), 3);
QCOMPARE(musicDbTrackModifiedSpy.count(), 0);
QCOMPARE(musicDbDatabaseErrorSpy.count(), 0);
}
......@@ -2629,7 +2629,7 @@ private Q_SLOTS:
QStringLiteral("artist9"), QStringLiteral("album3"), QStringLiteral("artist2"), 6, 1,
QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))},
QDateTime::fromMSecsSinceEpoch(23),
QUrl::fromLocalFile(QStringLiteral("album3")), 5, true,
QUrl::fromLocalFile(QStringLiteral("image$19")), 5, true,
QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1"), false};
auto newTracks2 = DataTypes::ListTrackDataType();
newTracks2.push_back(newTrack2);
......@@ -2677,7 +2677,7 @@ private Q_SLOTS:
QCOMPARE(secondTrackAlbumArtist, QStringLiteral("artist2"));
QCOMPARE(secondTrackAlbum, QStringLiteral("album3"));
QCOMPARE(secondTrackImage.isValid(), true);
QCOMPARE(secondTrackImage, QUrl::fromLocalFile(QStringLiteral("album3")));
QCOMPARE(secondTrackImage, QUrl::fromLocalFile(QStringLiteral("image$19")));
QCOMPARE(secondTrackDuration, QTime::fromMSecsSinceStartOfDay(23));
QCOMPARE(secondTrackMilliSecondsDuration, 23);
QCOMPARE(secondTrackTrackNumber, 6);
......@@ -2699,7 +2699,7 @@ private Q_SLOTS:
QCOMPARE(firstAlbumTitle2, QStringLiteral("album3"));
QCOMPARE(firstAlbumArtist2, QStringLiteral("artist2"));
QCOMPARE(firstAlbumImage2.isValid(), true);
QCOMPARE(firstAlbumImage2, QUrl::fromLocalFile(QStringLiteral("album3")));
QCOMPARE(firstAlbumImage2, QUrl::fromLocalFile(QStringLiteral("image$19")));
QCOMPARE(firstAlbumTracksCount2, 1);
QCOMPARE(firstAlbumIsSingleDiscAlbum2, true);
}
......@@ -3462,7 +3462,7 @@ private Q_SLOTS:
QCOMPARE(musicDbAlbumRemovedSpy.count(), 0);
QCOMPARE(musicDbTrackRemovedSpy.count(), 0);
QCOMPARE(musicDbAlbumModifiedSpy.count(), 1);
QCOMPARE(musicDbTrackModifiedSpy.count(), 4);
QCOMPARE(musicDbTrackModifiedSpy.count(), 0);
QCOMPARE(musicDbDatabaseErrorSpy.count(), 0);
}
......@@ -3543,8 +3543,8 @@ private Q_SLOTS:
QCOMPARE(musicDbArtistRemovedSpy2.count(), 0);
QCOMPARE(musicDbAlbumRemovedSpy2.count(), 0);
QCOMPARE(musicDbTrackRemovedSpy2.count(), 0);
QCOMPARE(musicDbAlbumModifiedSpy2.count(), 1);
QCOMPARE(musicDbTrackModifiedSpy2.count(), 1);
QCOMPARE(musicDbAlbumModifiedSpy2.count(), 0);
QCOMPARE(musicDbTrackModifiedSpy2.count(), 0);
QCOMPARE(musicDbDatabaseErrorSpy2.count(), 0);
}
......@@ -3847,7 +3847,7 @@ private Q_SLOTS:
QCOMPARE(musicDbAlbumRemovedSpy.count(), 0);
QCOMPARE(musicDbTrackRemovedSpy.count(), 0);
QCOMPARE(musicDbAlbumModifiedSpy.count(), 1);
QCOMPARE(musicDbTrackModifiedSpy.count(), 1);
QCOMPARE(musicDbTrackModifiedSpy.count(), 0);
QCOMPARE(musicDbDatabaseErrorSpy.count(), 0);
auto firstTrack = musicDb.trackDataFromDatabaseId(musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist4"),
......@@ -4245,7 +4245,7 @@ private Q_SLOTS:
QCOMPARE(musicDbAlbumRemovedSpy.count(), 0);
QCOMPARE(musicDbTrackRemovedSpy.count(), 0);
QCOMPARE(musicDbAlbumModifiedSpy.count(), 1);
QCOMPARE(musicDbTrackModifiedSpy.count(), 1);
QCOMPARE(musicDbTrackModifiedSpy.count(), 0);
QCOMPARE(musicDbDatabaseErrorSpy.count(), 0);
auto secondTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track8"), QStringLiteral("artist9"),
......@@ -4281,39 +4281,6 @@ private Q_SLOTS:
QCOMPARE(secondTrackRating, 5);
QCOMPARE(secondIsSingleDiscAlbum, false);
const auto &modifiedTrackSignal = musicDbTrackModifiedSpy.at(0);
QCOMPARE(modifiedTrackSignal.count(), 1);
const auto &modifiedTrack = modifiedTrackSignal.at(0).value<DataTypes::TrackDataType>();
auto modifiedTrackTitle = modifiedTrack.title();
auto modifiedTrackArtist = modifiedTrack.artist();
auto modifiedTrackAlbumArtist = modifiedTrack.albumArtist();
auto modifiedTrackAlbum = modifiedTrack.album();
auto modifiedTrackImage = modifiedTrack.albumCover();
auto modifiedTrackDuration = modifiedTrack.duration();
auto modifiedTrackMilliSecondsDuration = modifiedTrack.duration().msecsSinceStartOfDay();
auto modifiedTrackTrackNumber = modifiedTrack.trackNumber();
auto modifiedTrackDiscNumber = modifiedTrack.discNumber();
const auto &modifiedTrackResource = modifiedTrack.resourceURI();
auto modifiedTrackRating = modifiedTrack.rating();
auto modifiedTrackIsSingleDiscAlbum = modifiedTrack.isSingleDiscAlbum();
QCOMPARE(modifiedTrack.isValid(), true);
QCOMPARE(modifiedTrackTitle, QStringLiteral("track6"));
QCOMPARE(modifiedTrackArtist, QStringLiteral("artist2"));
QCOMPARE(modifiedTrackAlbumArtist, QStringLiteral("artist2"));
QCOMPARE(modifiedTrackAlbum, QStringLiteral("album3"));
QCOMPARE(modifiedTrackImage.isValid(), true);
QCOMPARE(modifiedTrackImage, QUrl::fromLocalFile(QStringLiteral("album3")));
QCOMPARE(modifiedTrackDuration, QTime::fromMSecsSinceStartOfDay(23));
QCOMPARE(modifiedTrackMilliSecondsDuration, 23);
QCOMPARE(modifiedTrackTrackNumber, 6);
QCOMPARE(modifiedTrackDiscNumber, 1);
QCOMPARE(modifiedTrackResource.isValid(), true);
QCOMPARE(modifiedTrackResource, QUrl::fromLocalFile(QStringLiteral("/$23")));
QCOMPARE(modifiedTrackRating, 5);
QCOMPARE(modifiedTrackIsSingleDiscAlbum, false);
auto allAlbums2 = musicDb.allAlbumsData();
auto firstAlbumData2 = musicDb.albumData(allAlbums2[0].databaseId());
......@@ -5475,6 +5442,8 @@ private Q_SLOTS:
QUrl::fromLocalFile(QStringLiteral("album3")), 5, true,
QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1"), false}};
newTracks.last()[DataTypes::YearRole] = 2020;
auto newCovers = mNewCovers;
newCovers[QStringLiteral("/test/$23")] = QUrl::fromLocalFile(QStringLiteral("album3"));
newCovers[QStringLiteral("/test/$24")] = QUrl::fromLocalFile(QStringLiteral("album3"));
......
......@@ -4901,19 +4901,7 @@ void DatabaseInterface::initRequest()
"LEFT JOIN `Genre` trackGenre ON trackGenre.`Name` = tracks.`Genre` "
"WHERE "
"tracks.`ID` = :trackId AND "
"tracksMapping.`FileName` = tracks.`FileName` AND "
"tracks.`Priority` = ("
" SELECT "
" MIN(`Priority`) "
" FROM "
" `Tracks` tracks2 "
" WHERE "
" tracks.`Title` = tracks2.`Title` AND "
" (tracks.`ArtistName` IS NULL OR tracks.`ArtistName` = tracks2.`ArtistName`) AND "
" (tracks.`AlbumTitle` IS NULL OR tracks.`AlbumTitle` = tracks2.`AlbumTitle`) AND "
" (tracks.`AlbumArtistName` IS NULL OR tracks.`AlbumArtistName` = tracks2.`AlbumArtistName`) AND "
" (tracks.`AlbumPath` IS NULL OR tracks.`AlbumPath` = tracks2.`AlbumPath`)"
")"
"tracksMapping.`FileName` = tracks.`FileName`"
"");
auto result = prepareQuery(d->mSelectTrackFromIdQuery, selectTrackFromIdQueryText);
......@@ -6436,6 +6424,9 @@ qulonglong DatabaseInterface::insertAlbum(const QString &title, const QString &a
if (!albumArtist.isEmpty()) {
const auto similarAlbum = internalOneAlbumPartialData(result);
updateAlbumArtist(result, title, trackPath, albumArtist);
if (updateAlbumCover(result, albumArtURI)) {
recordModifiedAlbum(result);
}
}
return result;
......@@ -6483,38 +6474,10 @@ bool DatabaseInterface::updateAlbumFromId(qulonglong albumId, const QUrl &albumA
const DataTypes::TrackDataType &currentTrack, const QString &albumPath)
{
auto modifiedAlbum = false;
modifiedAlbum = true;
if (!albumArtUri.isValid()) {
return modifiedAlbum;
}
auto storedAlbumArtUri = internalAlbumArtUriFromAlbumId(albumId);
if (!storedAlbumArtUri.isValid() || storedAlbumArtUri != albumArtUri) {
d->mUpdateAlbumArtUriFromAlbumIdQuery.bindValue(QStringLiteral(":albumId"), albumId);
d->mUpdateAlbumArtUriFromAlbumIdQuery.bindValue(QStringLiteral(":coverFileName"), albumArtUri);
auto result = execQuery(d->mUpdateAlbumArtUriFromAlbumIdQuery);
if (!result || !d->mUpdateAlbumArtUriFromAlbumIdQuery.isActive()) {
Q_EMIT databaseError();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::updateAlbumFromId" << d->mUpdateAlbumArtUriFromAlbumIdQuery.lastQuery();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::updateAlbumFromId" << d->mUpdateAlbumArtUriFromAlbumIdQuery.boundValues();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::updateAlbumFromId" << d->mUpdateAlbumArtUriFromAlbumIdQuery.lastError();
d->mUpdateAlbumArtUriFromAlbumIdQuery.finish();
return modifiedAlbum;
}
d->mUpdateAlbumArtUriFromAlbumIdQuery.finish();
modifiedAlbum = true;
}
modifiedAlbum = updateAlbumCover(albumId, albumArtUri);
if (!isValidArtist(albumId) && currentTrack.hasAlbum()) {
if (!isValidArtist(albumId) && currentTrack.hasAlbum() && (currentTrack.hasAlbumArtist() || currentTrack.hasArtist())) {
updateAlbumArtist(albumId, currentTrack.album(), albumPath, currentTrack.albumArtist());
modifiedAlbum = true;
......@@ -6793,22 +6756,29 @@ qulonglong DatabaseInterface::internalInsertTrack(const DataTypes::TrackDataType
if (isModifiedTrack && !oneTrack.title().isEmpty()) {
resultId = existingTrackId;
bool albumInfoIsSame = true;
auto oldTrack = internalTrackFromDatabaseId(existingTrackId);
qCDebug(orgKdeElisaDatabase()) << "DatabaseInterface::internalInsertTrack" << existingTrackId << oldTrack;
oldAlbumId = oldTrack.albumId();
auto isSameTrack = true;
isSameTrack = isSameTrack && (oldTrack.title() == oneTrack.title());
isSameTrack = isSameTrack && (oldTrack.hasAlbum() == oneTrack.hasAlbum());
albumInfoIsSame = albumInfoIsSame && (oldTrack.hasAlbum() == oneTrack.hasAlbum());
if (isSameTrack && oldTrack.hasAlbum()) {
isSameTrack = isSameTrack && (oldTrack.album() == oneTrack.album());
albumInfoIsSame = albumInfoIsSame && (oldTrack.album() == oneTrack.album());
}
isSameTrack = isSameTrack && (oldTrack.hasArtist() == oneTrack.hasArtist());
if (isSameTrack && oldTrack.hasArtist()) {
isSameTrack = isSameTrack && (oldTrack.artist() == oneTrack.artist());
}
isSameTrack = isSameTrack && (oldTrack.hasAlbumArtist() == oneTrack.hasAlbumArtist());
albumInfoIsSame = albumInfoIsSame && (oldTrack.hasAlbumArtist() == oneTrack.hasAlbumArtist());
if (isSameTrack && oldTrack.hasAlbumArtist()) {
isSameTrack = isSameTrack && (oldTrack.albumArtist() == oneTrack.albumArtist());
albumInfoIsSame = albumInfoIsSame && (oldTrack.albumArtist() == oneTrack.albumArtist());
}
isSameTrack = isSameTrack && (oldTrack.hasTrackNumber() == oneTrack.hasTrackNumber());
if (isSameTrack && oldTrack.hasTrackNumber()) {
......@@ -6862,17 +6832,19 @@ qulonglong DatabaseInterface::internalInsertTrack(const DataTypes::TrackDataType
newTrack[DataTypes::ColumnsRoles::DatabaseIdRole] = resultId;
updateTrackInDatabase(newTrack, trackPath);
updateTrackOrigin(oneTrack.resourceURI(), oneTrack.fileModificationTime());
updateAlbumFromId(albumId, oneTrack.albumCover(), oneTrack, trackPath);
auto albumIsModified = updateAlbumFromId(albumId, oneTrack.albumCover(), oneTrack, trackPath);
recordModifiedTrack(existingTrackId);
if (albumId != 0) {
if (albumIsModified && albumId != 0) {
recordModifiedAlbum(albumId);
}
if (oldAlbumId != 0) {
auto tracksCount = fetchTrackIds(oldAlbumId).count();
if (tracksCount) {
recordModifiedAlbum(oldAlbumId);
if (!albumInfoIsSame) {
recordModifiedAlbum(oldAlbumId);
}
} else {
removeAlbumInDatabase(oldAlbumId);
Q_EMIT albumRemoved(oldAlbumId);
......@@ -6909,9 +6881,17 @@ qulonglong DatabaseInterface::internalInsertTrack(const DataTypes::TrackDataType
d->mInsertTrackQuery.bindValue(QStringLiteral(":fileName"), oneTrack.resourceURI());
d->mInsertTrackQuery.bindValue(QStringLiteral(":priority"), priority);
d->mInsertTrackQuery.bindValue(QStringLiteral(":title"), oneTrack.title());
insertArtist(oneTrack.artist());
d->mInsertTrackQuery.bindValue(QStringLiteral(":artistName"), oneTrack.artist());
d->mInsertTrackQuery.bindValue(QStringLiteral(":albumTitle"), oneTrack.album());
if (oneTrack.hasArtist()) {
insertArtist(oneTrack.artist());
d->mInsertTrackQuery.bindValue(QStringLiteral(":artistName"), oneTrack.artist());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":artistName"), {});
}
if (oneTrack.hasAlbum()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":albumTitle"), oneTrack.album());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":albumTitle"), {});
}
if (oneTrack.hasAlbumArtist()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":albumArtistName"), oneTrack.albumArtist());
} else {
......@@ -6945,8 +6925,16 @@ qulonglong DatabaseInterface::internalInsertTrack(const DataTypes::TrackDataType
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":lyricist"), {});
}
d->mInsertTrackQuery.bindValue(QStringLiteral(":comment"), oneTrack.comment());
d->mInsertTrackQuery.bindValue(QStringLiteral(":year"), oneTrack.year());
if (oneTrack.hasComment()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":comment"), oneTrack.comment());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":comment"), {});
}
if (oneTrack.hasYear()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":year"), oneTrack.year());
} else {
d->mInsertTrackQuery.bindValue(QStringLiteral(":year"), {});
}
if (oneTrack.hasChannels()) {
d->mInsertTrackQuery.bindValue(QStringLiteral(":channels"), oneTrack.channels());
} else {
......@@ -8470,6 +8458,38 @@ void DatabaseInterface::updateAlbumArtist(qulonglong albumId, const QString &tit
d->mUpdateAlbumArtistInTracksQuery.finish();
}
bool DatabaseInterface::updateAlbumCover(qulonglong albumId, const QUrl &albumArtUri)
{
bool modifiedAlbum = false;
auto storedAlbumArtUri = internalAlbumArtUriFromAlbumId(albumId);
if (albumArtUri.isValid() && (!storedAlbumArtUri.isValid() || storedAlbumArtUri != albumArtUri)) {
d->mUpdateAlbumArtUriFromAlbumIdQuery.bindValue(QStringLiteral(":albumId"), albumId);
d->mUpdateAlbumArtUriFromAlbumIdQuery.bindValue(QStringLiteral(":coverFileName"), albumArtUri);
auto result = execQuery(d->mUpdateAlbumArtUriFromAlbumIdQuery);
if (!result || !d->mUpdateAlbumArtUriFromAlbumIdQuery.isActive()) {
Q_EMIT databaseError();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::updateAlbumCover" << d->mUpdateAlbumArtUriFromAlbumIdQuery.lastQuery();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::updateAlbumCover" << d->mUpdateAlbumArtUriFromAlbumIdQuery.boundValues();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::updateAlbumCover" << d->mUpdateAlbumArtUriFromAlbumIdQuery.lastError();
d->mUpdateAlbumArtUriFromAlbumIdQuery.finish();
return modifiedAlbum;
}
d->mUpdateAlbumArtUriFromAlbumIdQuery.finish();
modifiedAlbum = true;
}
return modifiedAlbum;
}
void DatabaseInterface::updateTrackStatistics(const QUrl &fileName, const QDateTime &time)
{
d->mUpdateTrackStatistics.bindValue(QStringLiteral(":fileName"), fileName);
......
......@@ -286,6 +286,8 @@ private:
void updateAlbumArtist(qulonglong albumId, const QString &title, const QString &albumPath,
const QString &artistName);
bool updateAlbumCover(qulonglong albumId, const QUrl &albumArtUri);
void updateTrackStatistics(const QUrl &fileName, const QDateTime &time);
void createDatabaseV9();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment