mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-16 02:02:58 -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):
|
||||
row_ids = map(helpers.cast_to_int, row_ids.split(','))
|
||||
|
||||
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))
|
||||
monitor_db = MonitorDatabase()
|
||||
monitor_db.action(query, row_ids)
|
||||
if row_ids:
|
||||
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))
|
||||
monitor_db = MonitorDatabase()
|
||||
|
||||
try:
|
||||
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):
|
||||
if row_ids:
|
||||
for table in ('session_history', 'session_history_media_info', 'session_history_metadata'):
|
||||
delete_rows_from_table(table=table, row_ids=row_ids)
|
||||
return True
|
||||
return False
|
||||
success = []
|
||||
for table in ('session_history', 'session_history_media_info', 'session_history_metadata'):
|
||||
success.append(delete_rows_from_table(table=table, row_ids=row_ids))
|
||||
return all(success)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def delete_library_history(server_id=None, section_id=None):
|
||||
if server_id and str(section_id).isdigit():
|
||||
def delete_library_history(section_id=None):
|
||||
if str(section_id).isdigit():
|
||||
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 '
|
||||
'JOIN session_history_metadata ON session_history.id = session_history_metadata.id '
|
||||
'WHERE session_history.server_id = ? AND session_history_metadata.section_id = ?',
|
||||
[server_id, section_id])
|
||||
'WHERE session_history_metadata.section_id = ?',
|
||||
[section_id])
|
||||
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."
|
||||
% (server_id, section_id))
|
||||
logger.info(u"Tautulli Database :: Deleting all history for library section_id %s from database." % section_id)
|
||||
return delete_session_history_rows(row_ids=row_ids)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue