26 QString upgradeSchemaVal)
27 : m_schemaSetting(
std::move(DBSchemaSetting)),
28 m_schemaName(
std::move(appName)),
29 m_newSchemaVer(
std::move(upgradeSchemaVal))
39#if defined(ENABLE_SCHEMA_DEVELOPER_MODE) && ENABLE_SCHEMA_DEVELOPER_MODE
53 const QString &appName,
54 const QString &upgradeSchemaVal)
88 LOG(VB_GENERAL, LOG_INFO,
89 "The database seems to be empty - not attempting a backup");
105 LOG(VB_GENERAL, LOG_INFO,
"No current database version?");
109 LOG(VB_GENERAL, LOG_INFO,
"Database appears to be empty/new!");
115 LOG(VB_GENERAL, LOG_INFO,
116 QString(
"Current %1 Schema Version (%2): %3")
120#if defined(TESTING) && TESTING
136 int old_version =
m_DBver.toInt(&old_ok);
137 if (new_ok && old_ok)
146 bool upgradable,
bool expert)
167 dlg->AddButton(tr(
"Exit"));
170 dlg->AddButton(tr(
"Upgrade"));
174 dlg->AddButton(
"Use current schema");
181 &block, [&](
const QString& ,
int result) { block.exit(result); });
184 btnIndex = block.exec();
223 const bool upgradeAllowed,
224 const bool upgradeIfNoUI,
225 const int minDBMSmajor,
226 const int minDBMSminor,
227 const int minDBMSpoint)
229 bool connections =
false;
231 bool upgradable =
false;
232 bool validDBMS =
false;
241#if defined(minDBMS_is_only_for_schema_upgrades) && minDBMS_is_only_for_schema_upgrades
258 validDBMS = (minDBMSmajor == 0)
261 minDBMSminor, minDBMSpoint) >= 0;
268 warnOtherCl = tr(
"There are also other clients using this"
269 " database. They should be shut down first.");
272 warnOldDBMS = tr(
"Error: This version of Myth%1"
273 " requires MySQL %2.%3.%4 or later."
274 " You seem to be running MySQL version %5.")
275 .arg(name).arg(minDBMSmajor).arg(minDBMSminor)
292 if (!gui && (!isatty(fileno(stdin)) || !isatty(fileno(
stdout))))
294 LOG(VB_GENERAL, LOG_INFO,
295 "Console is non-interactive, can't prompt user...");
299 LOG(VB_GENERAL, LOG_CRIT,
"Using existing schema.");
305 LOG(VB_GENERAL, LOG_CRIT, warnOldDBMS);
311 LOG(VB_GENERAL, LOG_CRIT,
312 QString(
"Error: MythTV database has newer %1 schema (%2) "
313 "than expected (%3).")
318 if (upgradeIfNoUI && validDBMS)
320 LOG(VB_GENERAL, LOG_CRIT,
"Upgrading.");
339 message = tr(
"Error: MythTV cannot upgrade the schema of this"
340 " datatase because other clients are using it.\n\n"
341 "Please shut them down before upgrading.");
346 message = tr(
"Warning: MythTV wants to upgrade your database,")
347 +
"\n" + tr(
"for the %1 schema, from %2 to %3.");
351 message +=
"\n\nYou can try using the old schema,"
352 " but that may cause problems.";
358 message = warnOldDBMS;
363 message = tr(
"This version of MythTV requires an updated database. ")
365 +
"\n\n" + tr(
"Please run mythtv-setup or mythbackend "
366 "to update your database.");
374 message =
"Warning: MythTV database has newer"
375 " %1 schema (%2) than expected (%3).";
379 message = tr(
"Error: MythTV database has newer"
380 " %1 schema (%2) than expected (%3).");
386 message +=
"\n" + tr(
"MythTV was unable to backup your database.");
388 if (message.contains(
"%1"))
393 message +=
"\n\n" + tr(
"Database Host: %1\nDatabase Name: %2")
425 message = tr(
"If your system becomes unstable, a database"
426 " backup file called\n%1\nis located in %2")
427 .arg(fileName, dirName);
431 message = tr(
"This cannot be un-done, so having a"
432 " database backup would be a good idea.");
435 message +=
"\n\n" + warnOtherCl;
443 std::cout <<
'\n' << message.toLocal8Bit().constData() <<
"\n\n";
450 std::cout <<
"WARNING: MythTV was unable to backup your database.\n\n";
455 std::cout <<
"If your system becomes unstable, "
456 "a database backup is located in "
462 resp =
getResponse(
"Would you like to use the existing schema?",
"yes");
463 if (resp.isEmpty() || resp.startsWith(
"y", Qt::CaseInsensitive))
467 resp =
getResponse(
"\nShall I upgrade this database?",
"yes");
468 if (!resp.isEmpty() && !resp.startsWith(
"y", Qt::CaseInsensitive))
472 std::cout <<
'\n' << warnOtherCl.toLocal8Bit().constData() <<
'\n';
477 resp =
getResponse(
"\nA database backup might be a good idea"
478 "\nAre you sure you want to upgrade?",
"no");
479 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