Go to the documentation of this file.
28 QString upgradeSchemaVal)
29 : m_schemaSetting(std::move(DBSchemaSetting)),
30 m_schemaName(std::move(appName)),
31 m_newSchemaVer(std::move(upgradeSchemaVal))
41 #if defined(ENABLE_SCHEMA_DEVELOPER_MODE) && ENABLE_SCHEMA_DEVELOPER_MODE
55 const QString &appName,
56 const QString &upgradeSchemaVal)
90 LOG(VB_GENERAL, LOG_INFO,
91 "The database seems to be empty - not attempting a backup");
107 LOG(VB_GENERAL, LOG_INFO,
"No current database version?");
111 LOG(VB_GENERAL, LOG_INFO,
"Database appears to be empty/new!");
117 LOG(VB_GENERAL, LOG_INFO,
118 QString(
"Current %1 Schema Version (%2): %3")
122 #if defined(TESTING) && TESTING
138 int old_version =
m_DBver.toInt(&old_ok);
139 if (new_ok && old_ok)
148 bool upgradable,
bool expert)
169 dlg->AddButton(tr(
"Exit"));
172 dlg->AddButton(tr(
"Upgrade"));
176 dlg->AddButton(
"Use current schema");
183 &block, [&](
const QString& ,
int result) { block.exit(result); });
186 btnIndex = block.exec();
225 const bool upgradeAllowed,
226 const bool upgradeIfNoUI,
227 const int minDBMSmajor,
228 const int minDBMSminor,
229 const int minDBMSpoint)
231 bool connections =
false;
233 bool upgradable =
false;
234 bool validDBMS =
false;
243 #if defined(minDBMS_is_only_for_schema_upgrades) && minDBMS_is_only_for_schema_upgrades
260 validDBMS = (minDBMSmajor == 0)
263 minDBMSminor, minDBMSpoint) >= 0;
270 warnOtherCl = tr(
"There are also other clients using this"
271 " database. They should be shut down first.");
274 warnOldDBMS = tr(
"Error: This version of Myth%1"
275 " requires MySQL %2.%3.%4 or later."
276 " You seem to be running MySQL version %5.")
277 .arg(name).arg(minDBMSmajor).arg(minDBMSminor)
294 if (!gui && (!isatty(fileno(stdin)) || !isatty(fileno(
stdout))))
296 LOG(VB_GENERAL, LOG_INFO,
297 "Console is non-interactive, can't prompt user...");
301 LOG(VB_GENERAL, LOG_CRIT,
"Using existing schema.");
307 LOG(VB_GENERAL, LOG_CRIT, warnOldDBMS);
313 LOG(VB_GENERAL, LOG_CRIT,
314 QString(
"Error: MythTV database has newer %1 schema (%2) "
315 "than expected (%3).")
320 if (upgradeIfNoUI && validDBMS)
322 LOG(VB_GENERAL, LOG_CRIT,
"Upgrading.");
341 message = tr(
"Error: MythTV cannot upgrade the schema of this"
342 " datatase because other clients are using it.\n\n"
343 "Please shut them down before upgrading.");
348 message = tr(
"Warning: MythTV wants to upgrade your database,")
349 +
"\n" + tr(
"for the %1 schema, from %2 to %3.");
353 message +=
"\n\nYou can try using the old schema,"
354 " but that may cause problems.";
360 message = warnOldDBMS;
365 message = tr(
"This version of MythTV requires an updated database. ")
367 +
"\n\n" + tr(
"Please run mythtv-setup or mythbackend "
368 "to update your database.");
376 message =
"Warning: MythTV database has newer"
377 " %1 schema (%2) than expected (%3).";
381 message = tr(
"Error: MythTV database has newer"
382 " %1 schema (%2) than expected (%3).");
388 message +=
"\n" + tr(
"MythTV was unable to backup your database.");
390 if (message.contains(
"%1"))
395 message +=
"\n\n" + tr(
"Database Host: %1\nDatabase Name: %2")
427 message = tr(
"If your system becomes unstable, a database"
428 " backup file called\n%1\nis located in %2")
429 .arg(fileName, dirName);
433 message = tr(
"This cannot be un-done, so having a"
434 " database backup would be a good idea.");
437 message +=
"\n\n" + warnOtherCl;
445 cout << endl << message.toLocal8Bit().constData() << endl << endl;
452 cout <<
"WARNING: MythTV was unable to backup your database."
458 cout <<
"If your system becomes unstable, "
459 "a database backup is located in "
465 resp =
getResponse(
"Would you like to use the existing schema?",
"yes");
466 if (resp.isEmpty() || resp.startsWith(
"y", Qt::CaseInsensitive))
470 resp =
getResponse(
"\nShall I upgrade this database?",
"yes");
471 if (!resp.isEmpty() && !resp.startsWith(
"y", Qt::CaseInsensitive))
475 cout << endl << warnOtherCl.toLocal8Bit().constData() << endl;
480 resp =
getResponse(
"\nA database backup might be a good idea"
481 "\nAre you sure you want to upgrade?",
"no");
482 if (resp.isEmpty() || resp.startsWith(
"n", Qt::CaseInsensitive))
bool WaitFor(MythConfirmationDialog *dialog)
Blocks until confirmation dialog exits.
MythScreenStack * GetMainStack()
MythUIBusyDialog * ShowBusyPopup(const QString &message)
QString m_dbHostName
database server
static SchemaUpgradeWizard * Get(const QString &DBSchemaSetting, const QString &appName, const QString &upgradeSchemaVal)
Instead of creating a new wizard, use the existing one for its DB backup file & results and expert se...
void BusyPopup(const QString &message)
Delete any current "busy" popup, create new one.
bool IsScreenSetup() const
Structure containing the basic Database parameters.
~SchemaUpgradeWizard() override
int Compare(void)
How many schema versions old is the DB?
static SchemaUpgradeWizard * c_wizard
enum MythSchemaUpgrade PromptForUpgrade(const char *name, bool upgradeAllowed, bool upgradeIfNoUI, int minDBMSmajor=0, int minDBMSminor=0, int minDBMSpoint=0)
Query user, to prevent silent, automatic database upgrades.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
void Closed(QString, int)
bool m_expertMode
Also allow newer DB schema.
@ MYTH_SCHEMA_USE_EXISTING
static MythSchemaUpgrade GuiPrompt(const QString &message, bool upgradable, bool expert)
QString GetDBMSVersion(void)
Returns the QString version name of the DBMS or QString() in the event of an error.
Basic menu dialog, message and a list of options.
QString getResponse(const QString &query, const QString &def)
In an interactive shell, prompt the user to input a string.
static MythDBBackupStatus BackupDB(QString &filename, bool disableRotation=false)
Requests a backup of the database.
static int CountClients(void)
Estimate the number of MythTV programs using the database.
QString m_dbName
database name
QString m_backupResult
File path, or FAILED
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
int GetNumSetting(const QString &key, int defaultval=0)
static MythDB * getMythDB()
int m_versionsBehind
How many schema versions old is the DB?
MythDBBackupStatus BackupDB(void)
Call DBUtil::BackupDB(), and store results.
MythDBBackupStatus m_backupStatus
BackupDB() status.
MythUIBusyDialog * m_busyPopup
Displayed during long pauses.
bool m_emptyDB
Is the database currently empty?
Provides UI and helper functions for DB Schema updates.
MythSchemaUpgrade
Return values from PromptForUpgrade()
void SetMessage(const QString &message)
MythMainWindow * GetMythMainWindow(void)
static bool IsNewDatabase(void)
Returns true for a new (empty) database.
QString m_schemaName
Shown to user in logs.
QString m_schemaSetting
To lookup the schema version.
bool m_autoUpgrade
If no UI, always upgrade.
SchemaUpgradeWizard(QString DBSchemaSetting, QString appName, QString upgradeSchemaVal)
MythUIHelper * GetMythUI()
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
MythConfirmationDialog * ShowOkPopup(const QString &message, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
QString m_DBver
Schema version in the database.
QString m_newSchemaVer
What we need to upgrade to.
QString GetSetting(const QString &key, const QString &defaultval="")
int CompareDBMSVersion(int major, int minor=0, int point=0)
Compares the version of the active DBMS with the provided version.