Skip to content

Commit ea209de

Browse files
committed
Database: Make it possible to trigger the "Repair Database" action via --repair-database CLI option
1 parent 41e98ba commit ea209de

4 files changed

Lines changed: 23 additions & 5 deletions

File tree

src/library/trackcollectionmanager.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "sources/soundsourceproxy.h"
1212
#include "track/track.h"
1313
#include "util/assert.h"
14+
#include "util/cmdlineargs.h"
1415
#include "util/db/dbconnectionpooled.h"
1516
#include "util/logger.h"
1617

@@ -43,9 +44,11 @@ TrackCollectionManager::TrackCollectionManager(
4344
m_pInternalCollection(createInternalTrackCollection(this, pConfig, deleteTrackForTestingFn)) {
4445
const QSqlDatabase dbConnection = mixxx::DbConnectionPooled(pDbConnectionPool);
4546

46-
// TODO(XXX): Add a checkbox in the library preferences for checking
47-
// and repairing the database on the next restart of the application.
48-
if (pConfig->getValue(kRepairDatabaseOnNextRestartConfigKey, false)) {
47+
// The database repair can be triggered via "Repair Database"
48+
// in the options menu, as well as using the command line option
49+
// "--repair-database".
50+
if (CmdlineArgs::Instance().getRepairDatabase() ||
51+
pConfig->getValue(kRepairDatabaseOnNextRestartConfigKey, false)) {
4952
m_pInternalCollection->repairDatabase(dbConnection);
5053
// Reset config value
5154
pConfig->setValue(kRepairDatabaseOnNextRestartConfigKey, false);

src/mixxxmainwindow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,8 +1155,8 @@ void MixxxMainWindow::slotOptionsRepairDatabase() {
11551155

11561156
// Set flag and exit out of Mixxx
11571157
m_pCoreServices->getSettings()->setValue(
1158-
mixxx::library::prefs::kRepairDatabaseOnNextRestartConfigKey,
1159-
true);
1158+
mixxx::library::prefs::kRepairDatabaseOnNextRestartConfigKey,
1159+
true);
11601160
close();
11611161
}
11621162
}

src/util/cmdlineargs.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ CmdlineArgs::CmdlineArgs()
5959
m_qml(false),
6060
#endif
6161
m_safeMode(false),
62+
m_repairDatabase(false),
6263
m_useLegacyVuMeter(false),
6364
m_useLegacySpinny(false),
6465
m_debugAssertBreak(false),
@@ -199,6 +200,12 @@ bool CmdlineArgs::parse(const QStringList& arguments, CmdlineArgs::ParseMode mod
199200
: QString());
200201
parser.addOption(rescanLibrary);
201202

203+
const QCommandLineOption repairDatabase(QStringLiteral("repair-database"),
204+
forUserFeedback ? QCoreApplication::translate("CmdlineArgs",
205+
"Run a database cleanup when Mixxx is launched.")
206+
: QString());
207+
parser.addOption(repairDatabase);
208+
202209
// An option with a value
203210
const QCommandLineOption settingsPath(QStringLiteral("settings-path"),
204211
forUserFeedback ? QCoreApplication::translate("CmdlineArgs",
@@ -446,6 +453,10 @@ bool CmdlineArgs::parse(const QStringList& arguments, CmdlineArgs::ParseMode mod
446453
m_rescanLibrary = true;
447454
}
448455

456+
if (parser.isSet(repairDatabase)) {
457+
m_repairDatabase = true;
458+
}
459+
449460
if (parser.isSet(settingsPath)) {
450461
m_settingsPath = parser.value(settingsPath);
451462
if (!m_settingsPath.endsWith("/")) {

src/util/cmdlineargs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class CmdlineArgs final {
5555
}
5656
#endif
5757
bool getSafeMode() const { return m_safeMode; }
58+
bool getRepairDatabase() const {
59+
return m_repairDatabase;
60+
}
5861
bool useColors() const {
5962
return m_useColors;
6063
}
@@ -112,6 +115,7 @@ class CmdlineArgs final {
112115
bool m_awareOfRisk;
113116
#endif
114117
bool m_safeMode;
118+
bool m_repairDatabase;
115119
bool m_useLegacyVuMeter;
116120
bool m_useLegacySpinny;
117121
bool m_debugAssertBreak;

0 commit comments

Comments
 (0)