Exemple #1
0
bool CEpg::UpdateEntries(const CEpg &epg, bool bStoreInDb /* = true */)
{
  bool bReturn(false);
  CEpgDatabase *database = g_EpgContainer.GetDatabase();

  CSingleLock lock(m_critSection);

  if (epg.size() > 0)
  {
    if (bStoreInDb)
    {
      if (!database || !database->Open())
      {
        CLog::Log(LOGERROR, "%s - could not open the database", __FUNCTION__);
        return bReturn;
      }
      database->BeginTransaction();
    }
    CLog::Log(LOGDEBUG, "%s - %u entries in memory before merging", __FUNCTION__, size());
    /* copy over tags */
    for (unsigned int iTagPtr = 0; iTagPtr < epg.size(); iTagPtr++)
    {
      UpdateEntry(*epg.at(iTagPtr), bStoreInDb, false);
    }

    Sort();
    CLog::Log(LOGDEBUG, "%s - %u entries in memory after merging and before fixing", __FUNCTION__, size());
    FixOverlappingEvents(bStoreInDb);
    m_nowActive = NULL;
    CLog::Log(LOGDEBUG, "%s - %u entries in memory after fixing", __FUNCTION__, size());
    /* update the last scan time of this table */
    m_lastScanTime = CDateTime::GetCurrentDateTime().GetAsUTCDateTime();

    /* update the first and last date */
    UpdateFirstAndLastDates();

    //m_bTagsChanged = true;
    /* persist changes */
    if (bStoreInDb)
    {
      bReturn = database->CommitTransaction();
      database->Close();
      if (bReturn)
        Persist(true);
    }
    else
      bReturn = true;
  }
  else
  {
    if (bStoreInDb)
      bReturn = Persist(true);
    else
       bReturn = true;
  }

  return bReturn;
}
Exemple #2
0
bool CEpg::UpdateEntries(const CEpg &epg, bool bStoreInDb /* = true */)
{
  bool bReturn(false);
  CEpgDatabase *database = g_EpgContainer.GetDatabase();

  if (epg.m_tags.size() > 0)
  {
    if (bStoreInDb)
    {
      if (!database || !database->IsOpen())
      {
        CLog::Log(LOGERROR, "%s - could not open the database", __FUNCTION__);
        return bReturn;
      }
      database->BeginTransaction();
    }

    {
      CSingleLock lock(m_critSection);
      CLog::Log(LOGDEBUG, "%s - %zu entries in memory before merging", __FUNCTION__, m_tags.size());
      /* copy over tags */
      for (map<CDateTime, CEpgInfoTagPtr>::const_iterator it = epg.m_tags.begin(); it != epg.m_tags.end(); it++)
        UpdateEntry(*it->second, bStoreInDb, false);

      CLog::Log(LOGDEBUG, "%s - %zu entries in memory after merging and before fixing", __FUNCTION__, m_tags.size());
      FixOverlappingEvents(bStoreInDb);
      CLog::Log(LOGDEBUG, "%s - %zu entries in memory after fixing", __FUNCTION__, m_tags.size());
      /* update the last scan time of this table */
      m_lastScanTime = CDateTime::GetCurrentDateTime().GetAsUTCDateTime();

      SetChanged();
    }
    /* persist changes */
    if (bStoreInDb)
    {
      bReturn = database->CommitTransaction();
      if (bReturn)
        Persist(true);
    }
    else
      bReturn = true;
  }
  else
  {
    if (bStoreInDb)
      bReturn = Persist(true);
    else
      bReturn = true;
  }

  NotifyObservers(ObservableMessageEpg);

  return bReturn;
}
Exemple #3
0
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;
}