mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-15 01:32:57 -07:00
Don't delete library history if server_id doesn't match
This commit is contained in:
parent
e0cd6f7071
commit
523e6421be
3 changed files with 37 additions and 22 deletions
|
@ -62,18 +62,26 @@ def delete_rows_from_table(table, row_ids):
|
||||||
if row_ids and isinstance(row_ids, basestring):
|
if row_ids and isinstance(row_ids, basestring):
|
||||||
row_ids = map(helpers.cast_to_int, row_ids.split(','))
|
row_ids = map(helpers.cast_to_int, row_ids.split(','))
|
||||||
|
|
||||||
|
if row_ids:
|
||||||
logger.info(u"Tautulli Database :: Deleting row ids %s from %s database table", row_ids, table)
|
logger.info(u"Tautulli Database :: Deleting row ids %s from %s database table", row_ids, table)
|
||||||
query = "DELETE FROM " + table + " WHERE id IN (%s) " % ','.join(['?'] * len(row_ids))
|
query = "DELETE FROM " + table + " WHERE id IN (%s) " % ','.join(['?'] * len(row_ids))
|
||||||
monitor_db = MonitorDatabase()
|
monitor_db = MonitorDatabase()
|
||||||
|
|
||||||
|
try:
|
||||||
monitor_db.action(query, row_ids)
|
monitor_db.action(query, row_ids)
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(u"Tautulli Database :: Failed to delete rows from %s database table: %s" % (table, row_ids))
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def delete_session_history_rows(row_ids=None):
|
def delete_session_history_rows(row_ids=None):
|
||||||
if row_ids:
|
success = []
|
||||||
for table in ('session_history', 'session_history_media_info', 'session_history_metadata'):
|
for table in ('session_history', 'session_history_media_info', 'session_history_metadata'):
|
||||||
delete_rows_from_table(table=table, row_ids=row_ids)
|
success.append(delete_rows_from_table(table=table, row_ids=row_ids))
|
||||||
return True
|
return all(success)
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def delete_user_history(user_id=None):
|
def delete_user_history(user_id=None):
|
||||||
|
@ -89,19 +97,18 @@ def delete_user_history(user_id=None):
|
||||||
return delete_session_history_rows(row_ids=row_ids)
|
return delete_session_history_rows(row_ids=row_ids)
|
||||||
|
|
||||||
|
|
||||||
def delete_library_history(server_id=None, section_id=None):
|
def delete_library_history(section_id=None):
|
||||||
if server_id and str(section_id).isdigit():
|
if str(section_id).isdigit():
|
||||||
monitor_db = MonitorDatabase()
|
monitor_db = MonitorDatabase()
|
||||||
|
|
||||||
# Get all history associated with the server_id and section_id
|
# Get all history associated with the section_id
|
||||||
result = monitor_db.select('SELECT session_history.id FROM session_history '
|
result = monitor_db.select('SELECT session_history.id FROM session_history '
|
||||||
'JOIN session_history_metadata ON session_history.id = session_history_metadata.id '
|
'JOIN session_history_metadata ON session_history.id = session_history_metadata.id '
|
||||||
'WHERE session_history.server_id = ? AND session_history_metadata.section_id = ?',
|
'WHERE session_history_metadata.section_id = ?',
|
||||||
[server_id, section_id])
|
[section_id])
|
||||||
row_ids = [row['id'] for row in result]
|
row_ids = [row['id'] for row in result]
|
||||||
|
|
||||||
logger.info(u"Tautulli Database :: Deleting all history for library server_id %s and section_id %s from database."
|
logger.info(u"Tautulli Database :: Deleting all history for library section_id %s from database." % section_id)
|
||||||
% (server_id, section_id))
|
|
||||||
return delete_session_history_rows(row_ids=row_ids)
|
return delete_session_history_rows(row_ids=row_ids)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1042,9 +1042,16 @@ class Libraries(object):
|
||||||
|
|
||||||
elif str(section_id).isdigit():
|
elif str(section_id).isdigit():
|
||||||
server_id = server_id or plexpy.CONFIG.PMS_IDENTIFIER
|
server_id = server_id or plexpy.CONFIG.PMS_IDENTIFIER
|
||||||
database.delete_library_history(server_id=server_id, section_id=section_id)
|
if server_id == plexpy.CONFIG.PMS_IDENTIFIER:
|
||||||
|
delete_success = database.delete_library_history(section_id=section_id)
|
||||||
|
else:
|
||||||
|
logger.warn(u"Tautulli Libraries :: Library history not deleted for library section_id %s "
|
||||||
|
u"because library server_id %s does not match Plex server identifier %s."
|
||||||
|
% (section_id, server_id, plexpy.CONFIG.PMS_IDENTIFIER))
|
||||||
|
delete_success = True
|
||||||
|
|
||||||
if purge_only:
|
if purge_only:
|
||||||
return True
|
return delete_success
|
||||||
else:
|
else:
|
||||||
logger.info(u"Tautulli Libraries :: Deleting library with server_id %s and section_id %s from database."
|
logger.info(u"Tautulli Libraries :: Deleting library with server_id %s and section_id %s from database."
|
||||||
% (server_id, section_id))
|
% (server_id, section_id))
|
||||||
|
@ -1052,7 +1059,7 @@ class Libraries(object):
|
||||||
monitor_db.action('UPDATE library_sections '
|
monitor_db.action('UPDATE library_sections '
|
||||||
'SET deleted_section = 1, keep_history = 0, do_notify = 0, do_notify_created = 0 '
|
'SET deleted_section = 1, keep_history = 0, do_notify = 0, do_notify_created = 0 '
|
||||||
'WHERE server_id = ? AND section_id = ?', [server_id, section_id])
|
'WHERE server_id = ? AND section_id = ?', [server_id, section_id])
|
||||||
return True
|
return delete_success
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn(u"Tautulli Libraries :: Unable to execute database query for delete: %s." % e)
|
logger.warn(u"Tautulli Libraries :: Unable to execute database query for delete: %s." % e)
|
||||||
|
|
||||||
|
|
|
@ -681,9 +681,10 @@ class Users(object):
|
||||||
return all(success)
|
return all(success)
|
||||||
|
|
||||||
elif str(user_id).isdigit():
|
elif str(user_id).isdigit():
|
||||||
database.delete_user_history(user_id=user_id)
|
delete_success = database.delete_user_history(user_id=user_id)
|
||||||
|
|
||||||
if purge_only:
|
if purge_only:
|
||||||
return True
|
return delete_success
|
||||||
else:
|
else:
|
||||||
logger.info(u"Tautulli Users :: Deleting user with user_id %s from database."
|
logger.info(u"Tautulli Users :: Deleting user with user_id %s from database."
|
||||||
% user_id)
|
% user_id)
|
||||||
|
@ -691,7 +692,7 @@ class Users(object):
|
||||||
monitor_db.action('UPDATE users '
|
monitor_db.action('UPDATE users '
|
||||||
'SET deleted_user = 1, keep_history = 0, do_notify = 0 '
|
'SET deleted_user = 1, keep_history = 0, do_notify = 0 '
|
||||||
'WHERE user_id = ?', [user_id])
|
'WHERE user_id = ?', [user_id])
|
||||||
return True
|
return delete_success
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn(u"Tautulli Users :: Unable to execute database query for delete: %s." % e)
|
logger.warn(u"Tautulli Users :: Unable to execute database query for delete: %s." % e)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue