|
@@ -281,7 +281,7 @@ bool ADataBaseSetup::createDatabase()
|
|
|
|
|
|
bool ADataBaseSetup::downloadTemplates()
|
|
bool ADataBaseSetup::downloadTemplates()
|
|
{
|
|
{
|
|
- QDir template_dir(AStandardPaths::pathTo(AStandardPaths::Templates));
|
|
|
|
|
|
+ QDir template_dir(AStandardPaths::absPathOf(AStandardPaths::Templates));
|
|
DEB << template_dir;
|
|
DEB << template_dir;
|
|
for (const auto& table : templateTables) {
|
|
for (const auto& table : templateTables) {
|
|
QEventLoop loop;
|
|
QEventLoop loop;
|
|
@@ -295,7 +295,6 @@ bool ADataBaseSetup::downloadTemplates()
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
-
|
|
|
|
bool ADataBaseSetup::backupOldData()
|
|
bool ADataBaseSetup::backupOldData()
|
|
{
|
|
{
|
|
auto database_file = aDB()->databaseFile;
|
|
auto database_file = aDB()->databaseFile;
|
|
@@ -303,14 +302,17 @@ bool ADataBaseSetup::backupOldData()
|
|
DEB << "No Database to backup, returning.";
|
|
DEB << "No Database to backup, returning.";
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+
|
|
auto date_string = QDateTime::currentDateTime().toString(Qt::ISODate);
|
|
auto date_string = QDateTime::currentDateTime().toString(Qt::ISODate);
|
|
- auto backup_dir = QDir(AStandardPaths::pathTo(AStandardPaths::DatabaseBackup));
|
|
|
|
|
|
+ auto backup_dir = QDir(AStandardPaths::absPathOf(AStandardPaths::DatabaseBackup));
|
|
auto backup_name = database_file.baseName() + "-backup-" + date_string + ".bak";
|
|
auto backup_name = database_file.baseName() + "-backup-" + date_string + ".bak";
|
|
- if(!backup_dir.mkpath(backup_name)){
|
|
|
|
- DEB << "Could not create file " << backup_name << " at: " << backup_dir.path();
|
|
|
|
|
|
+ auto file = QFile(aDB()->databaseFile.absoluteFilePath());
|
|
|
|
+
|
|
|
|
+ if (!file.rename(backup_dir.absolutePath() + '/' + backup_name)) {
|
|
|
|
+ DEB << "Unable to backup old database.";
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- DEB << "Backing up old database as: " << backup_name;
|
|
|
|
|
|
+ DEB << "Backed up old database as: " << backup_name;
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -325,7 +327,7 @@ bool ADataBaseSetup::importDefaultData()
|
|
DEB << "Error: " << query.lastError().text();
|
|
DEB << "Error: " << query.lastError().text();
|
|
}
|
|
}
|
|
//fill with data from csv
|
|
//fill with data from csv
|
|
- if (!commitData(aReadCsv(AStandardPaths::pathTo(AStandardPaths::Templates)
|
|
|
|
|
|
+ if (!commitData(aReadCsv(AStandardPaths::absPathOf(AStandardPaths::Templates)
|
|
% QLatin1Char('/')
|
|
% QLatin1Char('/')
|
|
% table % QStringLiteral(".csv")),
|
|
% table % QStringLiteral(".csv")),
|
|
table)) {
|
|
table)) {
|
|
@@ -390,21 +392,20 @@ bool ADataBaseSetup::createSchemata(const QStringList &statements)
|
|
if(!query.isActive()) {
|
|
if(!query.isActive()) {
|
|
errors << statement.section(QLatin1Char(' '),2,2) + " ERROR - " + query.lastError().text();
|
|
errors << statement.section(QLatin1Char(' '),2,2) + " ERROR - " + query.lastError().text();
|
|
DEB << "Query: " << query.lastQuery();
|
|
DEB << "Query: " << query.lastQuery();
|
|
- } else {
|
|
|
|
- DEB << "Schema added: " << statement.section(QLatin1Char(' '),2,2);
|
|
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
|
|
+ DEB << "Schema added: " << statement.section(QLatin1Char(' '), 2, 2);
|
|
}
|
|
}
|
|
|
|
|
|
if (!errors.isEmpty()) {
|
|
if (!errors.isEmpty()) {
|
|
- DEB << "The following errors have ocurred: ";
|
|
|
|
|
|
+ DEB_SRC << "The following errors have ocurred: ";
|
|
for (const auto& error : errors) {
|
|
for (const auto& error : errors) {
|
|
- DEB << error;
|
|
|
|
|
|
+ DEB_RAW << error;
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|
|
- } else {
|
|
|
|
- DEB << "All schemas added successfully";
|
|
|
|
- return true;
|
|
|
|
}
|
|
}
|
|
|
|
+ DEB << "All schemas added successfully";
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
/*!
|
|
/*!
|
|
* \brief DbSetup::commitData inserts the data parsed from a csv file into the
|
|
* \brief DbSetup::commitData inserts the data parsed from a csv file into the
|