public function loadInstances() { $newInstances = $this->getNewInstancesInDir("./core"); foreach ($newInstances as $name => $className) { Registry::setInstance($name, new $className()); } $this->loadCoreModules(); $this->loadUserModules(); $this->logger->log('DEBUG', "Inject dependencies for all instances"); foreach (Registry::getAllInstances() as $instance) { Registry::injectDependencies($instance); } }
/** * @HandlesCommand("reloadinstance") * @Matches("/^reloadinstance all$/i") */ public function reloadinstanceAllCommand($message, $channel, $sender, $sendto, $args) { $instances = Registry::getAllInstances(); $count = count($instances); $blob = ''; foreach ($instances as $name => $instance) { $blob .= $name . ' (' . get_class($instance) . ")\n"; Registry::importChanges($instance); Registry::injectDependencies($instance); } $msg = $this->text->make_blob("All instances have been reloaded ({$count})", $blob); $sendto->reply($msg); }
public function init(&$vars) { $this->vars = $vars; // Set startup time $this->vars["startup"] = time(); $this->logger->log('DEBUG', 'Initializing bot'); // Create core tables if not exists $this->db->exec("CREATE TABLE IF NOT EXISTS cmdcfg_<myname> (`module` VARCHAR(50), `cmdevent` VARCHAR(6), `type` VARCHAR(18), `file` TEXT, `cmd` VARCHAR(50), `admin` VARCHAR(10), `description` VARCHAR(75) DEFAULT 'none', `verify` INT DEFAULT '0', `status` INT DEFAULT '0', `dependson` VARCHAR(25) DEFAULT 'none', `help` VARCHAR(255))"); $this->db->exec("CREATE TABLE IF NOT EXISTS eventcfg_<myname> (`module` VARCHAR(50), `type` VARCHAR(18), `file` VARCHAR(255), `description` VARCHAR(75) DEFAULT 'none', `verify` INT DEFAULT '0', `status` INT DEFAULT '0', `help` VARCHAR(255))"); $this->db->exec("CREATE TABLE IF NOT EXISTS settings_<myname> (`name` VARCHAR(50) NOT NULL, `module` VARCHAR(50), `type` VARCHAR(30), `mode` VARCHAR(10), `value` VARCHAR(255) DEFAULT '0', `options` VARCHAR(255) DEFAULT '0', `intoptions` VARCHAR(50) DEFAULT '0', `description` VARCHAR(75), `source` VARCHAR(5), `admin` VARCHAR(25), `verify` INT DEFAULT '0', `help` VARCHAR(255))"); $this->db->exec("CREATE TABLE IF NOT EXISTS hlpcfg_<myname> (`name` VARCHAR(25) NOT NULL, `module` VARCHAR(50), `file` VARCHAR(255), `description` VARCHAR(75), `admin` VARCHAR(10), `verify` INT DEFAULT '0')"); $this->db->exec("CREATE TABLE IF NOT EXISTS cmd_alias_<myname> (`cmd` VARCHAR(255) NOT NULL, `module` VARCHAR(50), `alias` VARCHAR(25) NOT NULL, `status` INT DEFAULT '0')"); // Prepare command/event settings table $this->db->exec("UPDATE cmdcfg_<myname> SET `verify` = 0"); $this->db->exec("UPDATE eventcfg_<myname> SET `verify` = 0"); $this->db->exec("UPDATE settings_<myname> SET `verify` = 0"); $this->db->exec("UPDATE hlpcfg_<myname> SET `verify` = 0"); $this->db->exec("UPDATE eventcfg_<myname> SET `status` = 1 WHERE `type` = 'setup'"); // To reduce queries load core items into memory $data = $this->db->query("SELECT * FROM cmdcfg_<myname> WHERE `cmdevent` = 'cmd'"); foreach ($data as $row) { $this->existing_commands[$row->type][$row->cmd] = true; } $data = $this->db->query("SELECT * FROM cmdcfg_<myname> WHERE `cmdevent` = 'subcmd'"); foreach ($data as $row) { $this->existing_subcmds[$row->type][$row->cmd] = true; } $data = $this->db->query("SELECT * FROM eventcfg_<myname>"); foreach ($data as $row) { $this->existing_events[$row->type][$row->file] = true; } $data = $this->db->query("SELECT * FROM hlpcfg_<myname>"); foreach ($data as $row) { $this->existing_helps[$row->name] = true; } $data = $this->db->query("SELECT * FROM settings_<myname>"); foreach ($data as $row) { $this->existing_settings[$row->name] = true; } $data = $this->db->query("SELECT * FROM cmd_alias_<myname>"); foreach ($data as $row) { $this->existing_cmd_aliases[$row->alias] = true; } $this->db->beginTransaction(); foreach (Registry::getAllInstances() as $name => $instance) { if (isset($instance->moduleName)) { $this->registerInstance($name, $instance); } } $this->db->commit(); //remove arrays unset($this->existing_commands); unset($this->existing_events); unset($this->existing_subcmds); unset($this->existing_settings); unset($this->existing_helps); unset($this->existing_cmd_aliases); //Delete old entrys in the DB $this->db->exec("DELETE FROM cmdcfg_<myname> WHERE `verify` = 0"); $this->db->exec("DELETE FROM eventcfg_<myname> WHERE `verify` = 0"); $this->db->exec("DELETE FROM settings_<myname> WHERE `verify` = 0"); $this->db->exec("DELETE FROM hlpcfg_<myname> WHERE `verify` = 0"); $this->commandManager->loadCommands(); $this->subcommandManager->loadSubcommands(); $this->commandAlias->load(); $this->eventManager->loadEvents(); }