mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-13 03:22:22 -05:00
Added Transaction for add/update/delete episodes and change episode status
This commit is contained in:
parent
50911a1f0f
commit
972833a7f6
@ -21,7 +21,7 @@ from __future__ import with_statement
|
||||
import sys
|
||||
import os
|
||||
import traceback
|
||||
import urllib, urllib2
|
||||
import urllib
|
||||
import re
|
||||
import datetime
|
||||
import urlparse
|
||||
@ -202,6 +202,7 @@ class KATProvider(generic.TorrentProvider):
|
||||
else:
|
||||
for show_name in set(allPossibleShowNames(ep_obj.show)):
|
||||
ep_string = sanitizeSceneName(show_name) +' '+'season:'+str(ep_obj.season)+' episode:'+str(ep_obj.episode)
|
||||
|
||||
search_string['Episode'].append(re.sub('\s+', ' ', ep_string))
|
||||
|
||||
return [search_string]
|
||||
|
@ -419,6 +419,7 @@ class TVShow(object):
|
||||
|
||||
scannedEps = {}
|
||||
|
||||
sql_l = []
|
||||
for season in showObj:
|
||||
scannedEps[season] = {}
|
||||
for episode in showObj[season]:
|
||||
@ -442,10 +443,14 @@ class TVShow(object):
|
||||
logger.log(str(self.indexerid) + u": Loading info from " + self.indexer + " for episode " + str(season) + "x" + str(episode), logger.DEBUG)
|
||||
ep.loadFromIndexer(season, episode, tvapi=t)
|
||||
if ep.dirty:
|
||||
ep.saveToDB()
|
||||
sql_l.append(ep.get_sql())
|
||||
|
||||
scannedEps[season][episode] = True
|
||||
|
||||
if len(sql_l) > 0:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
# Done updating save last update date
|
||||
self.last_update_indexer = datetime.date.today().toordinal()
|
||||
self.saveToDB()
|
||||
@ -826,9 +831,12 @@ class TVShow(object):
|
||||
def deleteShow(self):
|
||||
|
||||
myDB = db.DBConnection()
|
||||
myDB.action("DELETE FROM tv_episodes WHERE showid = ?", [self.indexerid])
|
||||
myDB.action("DELETE FROM tv_shows WHERE indexer_id = ?", [self.indexerid])
|
||||
myDB.action("DELETE FROM imdb_info WHERE indexer_id = ?", [self.indexerid])
|
||||
|
||||
sql_l = [["DELETE FROM tv_episodes WHERE showid = ?", [self.indexerid]],
|
||||
["DELETE FROM tv_shows WHERE indexer_id = ?", [self.indexerid]],
|
||||
["DELETE FROM imdb_info WHERE indexer_id = ?", [self.indexerid]]]
|
||||
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
# remove self from show list
|
||||
sickbeard.showList = [x for x in sickbeard.showList if x.indexerid != self.indexerid]
|
||||
@ -1238,10 +1246,6 @@ class TVEpisode(object):
|
||||
if result == False:
|
||||
raise exceptions.EpisodeNotFoundException("Couldn't find episode " + str(season) + "x" + str(episode))
|
||||
|
||||
# don't update if not needed
|
||||
if self.dirty:
|
||||
self.saveToDB()
|
||||
|
||||
def loadFromDB(self, season, episode):
|
||||
|
||||
logger.log(str(self.show.indexerid) + u": Loading episode details from DB for episode " + str(season) + "x" + str(episode), logger.DEBUG)
|
||||
@ -1546,6 +1550,22 @@ class TVEpisode(object):
|
||||
|
||||
raise exceptions.EpisodeDeletedException()
|
||||
|
||||
def get_sql(self, forceSave=False):
|
||||
"""
|
||||
Creates SQL queue for this episode if any of its data has been changed since the last save.
|
||||
|
||||
forceSave: If True it will create SQL queue even if no data has been changed since the
|
||||
last save (aka if the record is not dirty).
|
||||
"""
|
||||
|
||||
if not self.dirty and not forceSave:
|
||||
logger.log(str(self.show.indexeridid) + u": Not creating SQL queue - record is not dirty", logger.DEBUG)
|
||||
return
|
||||
|
||||
# use a custom update/insert method to get the data into the DB
|
||||
return ["INSERT OR REPLACE INTO tv_episodes (episode_id, indexerid, indexer, name, description, subtitles, subtitles_searchcount, subtitles_lastsearch, airdate, hasnfo, hastbn, status, location, file_size, release_name, is_proper, showid, season, episode) VALUES ((SELECT episode_id FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);",
|
||||
[self.show.tvdbid, self.season, self.episode, self.indexerid, self.indexer, self.name, self.description, ",".join([sub for sub in self.subtitles]), self.subtitles_searchcount, self.subtitles_lastsearch, self.airdate.toordinal(), self.hasnfo, self.hastbn, self.status, self.location, self.file_size, self.release_name, self.is_proper, self.show.indexerid, self.season, self.episode]]
|
||||
|
||||
def saveToDB(self, forceSave=False):
|
||||
"""
|
||||
Saves this episode to the database if any of its data has been changed since the last save.
|
||||
|
@ -3080,6 +3080,7 @@ class Home:
|
||||
|
||||
if eps != None:
|
||||
|
||||
sql_l = []
|
||||
for curEp in eps.split('|'):
|
||||
|
||||
logger.log(u"Attempting to set status on episode " + curEp + " to " + status, logger.DEBUG)
|
||||
@ -3116,7 +3117,11 @@ class Home:
|
||||
continue
|
||||
|
||||
epObj.status = int(status)
|
||||
epObj.saveToDB()
|
||||
sql_l.append(epObj.get_sql())
|
||||
|
||||
if len(sql_l) > 0:
|
||||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
if int(status) == WANTED:
|
||||
msg = "Backlog was automatically started for the following seasons of <b>" + showObj.name + "</b>:<br /><ul>"
|
||||
|
Loading…
Reference in New Issue
Block a user