Commit b108bd65 authored by Matěj Laitl's avatar Matěj Laitl
Browse files

SqlTrack: update uidUrl in db if it changes on metadata change

Following scenario lead to statistics, lyrics and labels loss:
 1. make sure a track in local collection is not tagged by
    amarok_afttagger or with musicbrainz uid
 2. turn off "Watch folders for changes" (or work fast)
 3. change title of the track within Amarok
 4. move the file within collection folders using Dolphin
 5. hit "Update Collection"
 6. the stats are lost; normally Amarok should match the track by
    uidUrl, but it isn't updated in the db in step 3., so it doesn't
    find the old track and removes the entry for it.

[Reporters: ^^^ see a nice example of "steps to reproduce"]

This patch changes step 3 to reread and update uidUrl in the database
if necessary.

BUGFIXES:
 * Don't loose statictis, labels and lyrics when changing metadata of a
   track (not tagged by afttagger) followed by moving it.

BUG: 292245
CCMAIL: Ralf Engels <ralf-engels@gmx.de>
FIXED-IN: 2.6
parent 7fae0dfc
......@@ -9,6 +9,8 @@ VERSION 2.6
argument.
BUGFIXES:
* Don't loose statictis, labels and lyrics when changing metadata of a
track (not tagged by afttagger) followed by moving it. (BR 292245)
* Fix Amarok.Playlist.{add,play}Media() and addMediaList() Qt script
bindings methods not being able to add playlists. (BR 232697)
* Add "Last Played" back to the Edit Filter dialog. (BR 302746)
......
......@@ -866,15 +866,6 @@ SqlTrack::commitMetaDataChanges()
// debug() << "m_cache contains a new URL, setting m_url to " << m_url << " from " << oldUrl;
}
// Use the latest uid here
if( m_cache.contains( Meta::valUniqueId ) )
{
QString newUid = m_cache.value( Meta::valUniqueId ).toString();
if( oldUid != newUid &&
m_collection->registry()->updateCachedUid( oldUid, newUid ) )
m_uid = newUid;
}
if( m_cache.contains( Meta::valArtist ) )
{
//invalidate cache of the old artist...
......@@ -969,7 +960,21 @@ SqlTrack::commitMetaDataChanges()
// --- write the file
if( m_writeFile )
writeMetaDataToFile();
{
Meta::Tag::writeTags( m_url.path(), m_cache );
// unique id may have changed
QString uid = Meta::Tag::readTags( m_url.path() ).value( Meta::valUniqueId ).toString();
if( !uid.isEmpty() )
m_cache[ Meta::valUniqueId ] = m_collection->generateUidUrl( uid );
}
// needs to be after writing to file; that may have changed generated uid
if( m_cache.contains( Meta::valUniqueId ) )
{
QString newUid = m_cache.value( Meta::valUniqueId ).toString();
if( oldUid != newUid && m_collection->registry()->updateCachedUid( oldUid, newUid ) )
m_uid = newUid;
}
//updating the fields might have changed the filesize
//read the current filesize so that we can update the db
......@@ -1040,12 +1045,6 @@ SqlTrack::commitMetaDataChanges()
m_cache.clear();
}
void
SqlTrack::writeMetaDataToFile()
{
Meta::Tag::writeTags( m_url.path(), m_cache );
}
void
SqlTrack::updatePlaylistsToDb( const FieldHash &fields, const QString &oldUid )
{
......
......@@ -246,7 +246,6 @@ class AMAROK_SQLCOLLECTION_EXPORT_TESTS SqlTrack : public Meta::Track
if( !m_batchUpdate )
commitMetaDataChanges();
}
void writeMetaDataToFile();
void updatePlaylistsToDb( const FieldHash &fields, const QString &oldUid );
void updateEmbeddedCoversToDb( const FieldHash &fields, const QString &oldUid );
......
Supports Markdown
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