This commit is contained in:
sfaulds 2016-09-16 11:46:30 +10:00
commit 828abd807e
3 changed files with 39 additions and 4 deletions

View file

@ -20,6 +20,21 @@ class Embydb_Functions():
self.embycursor = embycursor
def get_version(self, version=None):
if version is not None:
query = "INSERT INTO version(idVersion) VALUES (?)"
self.embycursor.execute(query, (version,))
else:
query = "SELECT idVersion FROM version"
self.embycursor.execute(query)
try:
version = self.embycursor.fetchone()[0]
except TypeError:
pass
return version
def getViews(self):
views = []

View file

@ -311,10 +311,14 @@ class LibrarySync(threading.Thread):
if pDialog:
pDialog.close()
emby_db = embydb.Embydb_Functions(embycursor)
current_version = emby_db.get_version(self.clientInfo.get_version())
window('emby_version', current_version)
embyconn.commit()
embycursor.close()
settings('SyncInstallRunDone', value="true")
settings("dbCreatedWithVersion", self.clientInfo.get_version())
self.saveLastSync()
xbmc.executebuiltin('UpdateLibrary(video)')
elapsedtotal = datetime.now() - starttotal
@ -890,6 +894,7 @@ class LibrarySync(threading.Thread):
def compareDBVersion(self, current, minimum):
# It returns True is database is up to date. False otherwise.
log.info("current: %s minimum: %s" % (current, minimum))
currMajor, currMinor, currPatch = current.split(".")
minMajor, minMinor, minPatch = minimum.split(".")
@ -940,7 +945,20 @@ class LibrarySync(threading.Thread):
if (window('emby_dbCheck') != "true" and settings('SyncInstallRunDone') == "true"):
# Verify the validity of the database
currentVersion = settings('dbCreatedWithVersion')
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor()
emby_db = embydb.Embydb_Functions(embycursor)
currentVersion = emby_db.get_version()
###$ Begin migration $###
if currentVersion is None:
currentVersion = emby_db.get_version(settings('dbCreatedWithVersion'))
embyconn.commit()
log.info("Migration of database version completed")
###$ End migration $###
embycursor.close()
window('emby_version', value=currentVersion)
minVersion = window('emby_minDBVersion')
uptoDate = self.compareDBVersion(currentVersion, minVersion)
@ -974,10 +992,11 @@ class LibrarySync(threading.Thread):
dialog.ok(
heading=lang(29999),
line1=lang(33024))
break
break
# Run start up sync
log.warn("Database version: %s" % settings('dbCreatedWithVersion'))
log.warn("Database version: %s", window('emby_version'))
log.info("SyncDatabase (started)")
startTime = datetime.now()
librarySync = self.startSync()

View file

@ -392,6 +392,7 @@ def reset():
cursor.execute("DELETE FROM " + tablename)
cursor.execute('DROP table IF EXISTS emby')
cursor.execute('DROP table IF EXISTS view')
cursor.execute("DELETE FROM version")
connection.commit()
cursor.close()