Skip to content
This repository
Browse code

[epg] fixed - delete tables that are no longer valid. fixed Delete() …

…method from the db, so it deletes the table instead of entries
  • Loading branch information...
commit b6e17f5572437f560bfbed66f6f1f13eefeaa355 1 parent e979ca9
Lars Op den Kamp authored
8  xbmc/epg/Epg.cpp
@@ -901,3 +901,11 @@ bool CEpg::NeedsSave(void) const
901 901
   CSingleLock lock(m_critSection);
902 902
   return !m_changedTags.empty() || !m_deletedTags.empty() || m_bChanged;
903 903
 }
  904
+
  905
+bool CEpg::IsValid(void) const
  906
+{
  907
+  CSingleLock lock(m_critSection);
  908
+  if (ScraperName() == "client")
  909
+    return Channel().get() != NULL;
  910
+  return true;
  911
+}
5  xbmc/epg/Epg.h
@@ -299,6 +299,11 @@ namespace EPG
299 299
     size_t Size(void) const;
300 300
 
301 301
     bool NeedsSave(void) const;
  302
+
  303
+    /*!
  304
+     * @return True when this EPG is valid and can be updated, false otherwise
  305
+     */
  306
+    bool IsValid(void) const;
302 307
   protected:
303 308
     CEpg(void);
304 309
 
10  xbmc/epg/EpgContainer.cpp
@@ -382,6 +382,7 @@ bool CEpgContainer::DeleteEpg(const CEpg &epg, bool bDeleteFromDatabase /* = fal
382 382
   if (it == m_epgs.end())
383 383
     return false;
384 384
 
  385
+  CLog::Log(LOGDEBUG, "deleting EPG table %s (%d)", epg.Name().c_str(), epg.EpgID());
385 386
   if (bDeleteFromDatabase && !m_bIgnoreDbForClient && m_database.IsOpen())
386 387
     m_database.Delete(*it->second);
387 388
 
@@ -490,6 +491,8 @@ bool CEpgContainer::UpdateEPG(bool bOnlyPending /* = false */)
490 491
     return false;
491 492
   }
492 493
 
  494
+  vector<CEpg*> invalidTables;
  495
+
493 496
   /* load or update all EPG tables */
494 497
   CEpg *epg;
495 498
   unsigned int iCounter(0);
@@ -509,9 +512,14 @@ bool CEpgContainer::UpdateEPG(bool bOnlyPending /* = false */)
509 512
       UpdateProgressDialog(++iCounter, m_epgs.size(), epg->Name());
510 513
 
511 514
     if ((!bOnlyPending || epg->UpdatePending()) && epg->Update(start, end, m_iUpdateTime, bOnlyPending))
512  
-      ++iUpdatedTables;
  515
+      iUpdatedTables++;
  516
+    else if (!epg->IsValid())
  517
+      invalidTables.push_back(epg);
513 518
   }
514 519
 
  520
+  for (vector<CEpg*>::iterator it = invalidTables.begin(); it != invalidTables.end(); it++)
  521
+    DeleteEpg(**it, true);
  522
+
515 523
   if (bInterrupted)
516 524
   {
517 525
     /* the update has been interrupted. try again later */
13  xbmc/epg/EpgDatabase.cpp
@@ -160,26 +160,19 @@ bool CEpgDatabase::DeleteEpg(void)
160 160
   return bReturn;
161 161
 }
162 162
 
163  
-bool CEpgDatabase::Delete(const CEpg &table, const time_t start /* = 0 */, const time_t end /* = 0 */)
  163
+bool CEpgDatabase::Delete(const CEpg &table)
164 164
 {
165 165
   /* invalid channel */
166 166
   if (table.EpgID() <= 0)
167 167
   {
168  
-    CLog::Log(LOGERROR, "EpgDB - %s - invalid channel id: %d",
169  
-        __FUNCTION__, table.EpgID());
  168
+    CLog::Log(LOGERROR, "EpgDB - %s - invalid channel id: %d", __FUNCTION__, table.EpgID());
170 169
     return false;
171 170
   }
172 171
 
173 172
   CStdString strWhereClause;
174 173
   strWhereClause = FormatSQL("idEpg = %u", table.EpgID());
175 174
 
176  
-  if (start != 0)
177  
-    strWhereClause.append(FormatSQL(" AND iStartTime >= %u", start).c_str());
178  
-
179  
-  if (end != 0)
180  
-    strWhereClause.append(FormatSQL(" AND iEndTime <= %u", end).c_str());
181  
-
182  
-  return DeleteValues("epgtags", strWhereClause);
  175
+  return DeleteValues("epg", strWhereClause);
183 176
 }
184 177
 
185 178
 bool CEpgDatabase::DeleteOldEpgEntries(void)
10  xbmc/epg/EpgDatabase.h
@@ -71,13 +71,11 @@ namespace EPG
71 71
     virtual bool DeleteEpg(void);
72 72
 
73 73
     /*!
74  
-     * @brief Erase all EPG entries for a table.
75  
-     * @param table The table to remove the EPG entries for.
76  
-     * @param start Remove entries after this time if set.
77  
-     * @param end Remove entries before this time if set.
78  
-     * @return True if the entries were removed successfully, false otherwise.
  74
+     * @brief Delete an EPG table.
  75
+     * @param table The table to remove.
  76
+     * @return True if the table was removed successfully, false otherwise.
79 77
      */
80  
-    virtual bool Delete(const CEpg &table, const time_t start = 0, const time_t end = 0);
  78
+    virtual bool Delete(const CEpg &table);
81 79
 
82 80
     /*!
83 81
      * @brief Erase all EPG entries older than 1 day.

0 notes on commit b6e17f5

Please sign in to comment.
Something went wrong with that request. Please try again.