Skip to content

Commit

Permalink
Merge pull request #23 from snoonetIRC/linuxdaemon/os_save
Browse files Browse the repository at this point in the history
Add command to forcibly write all in-memory data to the DB
  • Loading branch information
linuxdaemon authored May 16, 2024
2 parents 2a2ef8c + e02414e commit 57f271f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions modules/os_save.cpp
Original file line number Diff line number Diff line change
@@ -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<Anope::string> &params) anope_override
{
Log(LOG_ADMIN, source, this);
source.Reply(_("Writing objects."));
const std::list<Serializable *> &items = Serializable::GetItems();
for (std::list<Serializable *>::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)

0 comments on commit 57f271f

Please sign in to comment.