Ensure deletion of countries in Kodi DB for movies

This commit is contained in:
croneter 2018-02-25 14:15:50 +01:00
parent 5c944cd092
commit b79ed87ea7
2 changed files with 26 additions and 0 deletions

View file

@ -480,6 +480,7 @@ class Movies(Items):
artwork.deleteArtwork(kodi_id, kodi_type, kodicursor) artwork.deleteArtwork(kodi_id, kodi_type, kodicursor)
if kodi_type == v.KODI_TYPE_MOVIE: if kodi_type == v.KODI_TYPE_MOVIE:
self.kodi_db.delete_countries(kodi_id, kodi_type)
# Delete kodi movie and file # Delete kodi movie and file
kodicursor.execute("DELETE FROM movie WHERE idMovie = ?", kodicursor.execute("DELETE FROM movie WHERE idMovie = ?",
(kodi_id,)) (kodi_id,))

View file

@ -273,6 +273,31 @@ class KodiDBMethods(object):
) )
self.cursor.execute(query, (country_id, kodiid, mediatype)) self.cursor.execute(query, (country_id, kodiid, mediatype))
def delete_countries(self, kodi_id, kodi_type):
"""
Assuming that video kodi_id, kodi_type gets deleted, will delete any
associated country links in the table country_link and also deletes
orphaned countries in the table country
"""
# Get all existing links
query = '''
SELECT country_id FROM country_link
WHERE media_id = ? AND media_type = ?
'''
self.cursor.execute(query, (kodi_id, kodi_type))
country_ids = self.cursor.fetchall()
# Delete all links
query = 'DELETE FROM country_link WHERE media_id = ? AND media_type = ?'
self.cursor.execute(query, (kodi_id, kodi_type))
# Which countries are now orphaned?
query = 'SELECT country_id FROM country_link WHERE country_id = ?'
query_delete = 'DELETE FROM country WHERE country_id = ?'
for country_id in country_ids:
# country_id still in table?
self.cursor.execute(query, (country_id,))
if self.cursor.fetchone() is None:
self.cursor.execute(query_delete, (country_id,))
def _getactorid(self, name): def _getactorid(self, name):
""" """
Crucial für sync speed! Crucial für sync speed!