Fix OperationalError: enforce Kodi restart with clean DB once

- Fixes #570
This commit is contained in:
croneter 2018-12-10 19:51:17 +01:00
parent d2e0479225
commit 97d829779f
4 changed files with 28 additions and 19 deletions

View file

@ -511,6 +511,10 @@ class InitialSetup(object):
LOG.info("Using PMS %s with machineIdentifier %s",
app.CONN.server, app.CONN.machine_identifier)
self.save_pms_settings(app.CONN.server, self.pms_token)
if utils.settings('kodi_db_has_been_wiped_clean') == 'false':
# If the user chose to go to the PKC settings on the first run
# Will trigger a reboot
utils.wipe_database()
if reboot is True:
utils.reboot_kodi()
return
@ -531,6 +535,10 @@ class InitialSetup(object):
# User already answered the installation questions
if utils.settings('InstallQuestionsAnswered') == 'true':
LOG.info('Installation questions already answered')
if utils.settings('kodi_db_has_been_wiped_clean') == 'false':
# If the user chose to go to the PKC settings on the first run
# Will trigger a reboot
utils.wipe_database()
if reboot is True:
utils.reboot_kodi()
# Reload relevant settings
@ -594,20 +602,18 @@ class InitialSetup(object):
# Make sure that we only ask these questions upon first installation
utils.settings('InstallQuestionsAnswered', value='true')
# New installation - make sure we start with a clean slate
utils.wipe_database()
if goto_settings is False:
# Open Settings page now? You will need to restart!
goto_settings = utils.yesno_dialog(utils.lang(29999),
utils.lang(39017))
if goto_settings:
app.APP.suspend = True
app.APP.stop_pkc = True
executebuiltin(
'Addon.OpenSettings(plugin.video.plexkodiconnect)')
elif reboot is True:
utils.reboot_kodi()
# Reload relevant settings
# New installation - make sure we start with a clean slate
# Will trigger a reboot, usually
utils.wipe_database()
# Reload relevant settings if that is not the case
app.CONN.load()
app.ACCOUNT.load()
app.SYNC.load()

View file

@ -94,6 +94,9 @@ class Service():
self.connection_check_running = False
self.auth_running = False
def isCanceled(self):
return xbmc.abortRequested or app.APP.stop_pkc
def on_connection_check(self, result):
"""
Call this method after PF.check_connection()
@ -361,7 +364,7 @@ class Service():
self.playqueue = playqueue.PlayqueueMonitor()
# Main PKC program loop
while not xbmc.abortRequested:
while not self.isCanceled():
# Check for Kodi profile change
if utils.window('plex_kodiProfile') != v.KODI_PROFILE:
# Profile change happened, terminate this thread and others

View file

@ -403,16 +403,11 @@ def kodi_sql(media_type=None):
else:
db_path = v.DB_VIDEO_PATH
conn = connect(db_path, timeout=5.0)
try:
conn.execute('PRAGMA journal_mode=WAL;')
except OperationalError:
LOG.warn('Issue with sqlite WAL mode - force-rebooting Kodi')
settings('lastfullsync', value='0')
reboot_kodi()
conn.execute('PRAGMA cache_size = -8000;')
conn.execute('PRAGMA synchronous=NORMAL;')
# Use transactions
conn.execute('BEGIN')
# Use transactions
return conn
@ -485,7 +480,11 @@ def wipe_database():
settings('SyncInstallRunDone', value="false")
settings('lastfullsync', value="0")
LOG.info('Wiping done')
init_dbs()
if settings('kodi_db_has_been_wiped_clean') != 'true':
# Root cause is sqlite WAL mode - Kodi might still have DB access open
LOG.warn('Need to restart Kodi before filling Kodi DB again')
settings('kodi_db_has_been_wiped_clean', value='true')
reboot_kodi()
def init_dbs():
@ -526,15 +525,15 @@ def reset(ask_user=True):
return
xbmc.sleep(1000)
# Wipe everything
wipe_database()
# Reset all PlexKodiConnect Addon settings? (this is usually NOT
# recommended and unnecessary!)
if ask_user and yesno_dialog(lang(29999), lang(39603)):
# Delete the settings
LOG.info("Deleting: settings.xml")
path_ops.remove("%ssettings.xml" % v.ADDON_PROFILE)
# Wipe everything
wipe_database()
reboot_kodi()

View file

@ -84,6 +84,7 @@
<setting id="FanArtTVAPIKey" type="text" default="639191cb0774661597f28a47e7e2bad5" visible="false"/>
<setting id="syncEmptyShows" type="bool" label="30508" default="false" visible="false"/>
<setting id="lastfullsync" type="number" label="Time stamp when last successful full sync was conducted" default="0" visible="false" />
<setting id="kodi_db_has_been_wiped_clean" type="bool" label="PKC needs to completely clean the Kodi DB at least once, then reboot, to avoid Kodi error messages, e.g. OperationalError" default="false" visible="false" />
</category>
<category label="39057"><!-- Customize Paths -->