Initialize villages, and also call the relevant methods during migration.

This commit is contained in:
Relintai 2021-11-14 13:59:02 +01:00
parent be2a4a93f9
commit 165d0d5d70
5 changed files with 29 additions and 3 deletions

View File

@ -17,6 +17,8 @@
#include "modules/users/user.h" #include "modules/users/user.h"
#include "modules/users/user_controller.h" #include "modules/users/user_controller.h"
#include "village/village_initializer.h"
bool MourneApplication::is_logged_in(Request *request) { bool MourneApplication::is_logged_in(Request *request) {
if (!request->session) { if (!request->session) {
return false; return false;
@ -233,6 +235,11 @@ void MourneApplication::setup_middleware() {
} }
void MourneApplication::migrate() { void MourneApplication::migrate() {
VillageController::get_singleton()->migrate();
}
void MourneApplication::add_default_data() {
VillageController::get_singleton()->add_default_data();
} }
void MourneApplication::compile_menu() { void MourneApplication::compile_menu() {
@ -263,10 +270,14 @@ void MourneApplication::compile_menu() {
MourneApplication::MourneApplication() : MourneApplication::MourneApplication() :
DWebApplication() { DWebApplication() {
VillageInitializer::allocate_all();
compile_menu(); compile_menu();
} }
MourneApplication::~MourneApplication() { MourneApplication::~MourneApplication() {
VillageInitializer::free_all();
} }
std::string MourneApplication::menu_head = ""; std::string MourneApplication::menu_head = "";

View File

@ -50,6 +50,7 @@ public:
virtual void setup_middleware(); virtual void setup_middleware();
virtual void migrate(); virtual void migrate();
virtual void add_default_data();
void compile_menu(); void compile_menu();

View File

@ -7,10 +7,18 @@
#include "core/http/request.h" #include "core/http/request.h"
#include "core/http/session_manager.h" #include "core/http/session_manager.h"
#include "village_model.h"
void VillageController::handle_request_default(Request *request) { void VillageController::handle_request_default(Request *request) {
} }
void VillageController::migrate() {
VillageModel::get_singleton()->migrate();
}
void VillageController::add_default_data() {
VillageModel::get_singleton()->add_default_data();
}
VillageController *VillageController::get_singleton() { VillageController *VillageController::get_singleton() {
return _self; return _self;
} }

View File

@ -15,6 +15,9 @@ class VillageController : public Object {
RCPP_OBJECT(VillageController, Object); RCPP_OBJECT(VillageController, Object);
public: public:
void migrate();
virtual void add_default_data();
virtual void handle_request_default(Request *request); virtual void handle_request_default(Request *request);
static VillageController *get_singleton(); static VillageController *get_singleton();

View File

@ -14,8 +14,6 @@
#include "core/http/session_manager.h" #include "core/http/session_manager.h"
#define MAIN_CLASS MourneApplication
#include "modules/drogon/web_application.h" #include "modules/drogon/web_application.h"
//Backends //Backends
@ -67,7 +65,7 @@ int main(int argc, char **argv, char **envp) {
create_databases(); create_databases();
DWebApplication *app = new MAIN_CLASS(); MourneApplication *app = new MourneApplication();
app->load_settings(); app->load_settings();
app->setup_routes(); app->setup_routes();
@ -95,6 +93,11 @@ int main(int argc, char **argv, char **envp) {
} }
app->migrate(); app->migrate();
if (Platform::get_singleton()->arg_parser.has_arg("-d")) {
printf("Adding data.\n");
app->add_default_data();
}
} }
delete app; delete app;