diff options
-rw-r--r-- | xbmc/video/VideoDatabase.cpp | 63 | ||||
-rw-r--r-- | xbmc/video/VideoDatabase.h | 15 | ||||
-rw-r--r-- | xbmc/video/jobs/VideoLibraryRefreshingJob.cpp | 2 |
3 files changed, 41 insertions, 39 deletions
diff --git a/xbmc/video/VideoDatabase.cpp b/xbmc/video/VideoDatabase.cpp index 686dbbbe3d..cc7bda1fd7 100644 --- a/xbmc/video/VideoDatabase.cpp +++ b/xbmc/video/VideoDatabase.cpp @@ -2623,13 +2623,9 @@ int CVideoDatabase::SetDetailsForMovie(CVideoInfoTag& details, if (idMovie < 0) idMovie = GetMovieId(filePath); - if (idMovie > -1) - DeleteMovie(idMovie, true); // true to keep the table entry - else + if (idMovie == -1) { // only add a new movie if we don't already have a valid idMovie - // (DeleteMovie is called with bKeepId == true so the movie won't - // be removed from the movie table) idMovie = AddNewMovie(details); if (idMovie < 0) { @@ -3702,8 +3698,8 @@ void CVideoDatabase::DeleteBookMarkForEpisode(const CVideoInfoTag& tag) //******************************************************************************************************************************** void CVideoDatabase::DeleteMovie(int idMovie, - bool bKeepId /* = false */, - DeleteMovieCascadeAction ca /* = ALL_ASSETS */) + DeleteMovieCascadeAction ca /* = ALL_ASSETS */, + DeleteMovieHashAction hashAction /* = HASH_DELETE */) { if (idMovie < 0) return; @@ -3717,55 +3713,49 @@ void CVideoDatabase::DeleteMovie(int idMovie, BeginTransaction(); - int idFile = GetDbId(PrepareSQL("SELECT idFile FROM movie WHERE idMovie=%i", idMovie)); + const int idFile{GetDbId(PrepareSQL("SELECT idFile FROM movie WHERE idMovie=%i", idMovie))}; DeleteStreamDetails(idFile); - // keep the movie table entry, linking to tv shows, and bookmarks - // so we can update the data in place - // the ancillary tables are still purged - if (!bKeepId) + if (hashAction == DeleteMovieHashAction::HASH_DELETE) { const std::string path = GetSingleValue(PrepareSQL( "SELECT strPath FROM path JOIN files ON files.idPath=path.idPath WHERE files.idFile=%i", idFile)); if (!path.empty()) InvalidatePathHash(path); + } - const std::string strSQL = PrepareSQL("delete from movie where idMovie=%i", idMovie); - m_pDS->exec(strSQL); + const std::string strSQL{PrepareSQL("DELETE FROM movie WHERE idMovie=%i", idMovie)}; + m_pDS->exec(strSQL); - if (ca == DeleteMovieCascadeAction::ALL_ASSETS) - { - // The default version of the movie was removed by a delete trigger. - // Clean up the other assets attached to the movie, if any. + if (ca == DeleteMovieCascadeAction::ALL_ASSETS) + { + // The default version of the movie was removed by a delete trigger. + // Clean up the other assets attached to the movie, if any. - // need local dataset due to nested DeleteVideoAsset query - std::unique_ptr<Dataset> pDS{m_pDB->CreateDataset()}; + // need local dataset due to nested DeleteVideoAsset query + const std::unique_ptr<Dataset> pDS{m_pDB->CreateDataset()}; - pDS->query( - PrepareSQL("SELECT idFile FROM videoversion WHERE idMedia=%i AND media_type='%s'", - idMovie, MediaTypeMovie)); + pDS->query(PrepareSQL("SELECT idFile FROM videoversion WHERE idMedia=%i AND media_type='%s'", + idMovie, MediaTypeMovie)); - while (!pDS->eof()) + while (!pDS->eof()) + { + if (!DeleteVideoAsset(pDS->fv(0).get_asInt())) { - if (!DeleteVideoAsset(pDS->fv(0).get_asInt())) - { - RollbackTransaction(); - pDS->close(); - return; - } - pDS->next(); + RollbackTransaction(); + pDS->close(); + return; } - pDS->close(); + pDS->next(); } + pDS->close(); } //! @todo move this below CommitTransaction() once UPnP doesn't rely on this anymore - if (!bKeepId) - AnnounceRemove(MediaTypeMovie, idMovie); + AnnounceRemove(MediaTypeMovie, idMovie); CommitTransaction(); - } catch (...) { @@ -12419,7 +12409,8 @@ bool CVideoDatabase::ConvertVideoToVersion(VideoDbContentType itemType, SetVideoVersionDefaultArt(idFile, dbIdSource, itemType); if (itemType == VideoDbContentType::MOVIES) - DeleteMovie(dbIdSource); + DeleteMovie(dbIdSource, DeleteMovieCascadeAction::ALL_ASSETS, + DeleteMovieHashAction::HASH_PRESERVE); } // Rename the default version diff --git a/xbmc/video/VideoDatabase.h b/xbmc/video/VideoDatabase.h index 9c220a47b7..50b7feffde 100644 --- a/xbmc/video/VideoDatabase.h +++ b/xbmc/video/VideoDatabase.h @@ -414,6 +414,12 @@ enum class DeleteMovieCascadeAction ALL_ASSETS }; +enum class DeleteMovieHashAction +{ + HASH_DELETE, + HASH_PRESERVE +}; + #define COMPARE_PERCENTAGE 0.90f // 90% #define COMPARE_PERCENTAGE_MIN 0.50f // 50% @@ -591,6 +597,11 @@ public: const std::map<std::string, std::string>& artwork, int idMVideo = -1); int SetStreamDetailsForFile(const CStreamDetails& details, const std::string& strFileNameAndPath); + /*! + * \brief Clear any existing stream details and add the new provided details to a file. + * \param[in] details New stream details + * \param[in] idFile Identifier of the file + */ void SetStreamDetailsForFileId(const CStreamDetails& details, int idFile); bool SetSingleValue(VideoDbContentType type, int dbId, int dbField, const std::string& strValue); @@ -604,8 +615,8 @@ public: int UpdateDetailsForMovie(int idMovie, CVideoInfoTag& details, const std::map<std::string, std::string> &artwork, const std::set<std::string> &updatedDetails); void DeleteMovie(int idMovie, - bool bKeepId = false, - DeleteMovieCascadeAction action = DeleteMovieCascadeAction::ALL_ASSETS); + DeleteMovieCascadeAction action = DeleteMovieCascadeAction::ALL_ASSETS, + DeleteMovieHashAction hashAction = DeleteMovieHashAction::HASH_DELETE); void DeleteTvShow(int idTvShow, bool bKeepId = false); void DeleteTvShow(const std::string& strPath); void DeleteSeason(int idSeason, bool bKeepId = false); diff --git a/xbmc/video/jobs/VideoLibraryRefreshingJob.cpp b/xbmc/video/jobs/VideoLibraryRefreshingJob.cpp index 958a6f970c..35b5c09445 100644 --- a/xbmc/video/jobs/VideoLibraryRefreshingJob.cpp +++ b/xbmc/video/jobs/VideoLibraryRefreshingJob.cpp @@ -333,7 +333,7 @@ bool CVideoLibraryRefreshingJob::Work(CVideoDatabase &db) if (origDbId > 0) { if (scraper->Content() == CONTENT_MOVIES) - db.DeleteMovie(origDbId, false, DeleteMovieCascadeAction::DEFAULT_VERSION); + db.DeleteMovie(origDbId, DeleteMovieCascadeAction::DEFAULT_VERSION); else if (scraper->Content() == CONTENT_MUSICVIDEOS) db.DeleteMusicVideo(origDbId); else if (scraper->Content() == CONTENT_TVSHOWS) |