diff --git a/domain-server/src/AssetsBackupHandler.cpp b/domain-server/src/AssetsBackupHandler.cpp index 694277910f..19b970f30a 100644 --- a/domain-server/src/AssetsBackupHandler.cpp +++ b/domain-server/src/AssetsBackupHandler.cpp @@ -113,7 +113,7 @@ void AssetsBackupHandler::checkForAssetsToDelete() { std::pair AssetsBackupHandler::isAvailable(QString filePath) { - auto it = find_if(begin(_backups), end(_backups), [&](const std::vector::value_type& value) { + const auto it = find_if(begin(_backups), end(_backups), [&](const AssetServerBackup& value) { return value.filePath == filePath; }); if (it == end(_backups)) { @@ -269,7 +269,7 @@ void AssetsBackupHandler::recoverBackup(QuaZip& zip) { qCWarning(asset_backup) << "Current asset mappings that might be stale."; } - auto it = find_if(begin(_backups), end(_backups), [&](const std::vector::value_type& value) { + const auto it = find_if(begin(_backups), end(_backups), [&](const AssetServerBackup& value) { return value.filePath == zip.getZipName(); }); if (it == end(_backups)) { @@ -314,7 +314,7 @@ void AssetsBackupHandler::deleteBackup(const QString& absoluteFilePath) { return; } - auto it = find_if(begin(_backups), end(_backups), [&](const std::vector::value_type& value) { + const auto it = find_if(begin(_backups), end(_backups), [&](const AssetServerBackup& value) { return value.filePath == absoluteFilePath; }); if (it == end(_backups)) { @@ -335,7 +335,7 @@ void AssetsBackupHandler::consolidateBackup(QuaZip& zip) { } QFileInfo zipInfo(zip.getZipName()); - auto it = find_if(begin(_backups), end(_backups), [&](const std::vector::value_type& value) { + const auto it = find_if(begin(_backups), end(_backups), [&](const AssetServerBackup& value) { QFileInfo info(value.filePath); return info.fileName() == zipInfo.fileName(); }); diff --git a/domain-server/src/DomainContentBackupManager.cpp b/domain-server/src/DomainContentBackupManager.cpp index 0bef6bb891..dca3c645d6 100644 --- a/domain-server/src/DomainContentBackupManager.cpp +++ b/domain-server/src/DomainContentBackupManager.cpp @@ -50,7 +50,7 @@ void DomainContentBackupManager::addBackupHandler(BackupHandlerPointer handler) } DomainContentBackupManager::DomainContentBackupManager(const QString& backupDirectory, - const QJsonObject& settings, + const QVariantList& backupRules, int persistInterval, bool debugTimestampNow) : _backupDirectory(backupDirectory), @@ -62,59 +62,38 @@ DomainContentBackupManager::DomainContentBackupManager(const QString& backupDire // Make sure the backup directory exists. QDir(_backupDirectory).mkpath("."); - parseSettings(settings); + parseBackupRules(backupRules); } -void DomainContentBackupManager::parseSettings(const QJsonObject& settings) { - static const QString BACKUP_RULES_KEY = "backup_rules"; - if (settings[BACKUP_RULES_KEY].isArray()) { - const QJsonArray& backupRules = settings[BACKUP_RULES_KEY].toArray(); - qCDebug(domain_server) << "BACKUP RULES:"; +void DomainContentBackupManager::parseBackupRules(const QVariantList& backupRules) { + qCDebug(domain_server) << "BACKUP RULES:"; - for (const QJsonValue& value : backupRules) { - QJsonObject obj = value.toObject(); + for (const QVariant& value : backupRules) { + QVariantMap map = value.toMap(); - int interval = 0; - int count = 0; + int interval = map["backupInterval"].toInt(); + int count = map["maxBackupVersions"].toInt(); + auto name = map["Name"].toString(); + auto format = name.replace(" ", "_").toLower(); - QJsonValue intervalVal = obj["backupInterval"]; - if (intervalVal.isString()) { - interval = intervalVal.toString().toInt(); - } else { - interval = intervalVal.toInt(); - } + qCDebug(domain_server) << " Name:" << name; + qCDebug(domain_server) << " format:" << format; + qCDebug(domain_server) << " interval:" << interval; + qCDebug(domain_server) << " count:" << count; - QJsonValue countVal = obj["maxBackupVersions"]; - if (countVal.isString()) { - count = countVal.toString().toInt(); - } else { - count = countVal.toInt(); - } + BackupRule newRule = { name, interval, format, count, 0 }; - auto name = obj["Name"].toString(); - auto format = name.replace(" ", "_").toLower(); + newRule.lastBackupSeconds = getMostRecentBackupTimeInSecs(format); - qCDebug(domain_server) << " Name:" << name; - qCDebug(domain_server) << " format:" << format; - qCDebug(domain_server) << " interval:" << interval; - qCDebug(domain_server) << " count:" << count; - - BackupRule newRule = { name, interval, format, count, 0 }; - - newRule.lastBackupSeconds = getMostRecentBackupTimeInSecs(format); - - if (newRule.lastBackupSeconds > 0) { - auto now = QDateTime::currentSecsSinceEpoch(); - auto sinceLastBackup = now - newRule.lastBackupSeconds; - qCDebug(domain_server).noquote() << " lastBackup:" << formatSecTime(sinceLastBackup) << "ago"; - } else { - qCDebug(domain_server) << " lastBackup: NEVER"; - } - - _backupRules.push_back(newRule); + if (newRule.lastBackupSeconds > 0) { + auto now = QDateTime::currentSecsSinceEpoch(); + auto sinceLastBackup = now - newRule.lastBackupSeconds; + qCDebug(domain_server).noquote() << " lastBackup:" << formatSecTime(sinceLastBackup) << "ago"; + } else { + qCDebug(domain_server) << " lastBackup: NEVER"; } - } else { - qCDebug(domain_server) << "BACKUP RULES: NONE"; + + _backupRules.push_back(newRule); } } diff --git a/domain-server/src/DomainContentBackupManager.h b/domain-server/src/DomainContentBackupManager.h index d4b1f60b87..c820a084f8 100644 --- a/domain-server/src/DomainContentBackupManager.h +++ b/domain-server/src/DomainContentBackupManager.h @@ -50,7 +50,7 @@ public: static const int DEFAULT_PERSIST_INTERVAL; DomainContentBackupManager(const QString& rootBackupDirectory, - const QJsonObject& settings, + const QVariantList& settings, int persistInterval = DEFAULT_PERSIST_INTERVAL, bool debugTimestampNow = false); @@ -82,7 +82,7 @@ protected: void refreshBackupRules(); bool getMostRecentBackup(const QString& format, QString& mostRecentBackupFileName, QDateTime& mostRecentBackupTime); int64_t getMostRecentBackupTimeInSecs(const QString& format); - void parseSettings(const QJsonObject& settings); + void parseBackupRules(const QVariantList& backupRules); std::pair createBackup(const QString& prefix, const QString& name); diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 9cecea5f70..a332810e54 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -296,15 +296,12 @@ DomainServer::DomainServer(int argc, char* argv[]) : qCDebug(domain_server) << "Created entities data directory"; } maybeHandleReplacementEntityFile(); - - auto contentArchivesGroup = _settingsManager.valueOrDefaultValueForKeyPath(AUTOMATIC_CONTENT_ARCHIVES_GROUP); - auto archivesIntervalObject = QJsonObject(); - if (contentArchivesGroup.canConvert()) { - archivesIntervalObject = QJsonObject::fromVariantMap(contentArchivesGroup.toMap()); - } - _contentManager.reset(new DomainContentBackupManager(getContentBackupDir(), archivesIntervalObject)); + static const QString BACKUP_RULES_KEYPATH = AUTOMATIC_CONTENT_ARCHIVES_GROUP + ".backup_rules"; + auto backupRulesVariant = _settingsManager.valueOrDefaultValueForKeyPath(BACKUP_RULES_KEYPATH); + + _contentManager.reset(new DomainContentBackupManager(getContentBackupDir(), backupRulesVariant.toList())); connect(_contentManager.get(), &DomainContentBackupManager::started, _contentManager.get(), [this](){ _contentManager->addBackupHandler(BackupHandlerPointer(new EntitiesBackupHandler(getEntitiesFilePath(), getEntitiesReplacementFilePath())));