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))
static MythDBBackupStatus BackupDB(QString &filename, bool disableRotation=false)
Requests a backup of the database.
int CompareDBMSVersion(int major, int minor=0, int point=0)
Compares the version of the active DBMS with the provided version.
static int CountClients(void)
Estimate the number of MythTV programs using the database.
QString GetDBMSVersion(void)
Returns the QString version name of the DBMS or QString() in the event of an error.
static bool IsNewDatabase(void)
Returns true for a new (empty) database.
Structure containing the basic Database parameters.
QString m_dbName
database name
QString m_dbHostName
database server
QString GetSetting(const QString &key, const QString &defaultval="")
int GetNumSetting(const QString &key, int defaultval=0)
static MythDB * getMythDB()
Basic menu dialog, message and a list of options.
void Closed(QString, int)
MythScreenStack * GetMainStack()
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
void SetMessage(const QString &message)
bool IsScreenSetup() const
Provides UI and helper functions for DB Schema updates.
QString m_schemaName
Shown to user in logs.
bool m_autoUpgrade
If no UI, always upgrade.
MythDBBackupStatus m_backupStatus
BackupDB() status.
MythDBBackupStatus BackupDB(void)
Call DBUtil::BackupDB(), and store results.
QString m_newSchemaVer
What we need to upgrade to.
int m_versionsBehind
How many schema versions old is the DB?
QString m_schemaSetting
To lookup the schema version.
QString m_backupResult
File path, or FAILED
static MythSchemaUpgrade GuiPrompt(const QString &message, bool upgradable, bool expert)
bool m_emptyDB
Is the database currently empty?
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.
MythUIBusyDialog * m_busyPopup
Displayed during long pauses.
QString m_DBver
Schema version in the database.
bool m_expertMode
Also allow newer DB schema.
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.
SchemaUpgradeWizard(QString DBSchemaSetting, QString appName, QString upgradeSchemaVal)
~SchemaUpgradeWizard() override
int Compare(void)
How many schema versions old is the DB?
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythConfirmationDialog * ShowOkPopup(const QString &message, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
bool WaitFor(MythConfirmationDialog *dialog)
Blocks until confirmation dialog exits.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
MythMainWindow * GetMythMainWindow(void)
QString getResponse(const QString &query, const QString &def)
In an interactive shell, prompt the user to input a string.
MythUIBusyDialog * ShowBusyPopup(const QString &message)
MythUIHelper * GetMythUI()
static SchemaUpgradeWizard * c_wizard
MythSchemaUpgrade
Return values from PromptForUpgrade()
@ MYTH_SCHEMA_USE_EXISTING