AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
DBUpdater< T > Class Template Reference

#include "DBUpdater.h"

Public Types

using Path = std::filesystem::path
 

Public Member Functions

std::string GetConfigEntry ()
 
std::string GetTableName ()
 
std::string GetBaseFilesDirectory ()
 
bool IsEnabled (uint32 const updateMask)
 
std::string GetDBModuleName ()
 
std::string GetConfigEntry ()
 
std::string GetTableName ()
 
std::string GetBaseFilesDirectory ()
 
bool IsEnabled (uint32 const updateMask)
 
std::string GetDBModuleName ()
 
std::string GetConfigEntry ()
 
std::string GetTableName ()
 
std::string GetBaseFilesDirectory ()
 
bool IsEnabled (uint32 const updateMask)
 
std::string GetDBModuleName ()
 
std::string GetConfigEntry ()
 
std::string GetTableName ()
 
std::string GetBaseFilesDirectory ()
 
bool IsEnabled (uint32 const updateMask)
 
std::string GetDBModuleName ()
 
std::string GetConfigEntry ()
 
std::string GetTableName ()
 
std::string GetBaseFilesDirectory ()
 
bool IsEnabled (uint32 const updateMask)
 
std::string GetDBModuleName ()
 

Static Public Member Functions

static std::string GetConfigEntry ()
 
static std::string GetTableName ()
 
static std::string GetBaseFilesDirectory ()
 
static bool IsEnabled (uint32 const updateMask)
 
static BaseLocation GetBaseLocationType ()
 
static bool Create (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)
 
static std::string GetDBModuleName ()
 

Static Private Member Functions

static QueryResult Retrieve (DatabaseWorkerPool< T > &pool, std::string const &query)
 
static void Apply (DatabaseWorkerPool< T > &pool, std::string const &query)
 
static void ApplyFile (DatabaseWorkerPool< T > &pool, Path const &path)
 
static void ApplyFile (DatabaseWorkerPool< T > &pool, std::string const &host, std::string const &user, std::string const &password, std::string const &port_or_socket, std::string const &database, std::string const &ssl, Path const &path)
 

Detailed Description

template<class T>
class DBUpdater< T >

Member Typedef Documentation

◆ Path

template<class T >
using DBUpdater< T >::Path = std::filesystem::path

Member Function Documentation

◆ Apply()

template<class T >
void DBUpdater< T >::Apply ( DatabaseWorkerPool< T > &  pool,
std::string const &  query 
)
staticprivate
494{
495 pool.DirectExecute(query.c_str());
496}
void DirectExecute(std::string_view sql)
Definition: DatabaseWorkerPool.cpp:496

References DatabaseWorkerPool< T >::DirectExecute().

Referenced by DBUpdater< T >::Update().

◆ ApplyFile() [1/2]

template<class T >
void DBUpdater< T >::ApplyFile ( DatabaseWorkerPool< T > &  pool,
Path const &  path 
)
staticprivate
500{
503}
MySQLConnectionInfo const * GetConnectionInfo() const
Definition: DatabaseWorkerPool.h:57
std::string host
Definition: MySQLConnection.h:50
std::string port_or_socket
Definition: MySQLConnection.h:51
std::string user
Definition: MySQLConnection.h:47
std::string database
Definition: MySQLConnection.h:49
std::string ssl
Definition: MySQLConnection.h:52
std::string password
Definition: MySQLConnection.h:48
static void ApplyFile(DatabaseWorkerPool< T > &pool, Path const &path)
Definition: DBUpdater.cpp:499

References DBUpdater< T >::ApplyFile(), MySQLConnectionInfo::database, DatabaseWorkerPool< T >::GetConnectionInfo(), MySQLConnectionInfo::host, MySQLConnectionInfo::password, MySQLConnectionInfo::port_or_socket, MySQLConnectionInfo::ssl, and MySQLConnectionInfo::user.

Referenced by DBUpdater< T >::ApplyFile(), DBUpdater< T >::Create(), and DBUpdater< T >::Update().

◆ ApplyFile() [2/2]

template<class T >
void DBUpdater< T >::ApplyFile ( DatabaseWorkerPool< T > &  pool,
std::string const &  host,
std::string const &  user,
std::string const &  password,
std::string const &  port_or_socket,
std::string const &  database,
std::string const &  ssl,
Path const &  path 
)
staticprivate
508{
509 std::string configTempDir = sConfigMgr->GetOption<std::string>("TempDir", "");
510
511 auto tempDir = configTempDir.empty() ? std::filesystem::temp_directory_path().string() : configTempDir;
512
513 tempDir = Acore::String::AddSuffixIfNotExists(tempDir, std::filesystem::path::preferred_separator);
514
515 std::string confFileName = "mysql_ac.conf";
516
517 std::ofstream outfile (tempDir + confFileName);
518
519 outfile << "[client]\npassword = \"" << password << '"' << std::endl;
520
521 outfile.close();
522
523 std::vector<std::string> args;
524 args.reserve(9);
525
526 args.emplace_back("--defaults-extra-file="+tempDir + confFileName+"");
527
528 // CLI Client connection info
529 args.emplace_back("-h" + host);
530 args.emplace_back("-u" + user);
531
532 // Check if we want to connect through ip or socket (Unix only)
533#ifdef _WIN32
534
535 if (host == ".")
536 args.emplace_back("--protocol=PIPE");
537 else
538 args.emplace_back("-P" + port_or_socket);
539
540#else
541
542 if (!std::isdigit(port_or_socket[0]))
543 {
544 // We can't check if host == "." here, because it is named localhost if socket option is enabled
545 args.emplace_back("-P0");
546 args.emplace_back("--protocol=SOCKET");
547 args.emplace_back("-S" + port_or_socket);
548 }
549 else
550 // generic case
551 args.emplace_back("-P" + port_or_socket);
552
553#endif
554
555 // Set the default charset to utf8
556 args.emplace_back("--default-character-set=utf8");
557
558 // Set max allowed packet to 1 GB
559 args.emplace_back("--max-allowed-packet=1GB");
560
561#if !defined(MARIADB_VERSION_ID) && MYSQL_VERSION_ID >= 80000
562
563 if (ssl == "ssl")
564 args.emplace_back("--ssl-mode=REQUIRED");
565
566#else
567
568 if (ssl == "ssl")
569 args.emplace_back("--ssl");
570
571#endif
572
573 // Execute sql file
574 args.emplace_back("-e");
575 args.emplace_back(Acore::StringFormat("BEGIN; SOURCE %s; COMMIT;", path.generic_string().c_str()));
576
577 // Database
578 if (!database.empty())
579 args.emplace_back(database);
580
581 // Invokes a mysql process which doesn't leak credentials to logs
583 "sql.updates", "", true);
584
585 if (ret != EXIT_SUCCESS)
586 {
587 LOG_FATAL("sql.updates", "Applying of file \'{}\' to database \'{}\' failed!" \
588 " If you are a user, please pull the latest revision from the repository. "
589 "Also make sure you have not applied any of the databases with your sql client. "
590 "You cannot use auto-update system and import sql files from AzerothCore repository with your sql client. "
591 "If you are a developer, please fix your sql query.",
592 path.generic_string(), pool.GetConnectionInfo()->database);
593
594 throw UpdateException("update failed");
595 }
596}
#define sConfigMgr
Definition: Config.h:95
#define LOG_FATAL(filterType__,...)
Definition: Log.h:155
std::string StringFormat(Format &&fmt, Args &&... args)
Default AC string format function.
Definition: StringFormat.h:29
int StartProcess(std::string const &executable, std::vector< std::string > const &args, std::string const &logger, std::string input_file, bool secure)
Definition: StartProcess.cpp:146
AC_COMMON_API std::string AddSuffixIfNotExists(std::string str, const char suffix)
Util function to add a suffix char. Can be used to add a slash at the end of a path.
Definition: StringFormat.cpp:74
Definition: DBUpdater.h:38
static std::string GetCorrectedMySQLExecutable()
Definition: DBUpdater.cpp:32

References Acore::String::AddSuffixIfNotExists(), MySQLConnectionInfo::database, DatabaseWorkerPool< T >::GetConnectionInfo(), DBUpdaterUtil::GetCorrectedMySQLExecutable(), LOG_FATAL, sConfigMgr, Acore::StartProcess(), and Acore::StringFormat().

◆ Create()

template<class T >
bool DBUpdater< T >::Create ( DatabaseWorkerPool< T > &  pool)
static
236{
237 LOG_WARN("sql.updates", "Database \"{}\" does not exist", pool.GetConnectionInfo()->database);
238
239 const char* disableInteractive = std::getenv("AC_DISABLE_INTERACTIVE");
240
241 if (!sConfigMgr->isDryRun() && (disableInteractive == nullptr || std::strcmp(disableInteractive, "1") != 0))
242 {
243 std::cout << "Do you want to create it? [yes (default) / no]:" << std::endl;
244 std::string answer;
245 std::getline(std::cin, answer);
246 if (!answer.empty() && !(answer.substr(0, 1) == "y"))
247 return false;
248 }
249
250 LOG_INFO("sql.updates", "Creating database \"{}\"...", pool.GetConnectionInfo()->database);
251
252 // Path of temp file
253 static Path const temp("create_table.sql");
254
255 // Create temporary query to use external MySQL CLi
256 std::ofstream file(temp.generic_string());
257 if (!file.is_open())
258 {
259 LOG_FATAL("sql.updates", "Failed to create temporary query file \"{}\"!", temp.generic_string());
260 return false;
261 }
262
263 file << "CREATE DATABASE `" << pool.GetConnectionInfo()->database << "` DEFAULT CHARACTER SET UTF8MB4 COLLATE utf8mb4_general_ci;\n\n";
264 file.close();
265
266 try
267 {
269 pool.GetConnectionInfo()->port_or_socket, "", pool.GetConnectionInfo()->ssl, temp);
270 }
271 catch (UpdateException&)
272 {
273 LOG_FATAL("sql.updates", "Failed to create database {}! Does the user (named in *.conf) have `CREATE`, `ALTER`, `DROP`, `INSERT` and `DELETE` privileges on the MySQL server?", pool.GetConnectionInfo()->database);
274 std::filesystem::remove(temp);
275 return false;
276 }
277
278 LOG_INFO("sql.updates", "Done.");
279 LOG_INFO("sql.updates", " ");
280 std::filesystem::remove(temp);
281 return true;
282}
#define LOG_INFO(filterType__,...)
Definition: Log.h:167
#define LOG_WARN(filterType__,...)
Definition: Log.h:163
std::filesystem::path Path
Definition: DBUpdater.h:70

References DBUpdater< T >::ApplyFile(), MySQLConnectionInfo::database, DatabaseWorkerPool< T >::GetConnectionInfo(), MySQLConnectionInfo::host, LOG_FATAL, LOG_INFO, LOG_WARN, MySQLConnectionInfo::password, MySQLConnectionInfo::port_or_socket, sConfigMgr, MySQLConnectionInfo::ssl, and MySQLConnectionInfo::user.

◆ GetBaseFilesDirectory() [1/6]

std::string DBUpdater< LoginDatabaseConnection >::GetBaseFilesDirectory ( )
82{
83 return BuiltInConfig::GetSourceDirectory() + "/data/sql/base/db_auth/";
84}
AC_COMMON_API std::string GetSourceDirectory()
Definition: BuiltInConfig.cpp:42

References BuiltInConfig::GetSourceDirectory().

◆ GetBaseFilesDirectory() [2/6]

std::string DBUpdater< WorldDatabaseConnection >::GetBaseFilesDirectory ( )
114{
115 return BuiltInConfig::GetSourceDirectory() + "/data/sql/base/db_world/";
116}

References BuiltInConfig::GetSourceDirectory().

◆ GetBaseFilesDirectory() [3/6]

std::string DBUpdater< CharacterDatabaseConnection >::GetBaseFilesDirectory ( )
146{
147 return BuiltInConfig::GetSourceDirectory() + "/data/sql/base/db_characters/";
148}

References BuiltInConfig::GetSourceDirectory().

◆ GetBaseFilesDirectory() [4/6]

std::string DBUpdater< DBCDatabaseConnection >::GetBaseFilesDirectory ( )
178{
179 return BuiltInConfig::GetSourceDirectory() + "/data/sql/base/db_dbc/";
180}

References BuiltInConfig::GetSourceDirectory().

◆ GetBaseFilesDirectory() [5/6]

std::string DBUpdater< ModuleDatabaseConnection >::GetBaseFilesDirectory ( )
210{
211 return BuiltInConfig::GetSourceDirectory() + "/data/sql/base/db_module/";
212}

References BuiltInConfig::GetSourceDirectory().

◆ GetBaseFilesDirectory() [6/6]

template<class T >
static std::string DBUpdater< T >::GetBaseFilesDirectory ( )
static

◆ GetBaseLocationType()

template<class T >
BaseLocation DBUpdater< T >::GetBaseLocationType
static
230{
231 return LOCATION_REPOSITORY;
232}
@ LOCATION_REPOSITORY
Definition: DBUpdater.h:51

References LOCATION_REPOSITORY.

◆ GetConfigEntry() [1/6]

std::string DBUpdater< LoginDatabaseConnection >::GetConfigEntry ( )
70{
71 return "Updates.Auth";
72}

◆ GetConfigEntry() [2/6]

std::string DBUpdater< WorldDatabaseConnection >::GetConfigEntry ( )
102{
103 return "Updates.World";
104}

◆ GetConfigEntry() [3/6]

std::string DBUpdater< CharacterDatabaseConnection >::GetConfigEntry ( )
134{
135 return "Updates.Character";
136}

◆ GetConfigEntry() [4/6]

std::string DBUpdater< DBCDatabaseConnection >::GetConfigEntry ( )
166{
167 return "Updates.DBC";
168}

◆ GetConfigEntry() [5/6]

std::string DBUpdater< ModuleDatabaseConnection >::GetConfigEntry ( )
198{
199 return "Updates.Module";
200}

◆ GetConfigEntry() [6/6]

template<class T >
static std::string DBUpdater< T >::GetConfigEntry ( )
inlinestatic

◆ GetDBModuleName() [1/6]

std::string DBUpdater< LoginDatabaseConnection >::GetDBModuleName ( )
95{
96 return "db-auth";
97}

◆ GetDBModuleName() [2/6]

std::string DBUpdater< WorldDatabaseConnection >::GetDBModuleName ( )
127{
128 return "db-world";
129}

◆ GetDBModuleName() [3/6]

std::string DBUpdater< CharacterDatabaseConnection >::GetDBModuleName ( )
159{
160 return "db-characters";
161}

◆ GetDBModuleName() [4/6]

std::string DBUpdater< DBCDatabaseConnection >::GetDBModuleName ( )
191{
192 return "db-dbc";
193}

◆ GetDBModuleName() [5/6]

std::string DBUpdater< ModuleDatabaseConnection >::GetDBModuleName ( )
223{
224 return "db-module";
225}

◆ GetDBModuleName() [6/6]

template<class T >
static std::string DBUpdater< T >::GetDBModuleName ( )
static

Referenced by DBUpdater< T >::Update().

◆ GetTableName() [1/6]

std::string DBUpdater< LoginDatabaseConnection >::GetTableName ( )
76{
77 return "Auth";
78}

◆ GetTableName() [2/6]

std::string DBUpdater< WorldDatabaseConnection >::GetTableName ( )
108{
109 return "World";
110}

◆ GetTableName() [3/6]

std::string DBUpdater< CharacterDatabaseConnection >::GetTableName ( )
140{
141 return "Character";
142}

◆ GetTableName() [4/6]

std::string DBUpdater< DBCDatabaseConnection >::GetTableName ( )
172{
173 return "DBC";
174}

◆ GetTableName() [5/6]

std::string DBUpdater< ModuleDatabaseConnection >::GetTableName ( )
204{
205 return "Module";
206}

◆ GetTableName() [6/6]

template<class T >
static std::string DBUpdater< T >::GetTableName ( )
inlinestatic

◆ IsEnabled() [1/6]

bool DBUpdater< LoginDatabaseConnection >::IsEnabled ( uint32 const  updateMask)
88{
89 // This way silences warnings under msvc
90 return (updateMask & DatabaseLoader::DATABASE_LOGIN) ? true : false;
91}
@ DATABASE_LOGIN
Definition: DatabaseLoader.h:48

References DatabaseLoader::DATABASE_LOGIN.

◆ IsEnabled() [2/6]

bool DBUpdater< WorldDatabaseConnection >::IsEnabled ( uint32 const  updateMask)
120{
121 // This way silences warnings under msvc
122 return (updateMask & DatabaseLoader::DATABASE_WORLD) ? true : false;
123}
@ DATABASE_WORLD
Definition: DatabaseLoader.h:50

References DatabaseLoader::DATABASE_WORLD.

◆ IsEnabled() [3/6]

bool DBUpdater< CharacterDatabaseConnection >::IsEnabled ( uint32 const  updateMask)
152{
153 // This way silences warnings under msvc
154 return (updateMask & DatabaseLoader::DATABASE_CHARACTER) ? true : false;
155}
@ DATABASE_CHARACTER
Definition: DatabaseLoader.h:49

References DatabaseLoader::DATABASE_CHARACTER.

◆ IsEnabled() [4/6]

bool DBUpdater< DBCDatabaseConnection >::IsEnabled ( uint32 const  updateMask)
184{
185 // This way silences warnings under msvc
186 return (updateMask & DatabaseLoader::DATABASE_DBC) ? true : false;
187}
@ DATABASE_DBC
Definition: DatabaseLoader.h:51

References DatabaseLoader::DATABASE_DBC.

◆ IsEnabled() [5/6]

bool DBUpdater< ModuleDatabaseConnection >::IsEnabled ( uint32 const  updateMask)
216{
217 // This way silences warnings under msvc
218 return (updateMask & DatabaseLoader::DATABASE_MODULE) ? true : false;
219}
@ DATABASE_MODULE
Definition: DatabaseLoader.h:52

References DatabaseLoader::DATABASE_MODULE.

◆ IsEnabled() [6/6]

template<class T >
static bool DBUpdater< T >::IsEnabled ( uint32 const  updateMask)
static

◆ Populate()

template<class T >
bool DBUpdater< T >::Populate ( DatabaseWorkerPool< T > &  pool)
static
422{
423 {
424 QueryResult const result = Retrieve(pool, "SHOW TABLES");
425 if (result && (result->GetRowCount() > 0))
426 return true;
427 }
428
430 return false;
431
432 LOG_INFO("sql.updates", "Database {} is empty, auto populating it...", DBUpdater<T>::GetTableName());
433
434 std::string const DirPathStr = DBUpdater<T>::GetBaseFilesDirectory();
435
436 Path const DirPath(DirPathStr);
437 if (!std::filesystem::is_directory(DirPath))
438 {
439 LOG_ERROR("sql.updates", ">> Directory \"{}\" not exist", DirPath.generic_string());
440 return false;
441 }
442
443 if (DirPath.empty())
444 {
445 LOG_ERROR("sql.updates", ">> Directory \"{}\" is empty", DirPath.generic_string());
446 return false;
447 }
448
449 std::filesystem::directory_iterator const DirItr;
450 uint32 FilesCount = 0;
451
452 for (std::filesystem::directory_iterator itr(DirPath); itr != DirItr; ++itr)
453 {
454 if (itr->path().extension() == ".sql")
455 FilesCount++;
456 }
457
458 if (!FilesCount)
459 {
460 LOG_ERROR("sql.updates", ">> In directory \"{}\" not exist '*.sql' files", DirPath.generic_string());
461 return false;
462 }
463
464 for (std::filesystem::directory_iterator itr(DirPath); itr != DirItr; ++itr)
465 {
466 if (itr->path().extension() != ".sql")
467 continue;
468
469 LOG_INFO("sql.updates", ">> Applying \'{}\'...", itr->path().filename().generic_string());
470
471 try
472 {
473 ApplyFile(pool, itr->path());
474 }
475 catch (UpdateException&)
476 {
477 return false;
478 }
479 }
480
481 LOG_INFO("sql.updates", ">> Done!");
482 LOG_INFO("sql.updates", " ");
483 return true;
484}
std::uint32_t uint32
Definition: Define.h:108
#define LOG_ERROR(filterType__,...)
Definition: Log.h:159
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:28
static bool CheckExecutable()
Definition: DBUpdater.cpp:40
Definition: DBUpdater.h:68
static QueryResult Retrieve(DatabaseWorkerPool< T > &pool, std::string const &query)
Definition: DBUpdater.cpp:487
static std::string GetBaseFilesDirectory()

References DBUpdaterUtil::CheckExecutable(), DBUpdater< T >::GetBaseFilesDirectory(), LOG_ERROR, and LOG_INFO.

◆ Retrieve()

template<class T >
QueryResult DBUpdater< T >::Retrieve ( DatabaseWorkerPool< T > &  pool,
std::string const &  query 
)
staticprivate
488{
489 return pool.Query(query.c_str());
490}
QueryResult Query(std::string_view sql)
Definition: DatabaseWorkerPool.cpp:190

References DatabaseWorkerPool< T >::Query().

Referenced by DBUpdater< T >::Update().

◆ Update() [1/2]

template<class T >
bool DBUpdater< T >::Update ( DatabaseWorkerPool< T > &  pool,
std::string_view  modulesList = {} 
)
static
286{
288 return false;
289
290 LOG_INFO("sql.updates", "Updating {} database...", DBUpdater<T>::GetTableName());
291
292 Path const sourceDirectory(BuiltInConfig::GetSourceDirectory());
293
294 if (!is_directory(sourceDirectory))
295 {
296 LOG_ERROR("sql.updates", "DBUpdater: The given source directory {} does not exist, change the path to the directory where your sql directory exists (for example c:\\source\\azerothcore). Shutting down.",
297 sourceDirectory.generic_string());
298 return false;
299 }
300
301 auto CheckUpdateTable = [&](std::string const& tableName)
302 {
303 auto checkTable = DBUpdater<T>::Retrieve(pool, Acore::StringFormatFmt("SHOW TABLES LIKE '{}'", tableName));
304 if (!checkTable)
305 {
306 LOG_WARN("sql.updates", "> Table '{}' not exist! Try add based table", tableName);
307
308 Path const temp(GetBaseFilesDirectory() + tableName + ".sql");
309
310 try
311 {
312 DBUpdater<T>::ApplyFile(pool, temp);
313 }
314 catch (UpdateException&)
315 {
316 LOG_FATAL("sql.updates", "Failed apply file to database {}! Does the user (named in *.conf) have `INSERT` and `DELETE` privileges on the MySQL server?", pool.GetConnectionInfo()->database);
317 return false;
318 }
319
320 return true;
321 }
322
323 return true;
324 };
325
326 if (!CheckUpdateTable("updates") || !CheckUpdateTable("updates_include"))
327 return false;
328
329 UpdateFetcher updateFetcher(sourceDirectory, [&](std::string const & query) { DBUpdater<T>::Apply(pool, query); },
330 [&](Path const & file) { DBUpdater<T>::ApplyFile(pool, file); },
331 [&](std::string const & query) -> QueryResult { return DBUpdater<T>::Retrieve(pool, query); }, DBUpdater<T>::GetDBModuleName(), modulesList);
332
333 UpdateResult result;
334 try
335 {
336 result = updateFetcher.Update(
337 sConfigMgr->GetOption<bool>("Updates.Redundancy", true),
338 sConfigMgr->GetOption<bool>("Updates.AllowRehash", true),
339 sConfigMgr->GetOption<bool>("Updates.ArchivedRedundancy", false),
340 sConfigMgr->GetOption<int32>("Updates.CleanDeadRefMaxCount", 3));
341 }
342 catch (UpdateException&)
343 {
344 return false;
345 }
346
347 std::string const info = Acore::StringFormatFmt("Containing {} new and {} archived updates.", result.recent, result.archived);
348
349 if (!result.updated)
350 LOG_INFO("sql.updates", ">> {} database is up-to-date! {}", DBUpdater<T>::GetTableName(), info);
351 else
352 LOG_INFO("sql.updates", ">> Applied {} {}. {}", result.updated, result.updated == 1 ? "query" : "queries", info);
353
354 LOG_INFO("sql.updates", " ");
355
356 return true;
357}
std::int32_t int32
Definition: Define.h:104
std::string StringFormatFmt(std::string_view fmt, Args &&... args)
Definition: StringFormat.h:44
static void Apply(DatabaseWorkerPool< T > &pool, std::string const &query)
Definition: DBUpdater.cpp:493
static std::string GetDBModuleName()
Definition: UpdateFetcher.h:30
Definition: UpdateFetcher.h:43

References DBUpdater< T >::Apply(), DBUpdater< T >::ApplyFile(), DBUpdaterUtil::CheckExecutable(), MySQLConnectionInfo::database, DatabaseWorkerPool< T >::GetConnectionInfo(), DBUpdater< T >::GetDBModuleName(), BuiltInConfig::GetSourceDirectory(), LOG_ERROR, LOG_FATAL, LOG_INFO, LOG_WARN, DBUpdater< T >::Retrieve(), sConfigMgr, and Acore::StringFormatFmt().

◆ Update() [2/2]

template<class T >
bool DBUpdater< T >::Update ( DatabaseWorkerPool< T > &  pool,
std::vector< std::string > const *  setDirectories 
)
static
361{
363 {
364 return false;
365 }
366
367 Path const sourceDirectory(BuiltInConfig::GetSourceDirectory());
368 if (!is_directory(sourceDirectory))
369 {
370 return false;
371 }
372
373 auto CheckUpdateTable = [&](std::string const& tableName)
374 {
375 auto checkTable = DBUpdater<T>::Retrieve(pool, Acore::StringFormatFmt("SHOW TABLES LIKE '{}'", tableName));
376 if (!checkTable)
377 {
378 Path const temp(GetBaseFilesDirectory() + tableName + ".sql");
379 try
380 {
381 DBUpdater<T>::ApplyFile(pool, temp);
382 }
383 catch (UpdateException&)
384 {
385 return false;
386 }
387
388 return true;
389 }
390
391 return true;
392 };
393
394 if (!CheckUpdateTable("updates") || !CheckUpdateTable("updates_include"))
395 {
396 return false;
397 }
398
399 UpdateFetcher updateFetcher(sourceDirectory, [&](std::string const & query) { DBUpdater<T>::Apply(pool, query); },
400 [&](Path const & file) { DBUpdater<T>::ApplyFile(pool, file); },
401 [&](std::string const & query) -> QueryResult { return DBUpdater<T>::Retrieve(pool, query); }, DBUpdater<T>::GetDBModuleName(), setDirectories);
402
403 UpdateResult result;
404 try
405 {
406 result = updateFetcher.Update(
407 sConfigMgr->GetOption<bool>("Updates.Redundancy", true),
408 sConfigMgr->GetOption<bool>("Updates.AllowRehash", true),
409 sConfigMgr->GetOption<bool>("Updates.ArchivedRedundancy", false),
410 sConfigMgr->GetOption<int32>("Updates.CleanDeadRefMaxCount", 3));
411 }
412 catch (UpdateException&)
413 {
414 return false;
415 }
416
417 return true;
418}

References DBUpdater< T >::Apply(), DBUpdater< T >::ApplyFile(), DBUpdaterUtil::CheckExecutable(), DBUpdater< T >::GetDBModuleName(), BuiltInConfig::GetSourceDirectory(), DBUpdater< T >::Retrieve(), sConfigMgr, and Acore::StringFormatFmt().