Go to the documentation of this file.
13 #include <QRegularExpression>
14 #include <QStringList>
24 #include "libmythbase/mythversion.h"
53 query.
prepare(
"DELETE FROM inuseprograms "
54 "WHERE hostname = :HOSTNAME AND "
55 "( recusage = 'recorder' OR recusage LIKE 'Unknown %' );");
66 query.
prepare(
"DELETE FROM inuseprograms "
67 "WHERE lastupdatetime < :FOURHOURSAGO ;");
68 query.
bindValue(
":FOURHOURSAGO", fourHoursAgo);
80 query.
prepare(
"SELECT DISTINCT chainid FROM tvchain "
81 "WHERE endtime > :FOURHOURSAGO ;");
82 query.
bindValue(
":FOURHOURSAGO", fourHoursAgo);
94 if (keepChains.isEmpty())
95 keepChains =
"'" + query.
value(0).toString() +
"'";
97 keepChains +=
", '" + query.
value(0).toString() +
"'";
100 if (keepChains.isEmpty())
101 msg =
"DELETE FROM tvchain WHERE endtime < now();";
104 msg = QString(
"DELETE FROM tvchain "
105 "WHERE chainid NOT IN ( %1 ) AND endtime < now();")
109 if (!deleteQuery.
exec())
120 std::array<std::array<QString,2>,5> tables {{
121 {
"recordedprogram",
"progstart" },
122 {
"recordedrating",
"progstart" },
123 {
"recordedcredits",
"progstart" },
124 {
"recordedmarkup",
"starttime" },
125 {
"recordedseek",
"starttime" },
133 querystr =
"CREATE TEMPORARY TABLE IF NOT EXISTS temprecordedcleanup ( "
134 "chanid int(10) unsigned NOT NULL default '0', "
135 "starttime datetime NOT NULL default '0000-00-00 00:00:00' "
138 if (!query.
exec(querystr))
141 "(creating temporary table)", query);
145 for (
const auto & [table,column] : tables)
147 query.
prepare(QString(
"TRUNCATE TABLE temprecordedcleanup;"));
151 "(truncating temporary table)", query);
155 query.
prepare(QString(
"INSERT INTO temprecordedcleanup "
156 "( chanid, starttime ) "
157 "SELECT DISTINCT chanid, starttime "
164 "(cleaning recorded tables)", query);
168 query.
prepare(QString(
"SELECT DISTINCT p.chanid, p.starttime "
169 "FROM temprecordedcleanup p "
170 "LEFT JOIN recorded r "
171 "ON p.chanid = r.chanid "
172 "AND p.starttime = r.%1 "
173 "WHERE r.chanid IS NULL;").arg(column));
177 "(cleaning recorded tables)", query);
181 deleteQuery.
prepare(QString(
"DELETE FROM %1 "
182 "WHERE chanid = :CHANID "
183 "AND starttime = :STARTTIME;")
189 if (!deleteQuery.
exec())
192 "(cleaning recorded tables)", deleteQuery);
198 if (!query.
exec(
"DROP TABLE temprecordedcleanup;"))
200 "(deleting temporary table)", query);
211 query.
prepare(QString(
"DELETE channel "
213 "LEFT JOIN recorded r "
214 " ON r.chanid = channel.chanid "
215 "LEFT JOIN oldrecorded o "
216 " ON o.chanid = channel.chanid "
217 "WHERE channel.deleted IS NOT NULL "
218 " AND channel.deleted < "
219 " DATE_SUB(NOW(), INTERVAL 1 DAY) "
220 " AND r.chanid IS NULL "
221 " AND o.chanid IS NULL"));
224 "(channel table)", query);
228 query.
prepare(QString(
"DELETE dtv_multiplex "
229 "FROM dtv_multiplex "
230 "LEFT JOIN channel c "
231 " ON c.mplexid = dtv_multiplex.mplexid "
232 "WHERE c.chanid IS NULL"));
235 "(dtv_multiplex table)", query);
239 query.
prepare(QString(
"DELETE iptv_channel "
241 "LEFT JOIN channel c "
242 " ON c.chanid = iptv_channel.chanid "
243 "WHERE c.chanid IS NULL"));
246 "(iptv_channel table)", query);
258 offset = std::max(newEpiWindow, offset);
260 query.
prepare(
"DELETE FROM oldprogram WHERE airdate < "
261 "DATE_SUB(CURRENT_DATE, INTERVAL 320 DAY);");
265 query.
prepare(
"REPLACE INTO oldprogram (oldtitle,airdate) "
266 "SELECT title,starttime FROM program "
267 "WHERE starttime < NOW() AND manualid = 0 "
272 query.
prepare(
"DELETE FROM program WHERE starttime <= "
273 "DATE_SUB(CURRENT_DATE, INTERVAL :OFFSET DAY);");
278 query.
prepare(
"DELETE FROM programrating WHERE starttime <= "
279 "DATE_SUB(CURRENT_DATE, INTERVAL :OFFSET DAY);");
284 query.
prepare(
"DELETE FROM programgenres WHERE starttime <= "
285 "DATE_SUB(CURRENT_DATE, INTERVAL :OFFSET DAY);");
290 query.
prepare(
"DELETE FROM credits WHERE starttime <= "
291 "DATE_SUB(CURRENT_DATE, INTERVAL :OFFSET DAY);");
296 query.
prepare(
"DELETE FROM record WHERE (type = :SINGLE "
297 "OR type = :OVERRIDE OR type = :DONTRECORD) "
298 "AND enddate < CURDATE();");
306 findq.
prepare(
"SELECT record.recordid FROM record "
307 "LEFT JOIN oldfind ON oldfind.recordid = record.recordid "
308 "WHERE type = :FINDONE AND oldfind.findid IS NOT NULL;");
313 query.
prepare(
"DELETE FROM record WHERE recordid = :RECORDID;");
321 query.
prepare(
"DELETE FROM oldfind WHERE findid < TO_DAYS(NOW()) - 14;");
325 query.
prepare(
"DELETE FROM oldrecorded WHERE "
326 "recstatus <> :RECORDED AND duplicate = 0 AND "
327 "endtime < DATE_SUB(CURRENT_DATE, INTERVAL :CLEAN DAY);");
344 bool devel {
false };
348 if (!parsed || devel)
350 LOG(VB_GENERAL, LOG_INFO, QString(
"Loading themes for devel"));
355 LOG(VB_GENERAL, LOG_INFO, QString(
"Loading themes for %1").arg(major));
356 result |=
LoadVersion(QString::number(major), LOG_ERR);
358 for (
int i =
minor ; i > 0; i--)
360 QString majmin = QString(
"%1.%2").arg(major).arg(i);
361 LOG(VB_GENERAL, LOG_INFO,
362 QString(
"Loading themes for %1").arg(majmin));
372 remoteThemesDir.append(
"/tmp/remotethemes");
374 QDir dir(remoteThemesDir);
375 if (!dir.exists() && !dir.mkpath(remoteThemesDir))
377 LOG(VB_GENERAL, LOG_ERR,
378 QString(
"HouseKeeper: Error creating %1 "
379 "directory for remote themes info cache.")
380 .arg(remoteThemesDir));
384 QString remoteThemesFile = remoteThemesDir;
385 remoteThemesFile.append(
"/themes.zip");
387 m_url = QString(
"%1/%2/themes.zip")
389 "http://themes.mythtv.org/themes/repository"),
398 LOG(VB_GENERAL, (LogLevel_t)download_log_level,
399 QString(
"HouseKeeper: Failed to download %1 "
400 "remote themes info package.").arg(
m_url));
404 if (!
extractZIP(remoteThemesFile, remoteThemesDir))
406 LOG(VB_GENERAL, LOG_ERR,
407 QString(
"HouseKeeper: Error extracting %1 "
408 "remote themes info package.").arg(remoteThemesFile));
409 QFile::remove(remoteThemesFile);
441 args <<
"--updateradiostreams";
444 LOG(VB_GENERAL, LOG_INFO, QString(
"Performing Radio Streams Update: %1 %2")
445 .arg(command,
args.join(
" ")));
457 LOG(VB_GENERAL, LOG_ERR, QString(
"Update Radio Streams command '%1' failed")
462 LOG(VB_GENERAL, LOG_INFO, QString(
"Radio Streams Update Complete"));
476 if (!setting.isEmpty())
478 GetMythDB()->ClearSetting(
"MusicStreamListModified");
509 QString command =
GetAppBinDir() +
"mythmetadatalookup";
511 args <<
"--refresh-all-artwork";
514 LOG(VB_GENERAL, LOG_INFO, QString(
"Performing Artwork Refresh: %1 %2")
515 .arg(command,
args.join(
" ")));
527 LOG(VB_GENERAL, LOG_ERR, QString(
"Artwork command '%1' failed")
531 LOG(VB_GENERAL, LOG_INFO, QString(
"Artwork Refresh Complete"));
616 LOG(VB_GENERAL, LOG_DEBUG,
"MythFillDatabase is disabled. Cannot run.");
628 "1970-01-01T00:00:00"));
629 LOG(VB_GENERAL, LOG_DEBUG,
630 QString(
"MythFillDatabase scheduled to run at %1.")
631 .arg(nextRun.toString()));
633 return nextRun <= now;
640 LOG(VB_GENERAL, LOG_DEBUG,
"Performing daily run check.");
660 if (mfpath ==
"mythfilldatabase")
666 QString cmd = QString(
"%1 %2").arg(mfpath, mfarg);
678 LOG(VB_GENERAL, LOG_ERR, QString(
"MythFillDatabase command '%1' failed")
bool isActive(void) const
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
QSqlQuery wrapper that fetches a DB connection from the connection pool.
bool DoRun(void) override
bool extractZIP(QString zipFile, const QString &outDir)
bool DoRun(void) override
void Term(bool force=false)
void SetHourWindowFromDB(void)
uint GetStatus(void) const
bool DoRun(void) override
void Terminate(void) override
bool DoCheckRun(const QDateTime &now) override
static void CleanupInUsePrograms(void)
@ kHKRunOnStartup
task is queued when HouseKeeper is started
MythSystemLegacy * m_msMFD
bool DoCheckRun(const QDateTime &now) override
QVariant value(int i) const
~RadioStreamUpdateTask(void) override
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
void Terminate(void) override
bool DoCheckRun(const QDateTime &now) override
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
bool DoRun(void) override
static void CleanupOldRecordings(void)
MythSystemLegacy * m_msMU
bool ParseMythSourceVersion(bool &devel, uint &major, uint &minor, const char *version)
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
bool InWindow(const QDateTime &now) override
RadioStreamUpdateTask(void)
MythFillDatabaseTask(void)
static void CleanupRecordedTables(void)
~ArtworkTask(void) override
@ GENERIC_EXIT_OK
Exited with no error.
~MythFillDatabaseTask(void) override
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
static void DBError(const QString &where, const MSqlQuery &query)
virtual void SetHourWindow(std::chrono::hours min, std::chrono::hours max)
void Terminate(void) override
static void CleanupOldJobsInQueue()
std::enable_if_t< std::chrono::__is_duration< T >::value, T > GetDurSetting(const QString &key, T defaultval=T::zero())
bool LoadVersion(const QString &version, int download_log_level)
static void CleanupOrphanedLiveTV(void)
static constexpr int64_t kFourHours
uint Wait(std::chrono::seconds timeout=0s)
bool download(const QString &url, const QString &dest, bool reload=false)
Downloads a URL to a file in blocking mode.
void cancelDownload(const QString &url, bool block=true)
Cancel a queued or current download.
@ kMSPropagateLogs
add arguments for MythTV log propagation
static void CleanupProgramListings(void)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
int GetNumSetting(const QString &key, int defaultval=0)
bool DoRun(void) override
@ kMSRunShell
run process through shell
@ GENERIC_EXIT_RUNNING
Process is running.
@ kMSAutoCleanup
automatically delete if backgrounded
QDateTime fromString(const QString &dtstr)
Converts kFilename && kISODate formats to QDateTime.
bool GetBoolSetting(const QString &key, bool defaultval=false)
void Terminate(void) override
MythSystemLegacy * m_msMML
static bool UseSuggestedTime(void)
@ kHKGlobal
task should only run once per cluster e.g.
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
static void CleanupChannelTables(void)
QString GetAppBinDir(void)
QString GetHostName(void)
void Run(std::chrono::seconds timeout=0s)
Runs a command inside the /bin/sh shell. Returns immediately.
bool DoCheckRun(const QDateTime &now) override
bool DoRun(void) override
Modified PeriodicHouseKeeperTask for tasks to be run once daily.
static void RecoverOldJobsInQueue()
QString GetSetting(const QString &key, const QString &defaultval="")
MythDownloadManager * GetMythDownloadManager(void)
Gets the pointer to the MythDownloadManager singleton.
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
bool DoCheckRun(const QDateTime &now) override