bool CEpgInfoTag::Persist(bool bSingleUpdate /* = true */, bool bLastUpdate /* = false */) { bool bReturn = false; if (!m_bChanged) return true; CEpgDatabase *database = g_EpgContainer.GetDatabase(); if (!database || !database->Open()) { CLog::Log(LOGERROR, "%s - could not open the database", __FUNCTION__); return bReturn; } int iId = database->Persist(*this, bSingleUpdate, bLastUpdate); if (iId >= 0) { bReturn = true; if (iId > 0) { m_iBroadcastId = iId; m_bChanged = false; } } database->Close(); return bReturn; }
bool CEpgInfoTag::Persist(bool bSingleUpdate /* = true */) { bool bReturn = false; #if EPG_DEBUGGING CLog::Log(LOGDEBUG, "Epg - %s - Infotag '%s' %s, persisting...", __FUNCTION__, m_strTitle.c_str(), m_iBroadcastId > 0 ? "has changes" : "is new"); #endif CEpgDatabase *database = g_EpgContainer.GetDatabase(); if (!database || (bSingleUpdate && !database->IsOpen())) { CLog::Log(LOGERROR, "%s - could not open the database", __FUNCTION__); return bReturn; } int iId = database->Persist(*this, bSingleUpdate); if (iId >= 0) { bReturn = true; if (iId > 0) m_iBroadcastId = iId; } return bReturn; }
bool CEpg::Persist(bool bPersistTags /* = false */, bool bQueueWrite /* = false */) { bool bReturn = false; CEpgDatabase *database = g_EpgContainer.GetDatabase(); if (!database || !database->Open()) { CLog::Log(LOGERROR, "%s - could not open the database", __FUNCTION__); return bReturn; } CSingleLock lock(m_critSection); int iId = database->Persist(*this, bQueueWrite); if (iId >= 0) { if (iId > 0) m_iEpgID = iId; if (bPersistTags) bReturn = PersistTags(bQueueWrite); else bReturn = true; } database->Close(); return bReturn; }
bool CEpg::Update(time_t start, time_t end, int iUpdateTime, bool bStoreInDb /* = true */) { bool bGrabSuccess = true; bool bUpdate = false; CEpgDatabase *database = g_EpgContainer.GetDatabase(); if (bStoreInDb && (!database || !database->Open())) { CLog::Log(LOGERROR, "Epg - %s - cannot open the database", __FUNCTION__); return false; } CSingleLock lock(m_critSection); /* get the last update time from the database */ if (!m_lastScanTime.IsValid() && bStoreInDb) database->GetLastEpgScanTime(m_iEpgID, &m_lastScanTime); /* check if we have to update */ time_t iNow = 0; time_t iLastUpdate = 0; CDateTime::GetCurrentDateTime().GetAsTime(iNow); m_lastScanTime.GetAsTime(iLastUpdate); bUpdate = (iNow > iLastUpdate + iUpdateTime); if (bUpdate) { m_bInhibitSorting = true; bGrabSuccess = UpdateFromScraper(start, end); m_bInhibitSorting = false; /* store the loaded EPG entries in the database */ if (bGrabSuccess && size() > 0) { Sort(); FixOverlappingEvents(false); if (bStoreInDb) { database->PersistLastEpgScanTime(m_iEpgID, true); database->Persist(*this, true); PersistTags(true); database->CommitInsertQueries(); } m_lastScanTime = CDateTime::GetCurrentDateTime(); } else { m_lastScanTime = CDateTime::GetCurrentDateTime() - CDateTimeSpan(0, 0, 0, iUpdateTime + 300); /* try again in 5 minutes */ } } if (bStoreInDb) database->Close(); return bGrabSuccess; }
bool CEpg::Persist(bool bUpdateLastScanTime /* = false */) { if (g_guiSettings.GetBool("epg.ignoredbforclient")) return true; CEpgDatabase *database = g_EpgContainer.GetDatabase(); if (!database || !database->Open()) { CLog::Log(LOGERROR, "%s - could not open the database", __FUNCTION__); return false; } CEpg epgCopy; { CSingleLock lock(m_critSection); epgCopy = *this; m_bChanged = false; m_bTagsChanged = false; } database->BeginTransaction(); if (epgCopy.m_iEpgID <= 0 || epgCopy.m_bChanged) { int iId = database->Persist(epgCopy); if (iId > 0) { epgCopy.m_iEpgID = iId; epgCopy.m_bChanged = false; if (m_iEpgID != epgCopy.m_iEpgID) { CSingleLock lock(m_critSection); m_iEpgID = epgCopy.m_iEpgID; } } } bool bReturn(true); if (bUpdateLastScanTime) bReturn = database->PersistLastEpgScanTime(epgCopy.m_iEpgID); database->CommitTransaction(); database->Close(); 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(); }