mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-16 00:36:07 +00:00
feat(Core/Modules): add separated lib for modules (#9281)
This commit is contained in:
@@ -54,9 +54,6 @@ target_link_libraries(database
|
||||
PUBLIC
|
||||
common)
|
||||
|
||||
# Add support auto update db for modules
|
||||
GetModuleList()
|
||||
|
||||
set_target_properties(database
|
||||
PROPERTIES
|
||||
FOLDER
|
||||
|
||||
@@ -25,11 +25,11 @@
|
||||
#include <mysqld_error.h>
|
||||
#include <thread>
|
||||
|
||||
DatabaseLoader::DatabaseLoader(std::string const& logger, uint32 const defaultUpdateMask)
|
||||
: _logger(logger), _autoSetup(sConfigMgr->GetOption<bool>("Updates.AutoSetup", true)),
|
||||
_updateFlags(sConfigMgr->GetOption<uint32>("Updates.EnableDatabases", defaultUpdateMask))
|
||||
{
|
||||
}
|
||||
DatabaseLoader::DatabaseLoader(std::string const& logger, uint32 const defaultUpdateMask, std::string_view modulesList)
|
||||
: _logger(logger),
|
||||
_modulesList(modulesList),
|
||||
_autoSetup(sConfigMgr->GetOption<bool>("Updates.AutoSetup", true)),
|
||||
_updateFlags(sConfigMgr->GetOption<uint32>("Updates.EnableDatabases", defaultUpdateMask)) { }
|
||||
|
||||
template <class T>
|
||||
DatabaseLoader& DatabaseLoader::AddDatabase(DatabaseWorkerPool<T>& pool, std::string const& name)
|
||||
@@ -127,7 +127,7 @@ DatabaseLoader& DatabaseLoader::AddDatabase(DatabaseWorkerPool<T>& pool, std::st
|
||||
|
||||
_update.push([this, name, &pool]() -> bool
|
||||
{
|
||||
if (!DBUpdater<T>::Update(pool))
|
||||
if (!DBUpdater<T>::Update(pool, _modulesList))
|
||||
{
|
||||
LOG_ERROR(_logger, "Could not update the %s database, see log for details.", name.c_str());
|
||||
return false;
|
||||
|
||||
@@ -32,7 +32,7 @@ class DatabaseWorkerPool;
|
||||
class AC_DATABASE_API DatabaseLoader
|
||||
{
|
||||
public:
|
||||
DatabaseLoader(std::string const& logger, uint32 const defaultUpdateMask = 0);
|
||||
DatabaseLoader(std::string const& logger, uint32 const defaultUpdateMask = 0, std::string_view modulesList = {});
|
||||
|
||||
// Register a database to the loader (lazy implemented)
|
||||
template <class T>
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
return _updateFlags;
|
||||
}
|
||||
|
||||
private :
|
||||
private:
|
||||
bool OpenDatabases();
|
||||
bool PopulateDatabases();
|
||||
bool UpdateDatabases();
|
||||
@@ -71,6 +71,7 @@ private :
|
||||
bool Process(std::queue<Predicate>& queue);
|
||||
|
||||
std::string const _logger;
|
||||
std::string_view _modulesList;
|
||||
bool const _autoSetup;
|
||||
uint32 const _updateFlags;
|
||||
|
||||
|
||||
@@ -214,7 +214,7 @@ bool DBUpdater<T>::Create(DatabaseWorkerPool<T>& pool)
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool DBUpdater<T>::Update(DatabaseWorkerPool<T>& pool)
|
||||
bool DBUpdater<T>::Update(DatabaseWorkerPool<T>& pool, std::string_view modulesList /*= {}*/)
|
||||
{
|
||||
if (!DBUpdaterUtil::CheckExecutable())
|
||||
return false;
|
||||
@@ -260,7 +260,7 @@ bool DBUpdater<T>::Update(DatabaseWorkerPool<T>& pool)
|
||||
|
||||
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());
|
||||
[&](std::string const & query) -> QueryResult { return DBUpdater<T>::Retrieve(pool, query); }, DBUpdater<T>::GetDBModuleName(), modulesList);
|
||||
|
||||
UpdateResult result;
|
||||
try
|
||||
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
static bool IsEnabled(uint32 const updateMask);
|
||||
static BaseLocation GetBaseLocationType();
|
||||
static bool Create(DatabaseWorkerPool<T>& pool);
|
||||
static bool Update(DatabaseWorkerPool<T>& pool);
|
||||
static bool Update(DatabaseWorkerPool<T>& pool, std::string_view modulesList = {});
|
||||
static bool Update(DatabaseWorkerPool<T>& pool, std::vector<std::string> const* setDirectories);
|
||||
static bool Populate(DatabaseWorkerPool<T>& pool);
|
||||
|
||||
|
||||
@@ -45,6 +45,17 @@ UpdateFetcher::UpdateFetcher(Path const& sourceDirectory,
|
||||
{
|
||||
}
|
||||
|
||||
UpdateFetcher::UpdateFetcher(Path const& sourceDirectory,
|
||||
std::function<void(std::string const&)> const& apply,
|
||||
std::function<void(Path const& path)> const& applyFile,
|
||||
std::function<QueryResult(std::string const&)> const& retrieve,
|
||||
std::string const& dbModuleName,
|
||||
std::string_view modulesList /*= {}*/) :
|
||||
_sourceDirectory(std::make_unique<Path>(sourceDirectory)), _apply(apply), _applyFile(applyFile),
|
||||
_retrieve(retrieve), _dbModuleName(dbModuleName), _setDirectories(nullptr), _modulesList(modulesList)
|
||||
{
|
||||
}
|
||||
|
||||
UpdateFetcher::~UpdateFetcher()
|
||||
{
|
||||
}
|
||||
@@ -144,8 +155,10 @@ UpdateFetcher::DirectoryStorage UpdateFetcher::ReceiveIncludedDirectories() cons
|
||||
|
||||
std::vector<std::string> moduleList;
|
||||
|
||||
auto const& _modulesTokens = Acore::Tokenize(AC_MODULES_LIST, ',', true);
|
||||
for (auto const& itr : _modulesTokens) moduleList.emplace_back(itr);
|
||||
for (auto const& itr : Acore::Tokenize(_modulesList, ',', true))
|
||||
{
|
||||
moduleList.emplace_back(itr);
|
||||
}
|
||||
|
||||
// data/sql
|
||||
for (auto const& itr : moduleList)
|
||||
@@ -154,9 +167,11 @@ UpdateFetcher::DirectoryStorage UpdateFetcher::ReceiveIncludedDirectories() cons
|
||||
|
||||
Path const p(path);
|
||||
if (!is_directory(p))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
DirectoryEntry const entry = {p, AppliedFileEntry::StateConvert("MODULE")};
|
||||
DirectoryEntry const entry = { p, AppliedFileEntry::StateConvert("MODULE") };
|
||||
directories.push_back(entry);
|
||||
|
||||
LOG_TRACE("sql.updates", "Added applied modules file \"%s\" from remote.", p.filename().generic_string().c_str());
|
||||
|
||||
@@ -48,6 +48,14 @@ public:
|
||||
std::function<void(std::string const&)> const& apply,
|
||||
std::function<void(Path const& path)> const& applyFile,
|
||||
std::function<QueryResult(std::string const&)> const& retrieve, std::string const& dbModuleName, std::vector<std::string> const* setDirectories = nullptr);
|
||||
|
||||
UpdateFetcher(Path const& updateDirectory,
|
||||
std::function<void(std::string const&)> const& apply,
|
||||
std::function<void(Path const& path)> const& applyFile,
|
||||
std::function<QueryResult(std::string const&)> const& retrieve,
|
||||
std::string const& dbModuleName,
|
||||
std::string_view modulesList = {});
|
||||
|
||||
~UpdateFetcher();
|
||||
|
||||
UpdateResult Update(bool const redundancyChecks, bool const allowRehash,
|
||||
@@ -153,6 +161,7 @@ private:
|
||||
// modules
|
||||
std::string const _dbModuleName;
|
||||
std::vector<std::string> const* _setDirectories;
|
||||
std::string_view _modulesList = {};
|
||||
};
|
||||
|
||||
#endif // UpdateFetcher_h__
|
||||
|
||||
Reference in New Issue
Block a user