feat(Core/Modules): Preparation to implement progression-system module. (#8837)

This commit is contained in:
UltraNix
2021-11-06 14:06:12 +01:00
committed by GitHub
parent 93bbff4cca
commit 70d8b88f3b
13 changed files with 253 additions and 97 deletions

View File

@@ -289,6 +289,67 @@ bool DBUpdater<T>::Update(DatabaseWorkerPool<T>& pool)
return true;
}
template<class T>
bool DBUpdater<T>::Update(DatabaseWorkerPool<T>& pool, std::vector<std::string> const* setDirectories)
{
if (!DBUpdaterUtil::CheckExecutable())
{
return false;
}
Path const sourceDirectory(BuiltInConfig::GetSourceDirectory());
if (!is_directory(sourceDirectory))
{
return false;
}
auto CheckUpdateTable = [&](std::string const& tableName)
{
auto checkTable = DBUpdater<T>::Retrieve(pool, Acore::StringFormat("SHOW TABLES LIKE '%s'", tableName.c_str()));
if (!checkTable)
{
Path const temp(GetBaseFilesDirectory() + tableName + ".sql");
try
{
DBUpdater<T>::ApplyFile(pool, temp);
}
catch (UpdateException&)
{
return false;
}
return true;
}
return true;
};
if (!CheckUpdateTable("updates") || !CheckUpdateTable("updates_include"))
{
return false;
}
UpdateFetcher updateFetcher(sourceDirectory, [&](std::string const & query) { DBUpdater<T>::Apply(pool, query); },
[&](Path const & file) { DBUpdater<T>::ApplyFile(pool, file); },
[&](std::string const & query) -> QueryResult { return DBUpdater<T>::Retrieve(pool, query); }, DBUpdater<T>::GetDBModuleName(), setDirectories);
UpdateResult result;
try
{
result = updateFetcher.Update(
sConfigMgr->GetOption<bool>("Updates.Redundancy", true),
sConfigMgr->GetOption<bool>("Updates.AllowRehash", true),
sConfigMgr->GetOption<bool>("Updates.ArchivedRedundancy", false),
sConfigMgr->GetOption<int32>("Updates.CleanDeadRefMaxCount", 3));
}
catch (UpdateException&)
{
return false;
}
return true;
}
template<class T>
bool DBUpdater<T>::Populate(DatabaseWorkerPool<T>& pool)
{