Skip to content

Commit

Permalink
[epg] fixed - delete tables that are no longer valid. fixed Delete() …
Browse files Browse the repository at this point in the history
…method from the db, so it deletes the table instead of entries
  • Loading branch information
opdenkamp committed Dec 7, 2012
1 parent e979ca9 commit b6e17f5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
8 changes: 8 additions & 0 deletions xbmc/epg/Epg.cpp
Expand Up @@ -901,3 +901,11 @@ bool CEpg::NeedsSave(void) const
CSingleLock lock(m_critSection);
return !m_changedTags.empty() || !m_deletedTags.empty() || m_bChanged;
}

bool CEpg::IsValid(void) const
{
CSingleLock lock(m_critSection);
if (ScraperName() == "client")
return Channel().get() != NULL;
return true;
}
5 changes: 5 additions & 0 deletions xbmc/epg/Epg.h
Expand Up @@ -299,6 +299,11 @@ namespace EPG
size_t Size(void) const;

bool NeedsSave(void) const;

/*!
* @return True when this EPG is valid and can be updated, false otherwise
*/
bool IsValid(void) const;
protected:
CEpg(void);

Expand Down
10 changes: 9 additions & 1 deletion xbmc/epg/EpgContainer.cpp
Expand Up @@ -382,6 +382,7 @@ bool CEpgContainer::DeleteEpg(const CEpg &epg, bool bDeleteFromDatabase /* = fal
if (it == m_epgs.end())
return false;

CLog::Log(LOGDEBUG, "deleting EPG table %s (%d)", epg.Name().c_str(), epg.EpgID());
if (bDeleteFromDatabase && !m_bIgnoreDbForClient && m_database.IsOpen())
m_database.Delete(*it->second);

Expand Down Expand Up @@ -490,6 +491,8 @@ bool CEpgContainer::UpdateEPG(bool bOnlyPending /* = false */)
return false;
}

vector<CEpg*> invalidTables;

/* load or update all EPG tables */
CEpg *epg;
unsigned int iCounter(0);
Expand All @@ -509,9 +512,14 @@ bool CEpgContainer::UpdateEPG(bool bOnlyPending /* = false */)
UpdateProgressDialog(++iCounter, m_epgs.size(), epg->Name());

if ((!bOnlyPending || epg->UpdatePending()) && epg->Update(start, end, m_iUpdateTime, bOnlyPending))
++iUpdatedTables;
iUpdatedTables++;
else if (!epg->IsValid())
invalidTables.push_back(epg);
}

for (vector<CEpg*>::iterator it = invalidTables.begin(); it != invalidTables.end(); it++)
DeleteEpg(**it, true);

if (bInterrupted)
{
/* the update has been interrupted. try again later */
Expand Down
13 changes: 3 additions & 10 deletions xbmc/epg/EpgDatabase.cpp
Expand Up @@ -160,26 +160,19 @@ bool CEpgDatabase::DeleteEpg(void)
return bReturn;
}

bool CEpgDatabase::Delete(const CEpg &table, const time_t start /* = 0 */, const time_t end /* = 0 */)
bool CEpgDatabase::Delete(const CEpg &table)
{
/* invalid channel */
if (table.EpgID() <= 0)
{
CLog::Log(LOGERROR, "EpgDB - %s - invalid channel id: %d",
__FUNCTION__, table.EpgID());
CLog::Log(LOGERROR, "EpgDB - %s - invalid channel id: %d", __FUNCTION__, table.EpgID());
return false;
}

CStdString strWhereClause;
strWhereClause = FormatSQL("idEpg = %u", table.EpgID());

if (start != 0)
strWhereClause.append(FormatSQL(" AND iStartTime >= %u", start).c_str());

if (end != 0)
strWhereClause.append(FormatSQL(" AND iEndTime <= %u", end).c_str());

return DeleteValues("epgtags", strWhereClause);
return DeleteValues("epg", strWhereClause);
}

bool CEpgDatabase::DeleteOldEpgEntries(void)
Expand Down
10 changes: 4 additions & 6 deletions xbmc/epg/EpgDatabase.h
Expand Up @@ -71,13 +71,11 @@ namespace EPG
virtual bool DeleteEpg(void);

/*!
* @brief Erase all EPG entries for a table.
* @param table The table to remove the EPG entries for.
* @param start Remove entries after this time if set.
* @param end Remove entries before this time if set.
* @return True if the entries were removed successfully, false otherwise.
* @brief Delete an EPG table.
* @param table The table to remove.
* @return True if the table was removed successfully, false otherwise.
*/
virtual bool Delete(const CEpg &table, const time_t start = 0, const time_t end = 0);
virtual bool Delete(const CEpg &table);

/*!
* @brief Erase all EPG entries older than 1 day.
Expand Down

0 comments on commit b6e17f5

Please sign in to comment.