From 8bbc6a6611a015a935e6da9ff4633bdb88a3d40e Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Wed, 27 Jan 2016 19:51:10 -0800 Subject: [PATCH] Fix libraries without section_id in database --- plexpy/__init__.py | 15 +++++++++++++-- plexpy/pmsconnect.py | 8 ++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/plexpy/__init__.py b/plexpy/__init__.py index 03b393f1..c59ee7a2 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -739,7 +739,7 @@ def dbcheck(): 'ALTER TABLE library_sections_temp RENAME TO library_sections' ) except sqlite3.OperationalError: - logger.debug(u"Unable to remove section_id unique constraint from library_sections.") + logger.warn(u"Unable to remove section_id unique constraint from library_sections.") try: c_db.execute( 'DROP TABLE library_sections_temp' @@ -747,6 +747,17 @@ def dbcheck(): except: pass + # Upgrade library_sections table from earlier versions (remove duplicated libraries) + try: + result = c_db.execute('SELECT * FROM library_sections WHERE server_id = ""') + if result.rowcount > 0: + logger.debug(u"Altering database. Removing duplicate libraries from library_sections table.") + c_db.execute( + 'DELETE FROM library_sections WHERE server_id = ""' + ) + except sqlite3.OperationalError: + logger.warn(u"Unable to remove duplicate libraries from library_sections table.") + # Upgrade users table from earlier versions (remove UNIQUE constraint on username) try: result = c_db.execute('PRAGMA index_xinfo("sqlite_autoindex_users_2")') @@ -773,7 +784,7 @@ def dbcheck(): 'ALTER TABLE users_temp RENAME TO users' ) except sqlite3.OperationalError: - logger.debug(u"Unable to remove username unique constraint from users.") + logger.warn(u"Unable to remove username unique constraint from users.") try: c_db.execute( 'DROP TABLE users_temp' diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py index 8f2e0bfd..2a1a76b0 100644 --- a/plexpy/pmsconnect.py +++ b/plexpy/pmsconnect.py @@ -40,15 +40,19 @@ def get_server_friendly_name(): def refresh_libraries(): logger.info(u"PlexPy Pmsconnect :: Requesting libraries list refresh...") - library_sections = PmsConnect().get_library_details() server_id = plexpy.CONFIG.PMS_IDENTIFIER + if not server_id: + logger.error(u"PlexPy Pmsconnect :: No PMS identifier, cannot refresh libraries. Verify server in settings.") + return - library_keys = [] + library_sections = PmsConnect().get_library_details() if library_sections: monitor_db = database.MonitorDatabase() + library_keys = [] + for section in library_sections: section_keys = {'server_id': server_id, 'section_id': section['section_id']}