bool CEpg::PersistTags(void) const { bool bReturn = false; CEpgDatabase *database = g_EpgContainer.GetDatabase(); if (!database || !database->Open()) { CLog::Log(LOGERROR, "EPG - %s - could not load the database", __FUNCTION__); return bReturn; } time_t iStart, iEnd; GetFirstDate().GetAsTime(iStart); GetLastDate().GetAsTime(iEnd); database->Delete(*this, iStart, iEnd); if (size() > 0) { for (unsigned int iTagPtr = 0; iTagPtr < size(); iTagPtr++) bReturn = at(iTagPtr)->Persist() && bReturn; } else { /* Return true if we have no tags, so that no error is logged */ bReturn = true; } return bReturn; }
bool CEpg::FixOverlappingEvents(bool bUpdateDb /* = false */) { bool bReturn(false); CEpgInfoTag *previousTag(NULL), *currentTag(NULL); CEpgDatabase *database = g_EpgContainer.GetDatabase(); for (int iPtr = size() - 1; iPtr >= 0; iPtr--) { if (!previousTag) { previousTag = at(iPtr); continue; } currentTag = at(iPtr); if (previousTag->StartAsUTC() <= currentTag->StartAsUTC()) { if (bUpdateDb) { if (!database || !database->Open()) { CLog::Log(LOGERROR, "%s - could not open the database", __FUNCTION__); bReturn = false; continue; } bReturn = database->Delete(*currentTag); } else bReturn = true; if (m_nowActive && *m_nowActive == *currentTag) m_nowActive = NULL; delete currentTag; erase(begin() + iPtr); } else if (previousTag->StartAsUTC() < currentTag->EndAsUTC()) { currentTag->SetEndFromUTC(previousTag->StartAsUTC()); if (bUpdateDb) bReturn = currentTag->Persist(); else bReturn = true; previousTag = at(iPtr); } else { previousTag = at(iPtr); } } return bReturn; }
bool CEpg::Persist(void) { if (CSettings::GetInstance().GetBool(CSettings::SETTING_EPG_IGNOREDBFORCLIENT) || !NeedsSave()) return true; #if EPG_DEBUGGING CLog::Log(LOGDEBUG, "persist table '%s' (#%d) changed=%d deleted=%d", Name().c_str(), m_iEpgID, m_changedTags.size(), m_deletedTags.size()); #endif CEpgDatabase *database = g_EpgContainer.GetDatabase(); if (!database || !database->IsOpen()) { CLog::Log(LOGERROR, "EPG - %s - could not open the database", __FUNCTION__); return false; } { CSingleLock lock(m_critSection); if (m_iEpgID <= 0 || m_bChanged) { int iId = database->Persist(*this, m_iEpgID > 0); if (iId > 0) m_iEpgID = iId; } for (std::map<int, CEpgInfoTagPtr>::iterator it = m_deletedTags.begin(); it != m_deletedTags.end(); ++it) database->Delete(*it->second); for (std::map<int, CEpgInfoTagPtr>::iterator it = m_changedTags.begin(); it != m_changedTags.end(); ++it) it->second->Persist(false); if (m_bUpdateLastScanTime) database->PersistLastEpgScanTime(m_iEpgID, true); m_deletedTags.clear(); m_changedTags.clear(); m_bChanged = false; m_bTagsChanged = false; m_bUpdateLastScanTime = false; } return database->CommitInsertQueries(); }
bool CEpg::PersistTags(void) const { bool bReturn = false; CEpgDatabase *database = g_EpgContainer.GetDatabase(); if (!database || !database->IsOpen()) { CLog::Log(LOGERROR, "EPG - %s - could not load the database", __FUNCTION__); return bReturn; } CDateTime first = GetFirstDate(); CDateTime last = GetLastDate(); time_t iStart(0), iEnd(0); if (first.IsValid()) first.GetAsTime(iStart); if (last.IsValid()) last.GetAsTime(iEnd); database->Delete(*this, iStart, iEnd); if (m_tags.size() > 0) { for (map<CDateTime, CEpgInfoTag *>::const_iterator it = m_tags.begin(); it != m_tags.end(); it++) { if (!it->second->Persist()) { CLog::Log(LOGERROR, "failed to persist epg tag %d", it->second->UniqueBroadcastID()); bReturn = false; } } } else { /* Return true if we have no tags, so that no error is logged */ bReturn = true; } return bReturn; }