From e02414eaf85b804ba3e4da38d2104296b14884d4 Mon Sep 17 00:00:00 2001 From: linuxdaemon Date: Thu, 16 May 2024 13:03:22 +0000 Subject: [PATCH] Add command to forcibly write all in-memory data to the DB --- modules/os_save.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 modules/os_save.cpp diff --git a/modules/os_save.cpp b/modules/os_save.cpp new file mode 100644 index 0000000..09206d8 --- /dev/null +++ b/modules/os_save.cpp @@ -0,0 +1,45 @@ +#include "module.h" + +class CommandOSSave : public Command +{ +public: + CommandOSSave(Module *creator) : Command(creator, "operserv/save", 0, 0) + { + this->SetDesc(_("Write all objects to the database.")); + } + + void Execute(CommandSource &source, const std::vector ¶ms) anope_override + { + Log(LOG_ADMIN, source, this); + source.Reply(_("Writing objects.")); + const std::list &items = Serializable::GetItems(); + for (std::list::const_iterator it = items.begin(), it_end = items.end(); it != it_end; it++) + { + (*it)->QueueUpdate(); + } + + source.Reply(_("%d writes queued."), items.size()); + return; + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override + { + this->SendSyntax(source); + source.Reply(" "); + source.Reply(_("Forces all changes to be written immediately.")); + return true; + } +}; + +class OSSave : public Module +{ + CommandOSSave commandossave; + +public: + OSSave(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, THIRD), + commandossave(this) + { + } +}; + +MODULE_INIT(OSSave)