From d471d5119ffd36bcb0449ea33506abd79dd434b6 Mon Sep 17 00:00:00 2001 From: Klaas de Waal Date: Wed, 4 Dec 2024 21:36:52 +0100 Subject: [PATCH] Delete IPTV channel data when the channel is removed Delete all IPTV channel data extensions records from the database when the channel it refers to does not exist anymore. As part of the periodic housekeeping tasks all channels that have been marked for deletion and for which there are no more recordings preseent are removed from the database. For IPTV channels the IPTV URL is stored in table iptv_channel. This table can be seen as an extension of table channel and it is usually accessed with the chanid from the channel table. This means that when a channel is really deleted (removed from the database) also the corresponding record in iptv_channel has to be deleted. + // Delete all IPTV channel data extension records from the database + // when the channel it refers to does not exist anymore. --- .../programs/mythbackend/backendhousekeeper.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mythtv/programs/mythbackend/backendhousekeeper.cpp b/mythtv/programs/mythbackend/backendhousekeeper.cpp index f74f71e707e..d0bc1bcc296 100644 --- a/mythtv/programs/mythbackend/backendhousekeeper.cpp +++ b/mythtv/programs/mythbackend/backendhousekeeper.cpp @@ -204,6 +204,9 @@ void CleanupTask::CleanupChannelTables(void) MSqlQuery query(MSqlQuery::InitCon()); MSqlQuery deleteQuery(MSqlQuery::InitCon()); + // Delete all channels from the database that have already + // been deleted for at least one day and that are not referenced + // anymore by a recording. query.prepare(QString("DELETE channel " "FROM channel " "LEFT JOIN recorded r " @@ -219,6 +222,8 @@ void CleanupTask::CleanupChannelTables(void) MythDB::DBError("CleanupTask::CleanupChannelTables " "(channel table)", query); + // Delete all multiplexes from the database that are not + // referenced anymore by a channel. query.prepare(QString("DELETE dtv_multiplex " "FROM dtv_multiplex " "LEFT JOIN channel c " @@ -227,6 +232,17 @@ void CleanupTask::CleanupChannelTables(void) if (!query.exec()) MythDB::DBError("CleanupTask::CleanupChannelTables " "(dtv_multiplex table)", query); + + // Delete all IPTV channel data extension records from the database + // when the channel it refers to does not exist anymore. + query.prepare(QString("DELETE iptv_channel " + "FROM iptv_channel " + "LEFT JOIN channel c " + " ON c.chanid = iptv_channel.chanid " + "WHERE c.chanid IS NULL")); + if (!query.exec()) + MythDB::DBError("CleanupTask::CleanupChannelTables " + "(iptv_channel table)", query); } void CleanupTask::CleanupProgramListings(void)