Skip to content

Commit

Permalink
Delete IPTV channel data when the channel is removed (#986)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kmdewaal authored Dec 7, 2024
1 parent 00b5817 commit 5eddc0d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions mythtv/programs/mythbackend/backendhousekeeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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 "
Expand All @@ -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)
Expand Down

0 comments on commit 5eddc0d

Please sign in to comment.