Also delete orphaned path entries in Kodi DB

This commit is contained in:
croneter 2018-03-11 11:47:04 +01:00
parent 97dc1c1856
commit a7939f8b24
2 changed files with 13 additions and 0 deletions

View file

@ -307,6 +307,7 @@ class Movies(Items):
if update_item:
LOG.info("UPDATE movie itemid: %s - Title: %s", itemid, title)
if fileid != old_fileid:
LOG.debug('Removing old file entry: %s', old_fileid)
self.kodi_db.remove_file(old_fileid)
# Update the movie entry
if v.KODIVERSION >= 17:
@ -869,6 +870,7 @@ class TVShows(Items):
if update_item:
LOG.info("UPDATE episode itemid: %s", itemid)
if fileid != old_fileid:
LOG.debug('Removing old file entry: %s', old_fileid)
self.kodi_db.remove_file(old_fileid)
# Update the movie entry
if v.KODIVERSION >= 17:

View file

@ -209,6 +209,9 @@ class KodiDBMethods(object):
Removes the entry for file_id from the files table. Will also delete
entries from the associated tables: bookmark, settings, streamdetails
"""
self.cursor.execute('SELECT idPath FROM files WHERE idFile = ? LIMIT 1',
(file_id,))
path_id = self.cursor.fetchone()[0]
self.cursor.execute('DELETE FROM files WHERE idFile = ?',
(file_id,))
self.cursor.execute('DELETE FROM bookmark WHERE idFile = ?',
@ -217,6 +220,14 @@ class KodiDBMethods(object):
(file_id,))
self.cursor.execute('DELETE FROM streamdetails WHERE idFile = ?',
(file_id,))
self.cursor.execute('DELETE FROM stacktimes WHERE idFile = ?',
(file_id,))
# Delete orphaned path entry
self.cursor.execute('SELECT idFile FROM files WHERE idPath = ? LIMIT 1',
(path_id,))
if self.cursor.fetchone() is None:
self.cursor.execute('DELETE FROM path WHERE idPath = ?',
(path_id,))
def getFile(self, fileid):