Commit 230e4a11 authored by echel0n's avatar echel0n

Fixed issue with episodes being prematurely saved to database

parent 973d96d8
......@@ -45,6 +45,7 @@ def set_episode_to_wanted(show, s, e):
sickrage.app.log.info("Setting episode %s S%02dE%02d to wanted" % (show.name, s, e))
epObj.status = WANTED
epObj.save()
sickrage.app.search_queue.put(BacklogSearchTask(show.indexer_id, epObj.season, epObj.episode))
......
......@@ -63,6 +63,7 @@ class TVEpisode(object):
})
self.populate_episode(season, episode)
self.checkForMetaFiles()
@property
def showid(self):
......@@ -377,8 +378,6 @@ class TVEpisode(object):
self.hasnfo = cur_nfo
self.hastbn = cur_tbn
self.save()
# if either setting has changed return true, if not return false
return oldhasnfo != self.hasnfo or oldhastbn != self.hastbn
......@@ -506,8 +505,7 @@ class TVEpisode(object):
if not os.path.isdir(self.show.location) and not sickrage.app.config.create_missing_show_dirs and not sickrage.app.config.add_shows_wo_dir:
sickrage.app.log.info("The show dir {} is missing, not bothering to change the episode statuses since it'd "
"probably be invalid".format(self.show.location))
self.save()
return True
return False
if self.location:
sickrage.app.log.debug("%s: Setting status for S%02dE%02d based on status %s and location %s" %
......@@ -538,8 +536,6 @@ class TVEpisode(object):
sickrage.app.log.debug("6 Status changes from " + str(self.status) + " to " + str(UNKNOWN))
self.status = UNKNOWN
self.save()
return True
def load_from_nfo(self, location):
......@@ -619,8 +615,6 @@ class TVEpisode(object):
if os.path.isfile(replace_extension(nfoFile, "tbn")):
self.hastbn = True
self.save()
return self.hasnfo
def create_meta_files(self, force=False):
......@@ -631,7 +625,8 @@ class TVEpisode(object):
self.create_nfo(force)
self.create_thumbnail(force)
self.checkForMetaFiles()
if self.checkForMetaFiles():
self.save()
def create_nfo(self, force=False):
result = False
......@@ -806,6 +801,7 @@ class TVEpisode(object):
# in case something changed with the metadata just do a quick check
for curEp in [self] + self.related_episodes:
curEp.checkForMetaFiles()
curEp.save()
def airdate_modify_stamp(self):
"""
......@@ -1042,13 +1038,9 @@ class TVEpisode(object):
if not hasattr(self, '_release_group'):
sickrage.app.log.debug("Episode has no release group, replacing it with '" + replace_map['%RG'] + "'")
self.release_group = replace_map['%RG'] # if release_group is not in the db, put it there
if getattr(self, 'save', None):
self.save()
elif not self.release_group:
sickrage.app.log.debug("Episode has no release group, replacing it with '" + replace_map['%RG'] + "'")
self.release_group = replace_map['%RG'] # if release_group is not in the db, put it there
if getattr(self, 'save', None):
self.save()
# if there's no release name then replace it with a reasonable facsimile
if not replace_map['%RN']:
......
......@@ -665,6 +665,7 @@ class TVShow(object):
else:
try:
episode_obj.load_from_indexer(season, episode)
episode_obj.save()
except EpisodeDeletedException:
sickrage.app.log.info("The episode was deleted, skipping the rest of the load")
continue
......@@ -678,7 +679,7 @@ class TVShow(object):
return scanned_eps
def get_episode(self, season=None, episode=None, absolute_number=None, no_create=False):
def get_episode(self, season=None, episode=None, absolute_number=None, location=None, no_create=False):
try:
if season is None and episode is None and absolute_number is not None:
with sickrage.app.main_db.session() as session:
......@@ -693,7 +694,7 @@ class TVShow(object):
else:
if no_create:
return None
tv_episode = TVEpisode(showid=self.indexer_id, indexer=self.indexer, season=season, episode=episode)
tv_episode = TVEpisode(showid=self.indexer_id, indexer=self.indexer, season=season, episode=episode, location=location)
self._episodes[tv_episode.indexer_id] = tv_episode
return tv_episode
except orm.exc.MultipleResultsFound:
......@@ -954,7 +955,7 @@ class TVShow(object):
check_quality_again = False
try:
episode_obj = self.get_episode(season, episode)
episode_obj = self.get_episode(season, episode, location=filename)
except EpisodeNotFoundException:
sickrage.app.log.warning("{}: Unable to figure out what this file is, skipping {}".format(self.indexer_id, filename))
continue
......
......@@ -321,6 +321,7 @@ class FailedHistory(object):
else:
sickrage.app.log.debug("WARNING: Episode not found in history. Setting it back to WANTED")
episode_object.status = WANTED
episode_object.save()
except EpisodeNotFoundException as e:
sickrage.app.log.warning("Unable to create episode, please set its status manually: {}".format(e))
......@@ -339,11 +340,11 @@ class FailedHistory(object):
if not show_object:
return log_str
episode_object = show_object.get_episode(season, episode)
try:
episode_object = show_object.get_episode(season, episode)
quality = Quality.split_composite_status(episode_object.status)[1]
episode_object.status = Quality.composite_status(FAILED, quality)
episode_object.save()
except EpisodeNotFoundException as e:
sickrage.app.log.warning("Unable to get episode, please set its status manually: {}".format(e))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment