mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-15 10:00:28 +00:00
feat(Core/Modules): Preparation to implement progression-system module. (#8837)
This commit is contained in:
@@ -52,7 +52,12 @@ public:
|
||||
DATABASE_MASK_ALL = DATABASE_LOGIN | DATABASE_CHARACTER | DATABASE_WORLD
|
||||
};
|
||||
|
||||
private:
|
||||
[[nodiscard]] uint32 GetUpdateFlags() const
|
||||
{
|
||||
return _updateFlags;
|
||||
}
|
||||
|
||||
private :
|
||||
bool OpenDatabases();
|
||||
bool PopulateDatabases();
|
||||
bool UpdateDatabases();
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -76,6 +76,7 @@ public:
|
||||
static BaseLocation GetBaseLocationType();
|
||||
static bool Create(DatabaseWorkerPool<T>& pool);
|
||||
static bool Update(DatabaseWorkerPool<T>& pool);
|
||||
static bool Update(DatabaseWorkerPool<T>& pool, std::vector<std::string> const* setDirectories);
|
||||
static bool Populate(DatabaseWorkerPool<T>& pool);
|
||||
|
||||
// module
|
||||
|
||||
@@ -39,9 +39,9 @@ struct UpdateFetcher::DirectoryEntry
|
||||
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::function<QueryResult(std::string const&)> const& retrieve, std::string const& dbModuleName, std::vector<std::string> const* setDirectories /*= nullptr*/) :
|
||||
_sourceDirectory(std::make_unique<Path>(sourceDirectory)), _apply(apply), _applyFile(applyFile),
|
||||
_retrieve(retrieve), _dbModuleName(dbModuleName_)
|
||||
_retrieve(retrieve), _dbModuleName(dbModuleName), _setDirectories(setDirectories)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -96,53 +96,71 @@ UpdateFetcher::DirectoryStorage UpdateFetcher::ReceiveIncludedDirectories() cons
|
||||
{
|
||||
DirectoryStorage directories;
|
||||
|
||||
QueryResult const result = _retrieve("SELECT `path`, `state` FROM `updates_include`");
|
||||
if (!result)
|
||||
return directories;
|
||||
|
||||
do
|
||||
if (_setDirectories)
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
std::string path = fields[0].GetString();
|
||||
std::string state = fields[1].GetString();
|
||||
if (path.substr(0, 1) == "$")
|
||||
path = _sourceDirectory->generic_string() + path.substr(1);
|
||||
|
||||
Path const p(path);
|
||||
|
||||
if (!is_directory(p))
|
||||
for (auto const& itr : *_setDirectories)
|
||||
{
|
||||
LOG_WARN("sql.updates", "DBUpdater: Given update include directory \"%s\" does not exist, skipped!", p.generic_string().c_str());
|
||||
continue;
|
||||
std::string path = _sourceDirectory->generic_string() + itr;
|
||||
|
||||
Path const p(path);
|
||||
if (!is_directory(p))
|
||||
continue;
|
||||
|
||||
DirectoryEntry const entry = {p, AppliedFileEntry::StateConvert("MODULE")};
|
||||
directories.push_back(entry);
|
||||
|
||||
LOG_TRACE("sql.updates", "Added applied extra file \"%s\" from remote.", p.filename().generic_string().c_str());
|
||||
}
|
||||
|
||||
DirectoryEntry const entry = { p, AppliedFileEntry::StateConvert(state) };
|
||||
directories.push_back(entry);
|
||||
|
||||
LOG_TRACE("sql.updates", "Added applied file \"%s\" '%s' state from remote.", p.filename().generic_string().c_str(), state.c_str());
|
||||
|
||||
} while (result->NextRow());
|
||||
|
||||
std::vector<std::string> moduleList;
|
||||
|
||||
auto const& _modulesTokens = Acore::Tokenize(AC_MODULES_LIST, ',', true);
|
||||
for (auto const& itr : _modulesTokens)
|
||||
moduleList.emplace_back(itr);
|
||||
|
||||
// data/sql
|
||||
for (auto const& itr : moduleList)
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string path = _sourceDirectory->generic_string() + "/modules/" + itr + "/data/sql/" + _dbModuleName; // modules/mod-name/data/sql/db-world
|
||||
QueryResult const result = _retrieve("SELECT `path`, `state` FROM `updates_include`");
|
||||
if (!result)
|
||||
return directories;
|
||||
|
||||
Path const p(path);
|
||||
if (!is_directory(p))
|
||||
continue;
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
DirectoryEntry const entry = { p, AppliedFileEntry::StateConvert("CUSTOM") };
|
||||
directories.push_back(entry);
|
||||
std::string path = fields[0].GetString();
|
||||
std::string state = fields[1].GetString();
|
||||
if (path.substr(0, 1) == "$")
|
||||
path = _sourceDirectory->generic_string() + path.substr(1);
|
||||
|
||||
LOG_TRACE("sql.updates", "Added applied modules file \"%s\" from remote.", p.filename().generic_string().c_str());
|
||||
Path const p(path);
|
||||
|
||||
if (!is_directory(p))
|
||||
{
|
||||
LOG_WARN("sql.updates", "DBUpdater: Given update include directory \"%s\" does not exist, skipped!", p.generic_string().c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
DirectoryEntry const entry = {p, AppliedFileEntry::StateConvert(state)};
|
||||
directories.push_back(entry);
|
||||
|
||||
LOG_TRACE("sql.updates", "Added applied file \"%s\" '%s' state from remote.", p.filename().generic_string().c_str(), state.c_str());
|
||||
|
||||
} while (result->NextRow());
|
||||
|
||||
std::vector<std::string> moduleList;
|
||||
|
||||
auto const& _modulesTokens = Acore::Tokenize(AC_MODULES_LIST, ',', true);
|
||||
for (auto const& itr : _modulesTokens) moduleList.emplace_back(itr);
|
||||
|
||||
// data/sql
|
||||
for (auto const& itr : moduleList)
|
||||
{
|
||||
std::string path = _sourceDirectory->generic_string() + "/modules/" + itr + "/data/sql/" + _dbModuleName; // modules/mod-name/data/sql/db-world
|
||||
|
||||
Path const p(path);
|
||||
if (!is_directory(p))
|
||||
continue;
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
return directories;
|
||||
@@ -201,6 +219,11 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks,
|
||||
int32 const cleanDeadReferencesMaxCount) const
|
||||
{
|
||||
LocaleFileStorage const available = GetFileList();
|
||||
if (_setDirectories && available.empty())
|
||||
{
|
||||
return UpdateResult();
|
||||
}
|
||||
|
||||
AppliedFileStorage applied = ReceiveAppliedFiles();
|
||||
|
||||
size_t countRecentUpdates = 0;
|
||||
@@ -347,37 +370,51 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks,
|
||||
// Apply default updates
|
||||
for (auto const& availableQuery : available)
|
||||
{
|
||||
if (availableQuery.second != CUSTOM)
|
||||
if (availableQuery.second != CUSTOM && availableQuery.second != MODULE)
|
||||
ApplyUpdateFile(availableQuery);
|
||||
}
|
||||
|
||||
// Apply only custom updates
|
||||
// Apply only custom/module updates
|
||||
for (auto const& availableQuery : available)
|
||||
{
|
||||
if (availableQuery.second == CUSTOM)
|
||||
if (availableQuery.second == CUSTOM || availableQuery.second == MODULE)
|
||||
ApplyUpdateFile(availableQuery);
|
||||
}
|
||||
|
||||
// Cleanup up orphaned entries (if enabled)
|
||||
if (!applied.empty())
|
||||
if (!applied.empty() && !_setDirectories)
|
||||
{
|
||||
bool const doCleanup = (cleanDeadReferencesMaxCount < 0) || (applied.size() <= static_cast<size_t>(cleanDeadReferencesMaxCount));
|
||||
|
||||
AppliedFileStorage toCleanup;
|
||||
for (auto const& entry : applied)
|
||||
{
|
||||
LOG_WARN("sql.updates", ">> The file \'%s\' was applied to the database, but is missing in" \
|
||||
" your update directory now!", entry.first.c_str());
|
||||
if (entry.second.state != MODULE)
|
||||
{
|
||||
LOG_WARN("sql.updates",
|
||||
">> The file \'%s\' was applied to the database, but is missing in"
|
||||
" your update directory now!",
|
||||
entry.first.c_str());
|
||||
|
||||
if (doCleanup)
|
||||
LOG_INFO("sql.updates", "Deleting orphaned entry \'%s\'...", entry.first.c_str());
|
||||
if (doCleanup)
|
||||
{
|
||||
LOG_INFO("sql.updates", "Deleting orphaned entry \'%s\'...", entry.first.c_str());
|
||||
toCleanup.insert(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (doCleanup)
|
||||
CleanUp(applied);
|
||||
else
|
||||
if (!toCleanup.empty())
|
||||
{
|
||||
LOG_ERROR("sql.updates", "Cleanup is disabled! There were " SZFMTD " dirty files applied to your database, " \
|
||||
"but they are now missing in your source directory!", applied.size());
|
||||
if (doCleanup)
|
||||
CleanUp(toCleanup);
|
||||
else
|
||||
{
|
||||
LOG_ERROR("sql.updates",
|
||||
"Cleanup is disabled! There were " SZFMTD " dirty files applied to your database, "
|
||||
"but they are now missing in your source directory!",
|
||||
toCleanup.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
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::function<QueryResult(std::string const&)> const& retrieve, std::string const& dbModuleName, std::vector<std::string> const* setDirectories = nullptr);
|
||||
~UpdateFetcher();
|
||||
|
||||
UpdateResult Update(bool const redundancyChecks, bool const allowRehash,
|
||||
@@ -64,6 +64,7 @@ private:
|
||||
{
|
||||
RELEASED,
|
||||
CUSTOM,
|
||||
MODULE,
|
||||
ARCHIVED
|
||||
};
|
||||
|
||||
@@ -83,6 +84,8 @@ private:
|
||||
return RELEASED;
|
||||
else if (state == "CUSTOM")
|
||||
return CUSTOM;
|
||||
else if (state == "MODULE")
|
||||
return MODULE;
|
||||
|
||||
return ARCHIVED;
|
||||
}
|
||||
@@ -91,14 +94,16 @@ private:
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case RELEASED:
|
||||
return "RELEASED";
|
||||
case CUSTOM:
|
||||
return "CUSTOM";
|
||||
case ARCHIVED:
|
||||
return "ARCHIVED";
|
||||
default:
|
||||
return "";
|
||||
case RELEASED:
|
||||
return "RELEASED";
|
||||
case CUSTOM:
|
||||
return "CUSTOM";
|
||||
case MODULE:
|
||||
return "MODULE";
|
||||
case ARCHIVED:
|
||||
return "ARCHIVED";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,6 +152,7 @@ private:
|
||||
|
||||
// modules
|
||||
std::string const _dbModuleName;
|
||||
std::vector<std::string> const* _setDirectories;
|
||||
};
|
||||
|
||||
#endif // UpdateFetcher_h__
|
||||
|
||||
Reference in New Issue
Block a user