Commit 2fe4350e authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Playlist: Don't store external media type as Unknown

Use External instead, since that's what they are
parent cb253ce8
......@@ -41,6 +41,15 @@
"DROP TABLE " + MediaTable::Name + "_backup",
/************ Playlist external media were stored as Unknown ******************/
"UPDATE " + policy::MediaTable::Name + " SET type = " +
std::to_string( static_cast<typename std::underlying_type<IMedia::Type>::type>(
IMedia::Type::External ) ) + " "
"WHERE id_media IN (SELECT media_id FROM PlaylistMediaRelation) AND "
"type = " + std::to_string( static_cast<typename std::underlying_type<IMedia::Type>::type>(
IMedia::Type::Unknown ) ),
/******************* Migrate metadata table ***********************************/
"CREATE TEMPORARY TABLE " + MetadataTable::Name + "_backup"
"("
......
......@@ -304,7 +304,7 @@ void MetadataAnalyzer::addPlaylistElement( IItem& item,
if ( fsFactory == nullptr ) // Media not supported by any FsFactory, registering it as external
{
auto t2 = m_ml->getConn()->newTransaction();
auto externalMedia = Media::create( m_ml, IMedia::Type::Unknown, utils::url::encode(
auto externalMedia = Media::create( m_ml, IMedia::Type::External, utils::url::encode(
subitem.meta( IItem::Metadata::Title ) ) );
if ( externalMedia == nullptr )
{
......
......@@ -183,7 +183,7 @@ TEST_F( DbModel, Upgrade13to14 )
auto res = ml->initialize( "test.db", "/tmp", cbMock.get() );
ASSERT_EQ( InitializeResult::Success, res );
auto media = ml->files();
ASSERT_EQ( 2u, media.size() );
ASSERT_EQ( 4u, media.size() );
auto m = media[0];
ASSERT_EQ( m->thumbnail(), "/path/to/thumbnail" );
ASSERT_TRUE( m->isThumbnailGenerated() );
......@@ -200,9 +200,16 @@ TEST_F( DbModel, Upgrade13to14 )
auto playlists = ml->playlists( nullptr )->all();
ASSERT_EQ( 1u, playlists.size() );
auto playlistMedia = playlists[0]->media()->all();
ASSERT_EQ( 2u, playlistMedia.size() );
ASSERT_EQ( 3u, playlistMedia.size() );
ASSERT_EQ( media[0]->id(), playlistMedia[0]->id() );
ASSERT_EQ( media[1]->id(), playlistMedia[1]->id() );
ASSERT_EQ( media[2]->id(), playlistMedia[2]->id() );
ASSERT_EQ( IMedia::Type::External, media[2]->type() );
auto externalMedia = ml->media( 99 );
ASSERT_NE( nullptr, externalMedia );
ASSERT_EQ( IMedia::Type::Unknown, externalMedia->type() );
CheckNbTriggers( 32 );
}
......@@ -77,8 +77,13 @@ INSERT INTO `Media` (id_media,type,subtype,duration,play_count,last_played_date,
INSERT INTO `File` (id_file,media_id,playlist_id,mrl,type,last_modification_date,size,folder_id,is_present,is_removable,is_external) VALUES (1,1,NULL,'media.avi',1,NULL,NULL,NULL,1,0,1);
INSERT INTO `Media` (id_media,type,subtype,duration,play_count,last_played_date,insertion_date,release_date,thumbnail,title,filename,is_favorite,is_present) VALUES (2,3,NULL,-1,NULL,NULL,1522231538,NULL,'','media2.avi','media2.avi',0,1);
INSERT INTO `File` (id_file,media_id,playlist_id,mrl,type,last_modification_date,size,folder_id,is_present,is_removable,is_external) VALUES (2,2,NULL,'media2.avi',1,NULL,NULL,NULL,1,0,1);
INSERT INTO `Media` (id_media,type,subtype,duration,play_count,last_played_date,insertion_date,release_date,thumbnail,title,filename,is_favorite,is_present) VALUES (3,0,NULL,-1,NULL,NULL,1522231538,NULL,'','external.avi','external.avi',0,1);
INSERT INTO `File` (id_file,media_id,playlist_id,mrl,type,last_modification_date,size,folder_id,is_present,is_removable,is_external) VALUES (3,3,NULL,'external.avi',1,NULL,NULL,NULL,1,0,1);
INSERT INTO `Media` (id_media,type,subtype,duration,play_count,last_played_date,insertion_date,release_date,thumbnail,title,filename,is_favorite,is_present) VALUES (99,0,NULL,-1,NULL,NULL,1522231538,NULL,'','other_external.avi','other_external.avi',0,1);
INSERT INTO `File` (id_file,media_id,playlist_id,mrl,type,last_modification_date,size,folder_id,is_present,is_removable,is_external) VALUES (99,99,NULL,'other_external.avi',1,NULL,NULL,NULL,1,0,1);
INSERT INTO `MediaMetadata` VALUES(2, 50, "fake progress");
INSERT INTO `Playlist` (id_playlist,name,file_id,creation_date,artwork_mrl) VALUES (1,'test playlist',NULL,1530864508,'');
INSERT INTO `PlaylistMediaRelation` (media_id,playlist_id,position) VALUES (1,1,1);
INSERT INTO `PlaylistMediaRelation` (media_id,playlist_id,position) VALUES (2,1,2);
INSERT INTO `PlaylistMediaRelation` (media_id,playlist_id,position) VALUES (3,1,3);
COMMIT;
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