bool CPVRChannelGroups::Update(const CPVRChannelGroup &group, bool bUpdateFromClient /* = false */) { if (group.GroupName().empty() && group.GroupID() <= 0) return true; CPVRChannelGroupPtr updateGroup; { CSingleLock lock(m_critSection); // There can be only one internal group! Make sure we never push a new one! if (group.IsInternalGroup()) updateGroup = GetGroupAll(); // try to find the group by id if (!updateGroup && group.GroupID() > 0) updateGroup = GetById(group.GroupID()); // try to find the group by name if we didn't find it yet if (!updateGroup) updateGroup = GetByName(group.GroupName()); if (!updateGroup) { // create a new group if none was found. Copy the properties immediately // so the group doesn't get flagged as "changed" further down. updateGroup = CPVRChannelGroupPtr(new CPVRChannelGroup(group.IsRadio(), group.GroupID(), group.GroupName())); m_groups.push_back(updateGroup); } updateGroup->SetRadio(group.IsRadio()); updateGroup->SetGroupID(group.GroupID()); updateGroup->SetGroupName(group.GroupName()); updateGroup->SetGroupType(group.GroupType()); updateGroup->SetPosition(group.GetPosition()); // don't override properties we only store locally in our PVR database if (!bUpdateFromClient) { updateGroup->SetLastWatched(group.LastWatched()); updateGroup->SetHidden(group.IsHidden()); } } // sort groups SortGroups(); // persist changes if (bUpdateFromClient) return updateGroup->Persist(); return true; }
bool CPVRDatabase::Persist(CPVRChannelGroup &group) { bool bReturn(false); if (group.GroupName().empty()) { CLog::Log(LOGERROR, "%s - empty group name", __FUNCTION__); return bReturn; } std::string strQuery; bReturn = true; { CSingleLock lock(group.m_critSection); /* insert a new entry when this is a new group, or replace the existing one otherwise */ if (group.GroupID() <= 0) strQuery = PrepareSQL("INSERT INTO channelgroups (bIsRadio, iGroupType, sName, iLastWatched, bIsHidden, iPosition) VALUES (%i, %i, '%s', %u, %i, %i)", (group.IsRadio() ? 1 :0), group.GroupType(), group.GroupName().c_str(), group.LastWatched(), group.IsHidden(), group.GetPosition()); else strQuery = PrepareSQL("REPLACE INTO channelgroups (idGroup, bIsRadio, iGroupType, sName, iLastWatched, bIsHidden, iPosition) VALUES (%i, %i, %i, '%s', %u, %i, %i)", group.GroupID(), (group.IsRadio() ? 1 :0), group.GroupType(), group.GroupName().c_str(), group.LastWatched(), group.IsHidden(), group.GetPosition()); bReturn = ExecuteQuery(strQuery); /* set the group id if it was <= 0 */ if (bReturn && group.GroupID() <= 0) group.m_iGroupId = (int) m_pDS->lastinsertid(); } /* only persist the channel data for the internal groups */ if (group.IsInternalGroup()) bReturn &= PersistChannels(group); /* persist the group member entries */ if (bReturn) bReturn = PersistGroupMembers(group); return bReturn; }