From 3c97dc8370525eb7a2e4721e9a4c9f594049d7fa Mon Sep 17 00:00:00 2001
From: Dustyn Gibson <miigotu@gmail.com>
Date: Fri, 10 Jul 2015 21:41:11 -0700
Subject: [PATCH] Daily and Backlog not honoring paused parameter - fixes
 SiCKRAGETV/sickrage-issues#1953

---
 sickbeard/dailysearcher.py |  2 ++
 sickbeard/search.py        |  9 ++-------
 sickbeard/searchBacklog.py | 20 +++++++++-----------
 3 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/sickbeard/dailysearcher.py b/sickbeard/dailysearcher.py
index ebf305ac..bd72ab25 100644
--- a/sickbeard/dailysearcher.py
+++ b/sickbeard/dailysearcher.py
@@ -40,6 +40,8 @@ class DailySearcher():
         self.amActive = False
 
     def run(self, force=False):
+        if self.amActive:
+            return
 
         self.amActive = True
 
diff --git a/sickbeard/search.py b/sickbeard/search.py
index 5c3b8e8f..d56bfab6 100644
--- a/sickbeard/search.py
+++ b/sickbeard/search.py
@@ -321,19 +321,14 @@ def isFirstBestMatch(result):
     return False
 
 def wantedEpisodes(show, fromDate):
+
     anyQualities, bestQualities = common.Quality.splitQuality(show.quality) # @UnusedVariable
     allQualities = list(set(anyQualities + bestQualities))
 
     logger.log(u"Seeing if we need anything from " + show.name, logger.DEBUG)
     myDB = db.DBConnection()
 
-    if show.air_by_date:
-        sqlResults = myDB.select(
-            "SELECT ep.status, ep.season, ep.episode FROM tv_episodes ep, tv_shows show WHERE season != 0 AND ep.showid = show.indexer_id AND show.paused = 0 AND ep.airdate > ? AND ep.showid = ? AND show.air_by_date = 1",
-        [fromDate.toordinal(), show.indexerid])
-    else:
-        sqlResults = myDB.select(
-            "SELECT status, season, episode FROM tv_episodes WHERE showid = ? AND season > 0 and airdate > ?",
+    sqlResults = myDB.select("SELECT status, season, episode FROM tv_episodes WHERE showid = ? AND season > 0 and airdate > ?",
             [show.indexerid, fromDate.toordinal()])
 
     # check through the list of statuses to see if we want any
diff --git a/sickbeard/searchBacklog.py b/sickbeard/searchBacklog.py
index fc50b66b..4f1c870d 100644
--- a/sickbeard/searchBacklog.py
+++ b/sickbeard/searchBacklog.py
@@ -74,6 +74,9 @@ class BacklogSearcher:
             logger.log(u"Backlog is still running, not starting it again", logger.DEBUG)
             return
 
+        self.amActive = True
+        self.amPaused = False
+
         if which_shows:
             show_list = which_shows
         else:
@@ -84,13 +87,10 @@ class BacklogSearcher:
         curDate = datetime.date.today().toordinal()
         fromDate = datetime.date.fromordinal(1)
 
-        if not which_shows and not curDate - self._lastBacklog >= self.cycleTime:
+        if not which_shows and not ((curDate - self._lastBacklog) >= self.cycleTime):
             logger.log(u"Running limited backlog on missed episodes " + str(sickbeard.BACKLOG_DAYS) + " day(s) and older only")
             fromDate = datetime.date.today() - datetime.timedelta(days=sickbeard.BACKLOG_DAYS)
 
-        self.amActive = True
-        self.amPaused = False
-
         # go through non air-by-date shows and see if they need any episodes
         for curShow in show_list:
 
@@ -135,19 +135,17 @@ class BacklogSearcher:
         return self._lastBacklog
 
     def _get_segments(self, show, fromDate):
+        if show.paused:
+            logger.log(u"Skipping backlog for {show_name} because the show is paused".format(show_name=show.name), logger.DEBUG)
+            return {}
+
         anyQualities, bestQualities = common.Quality.splitQuality(show.quality)  # @UnusedVariable
 
         logger.log(u"Seeing if we need anything from {show_name}".format(show_name=show.name), logger.DEBUG)
 
         myDB = db.DBConnection()
-        if show.air_by_date:
-            sqlResults = myDB.select(
-                "SELECT ep.status, ep.season, ep.episode FROM tv_episodes ep, tv_shows show WHERE season != 0 AND ep.showid = show.indexer_id AND show.paused = 0 AND ep.airdate > ? AND ep.showid = ? AND show.air_by_date = 1",
+        sqlResults = myDB.select("SELECT status, season, episode FROM tv_episodes WHERE season > 0 AND airdate > ? AND showid = ?",
                 [fromDate.toordinal(), show.indexerid])
-        else:
-            sqlResults = myDB.select(
-                "SELECT status, season, episode FROM tv_episodes WHERE showid = ? AND season > 0 and airdate > ?",
-                [show.indexerid, fromDate.toordinal()])
 
         # check through the list of statuses to see if we want any
         wanted = {}
-- 
GitLab