From 6cc12fd791e4eb6bcd7cc0132a7089715df08dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Mon, 19 Oct 2015 17:26:06 +0200 Subject: [PATCH] Don't expose deletion methods This might need to be reverted when properly addressing files deletion (while monitoring filesystem or when reloading) However, as of now, I'm not confident this respect the object ownership graph anyway --- src/Album.cpp | 5 ----- src/Album.h | 2 -- src/Movie.cpp | 10 ---------- src/Movie.h | 2 -- src/Show.cpp | 12 ------------ src/Show.h | 1 - src/ShowEpisode.cpp | 8 -------- src/ShowEpisode.h | 1 - test/Albums.cpp | 28 ---------------------------- test/Movies.cpp | 17 ----------------- test/Shows.cpp | 30 ------------------------------ 11 files changed, 116 deletions(-) diff --git a/src/Album.cpp b/src/Album.cpp index 433dea9ba..9b9416339 100644 --- a/src/Album.cpp +++ b/src/Album.cpp @@ -144,11 +144,6 @@ bool Album::addArtist( std::shared_ptr artist ) return sqlite::Tools::executeRequest( m_dbConnection, req, m_id, artist->id() ); } -bool Album::destroy() -{ - return _Cache::destroy( m_dbConnection, this ); -} - bool Album::createTable(DBConnection dbConnection ) { static const std::string req = "CREATE TABLE IF NOT EXISTS " + diff --git a/src/Album.h b/src/Album.h index cd29ae383..ed3132102 100644 --- a/src/Album.h +++ b/src/Album.h @@ -69,8 +69,6 @@ class Album : public IAlbum, public Cache virtual std::vector artists() const override; bool addArtist( std::shared_ptr artist ); - bool destroy(); - static bool createTable( DBConnection dbConnection ); static std::shared_ptr create(DBConnection dbConnection, const std::string& title ); diff --git a/src/Movie.cpp b/src/Movie.cpp index 5e20c4402..218e948ad 100644 --- a/src/Movie.cpp +++ b/src/Movie.cpp @@ -117,16 +117,6 @@ bool Movie::setImdbId( const std::string& imdbId ) return true; } -bool Movie::destroy() -{ - auto fs = files(); - for ( auto& f : fs ) - { - Media::discard( std::static_pointer_cast( f ) ); - } - return _Cache::destroy( m_dbConnection, this ); -} - std::vector Movie::files() { static const std::string req = "SELECT * FROM " + policy::MediaTable::Name diff --git a/src/Movie.h b/src/Movie.h index 0f744c37e..d3400e3b2 100644 --- a/src/Movie.h +++ b/src/Movie.h @@ -57,8 +57,6 @@ class Movie : public IMovie, public Cache bool setImdbId(const std::string& imdbId); virtual std::vector files() override; - bool destroy(); - static bool createTable( DBConnection dbConnection ); static std::shared_ptr create( DBConnection dbConnection, const std::string& title ); diff --git a/src/Show.cpp b/src/Show.cpp index aa8727638..e99d53cf9 100644 --- a/src/Show.cpp +++ b/src/Show.cpp @@ -135,18 +135,6 @@ std::vector Show::episodes() return ShowEpisode::fetchAll( m_dbConnection, req, m_id ); } -bool Show::destroy() -{ - auto eps = episodes(); - //FIXME: This is suboptimal. Each episode::destroy() will fire a SQL request of its own - for ( auto& it : eps ) - { - auto e = std::static_pointer_cast( it ); - e->destroy(); - } - return _Cache::destroy( m_dbConnection, this ); -} - bool Show::createTable(DBConnection dbConnection) { const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::ShowTable::Name + "(" diff --git a/src/Show.h b/src/Show.h index 0d78f6c87..44e7d4762 100644 --- a/src/Show.h +++ b/src/Show.h @@ -62,7 +62,6 @@ class Show : public IShow, public Cache std::shared_ptr addEpisode( const std::string& title, unsigned int episodeNumber ); virtual std::vector episodes() override; - bool destroy(); static bool createTable( DBConnection dbConnection ); static std::shared_ptr create( DBConnection dbConnection, const std::string& name ); diff --git a/src/ShowEpisode.cpp b/src/ShowEpisode.cpp index 06c921ce4..a0611902f 100644 --- a/src/ShowEpisode.cpp +++ b/src/ShowEpisode.cpp @@ -148,14 +148,6 @@ std::vector ShowEpisode::files() return Media::fetchAll( m_dbConnection, req, m_id ); } -bool ShowEpisode::destroy() -{ - auto fs = files(); - for ( auto& f : fs ) - Media::discard( std::static_pointer_cast( f ) ); - return _Cache::destroy( m_dbConnection, this ); -} - bool ShowEpisode::createTable( DBConnection dbConnection ) { const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::ShowEpisodeTable::Name diff --git a/src/ShowEpisode.h b/src/ShowEpisode.h index 62b4df830..3b975f1b2 100644 --- a/src/ShowEpisode.h +++ b/src/ShowEpisode.h @@ -63,7 +63,6 @@ class ShowEpisode : public IShowEpisode, public Cache show() override; virtual std::vector files() override; - bool destroy(); static bool createTable( DBConnection dbConnection ); static std::shared_ptr create( DBConnection dbConnection, const std::string& title, unsigned int episodeNumber, unsigned int showId ); diff --git a/test/Albums.cpp b/test/Albums.cpp index bf234d278..efe4b72bd 100644 --- a/test/Albums.cpp +++ b/test/Albums.cpp @@ -90,20 +90,6 @@ TEST_F( Albums, AssignTrack ) ASSERT_EQ( t->title(), f->name() ); } -//TEST_F( Albums, DeleteTrack ) -//{ -// auto f = ml->addFile( "file.mp3", nullptr ); -// auto a = ml->createAlbum( "album" ); -// auto t = a->addTrack( f, 1 ); -// f->setAlbumTrack( t ); - -// bool res = t->destroy(); -// ASSERT_TRUE( res ); - -// auto f2 = ml->file( "file.mp3" ); -// ASSERT_EQ( f2, nullptr ); -//} - TEST_F( Albums, SetGenre ) { auto a = ml->createAlbum( "album" ); @@ -178,20 +164,6 @@ TEST_F( Albums, FetchAlbumFromTrack ) ASSERT_EQ( a->title(), "album" ); } -TEST_F( Albums, DestroyAlbum ) -{ -// auto a = ml->createAlbum( "album" ); -// auto f = ml->addFile( "file.mp3", nullptr ); -// auto t = a->addTrack( f, 1 ); -// f->setAlbumTrack( t ); - -// bool res = a->destroy(); -// ASSERT_TRUE( res ); - -// f = std::static_pointer_cast( ml->file( "file.mp3" ) ); -// ASSERT_EQ( f, nullptr ); -} - TEST_F( Albums, Artists ) { auto album = ml->createAlbum( "album" ); diff --git a/test/Movies.cpp b/test/Movies.cpp index 75b43934e..4a867c26a 100644 --- a/test/Movies.cpp +++ b/test/Movies.cpp @@ -119,20 +119,3 @@ TEST_F( Movies, AssignToFile ) ASSERT_NE( m2, nullptr ); ASSERT_EQ( m2->title(), "movie" ); } - -TEST_F( Movies, DestroyMovie ) -{ - auto f = ml->addFile( "file.avi", nullptr ); - auto m = ml->createMovie( "movie" ); - - f->setMovie( m ); - m->destroy(); - - auto f2 = ml->file( "file.avi" ); - ASSERT_EQ( f2, nullptr ); - - Reload(); - - f2 = ml->file( "file.avi" ); - ASSERT_EQ( f2, nullptr ); -} diff --git a/test/Shows.cpp b/test/Shows.cpp index 9b07946f2..cb78aa026 100644 --- a/test/Shows.cpp +++ b/test/Shows.cpp @@ -228,33 +228,3 @@ TEST_F( Shows, FileSetShowEpisode ) ASSERT_EQ( e2->name(), "episode 1" ); } -TEST_F( Shows, DeleteShowEpisode ) -{ - auto show = ml->createShow( "show" ); - auto e = show->addEpisode( "episode 1", 1 ); - auto f = ml->addFile( "file.avi", nullptr ); - - f->setShowEpisode( e ); - e->destroy(); - - f = std::static_pointer_cast( ml->file( "file.avi" ) ); - ASSERT_EQ( f, nullptr ); - - Reload(); - - auto f2 = ml->file( "file.avi" ); - ASSERT_EQ( f2, nullptr ); -} - -TEST_F( Shows, DeleteShow ) -{ - auto show = ml->createShow( "show" ); - auto e = show->addEpisode( "episode 1", 1 ); - auto f = ml->addFile( "file.avi", nullptr ); - f->setShowEpisode( e ); - - bool res = show->destroy(); - ASSERT_TRUE( res ); - auto f2 = ml->file( "file.avi" ); - ASSERT_EQ( f2, nullptr ); -} -- GitLab