From c084016b5b9e3ce734caabf0e2bd677979930005 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 10 Feb 2024 00:23:30 +0000 Subject: [PATCH] [setup] have ConfigSaveEvent carry its own params --- ext/setup/main.php | 16 +++++++++++----- ext/user_config/main.php | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ext/setup/main.php b/ext/setup/main.php index 2cbb9a3b..76b15ed9 100644 --- a/ext/setup/main.php +++ b/ext/setup/main.php @@ -17,11 +17,17 @@ require_once "config.php"; class ConfigSaveEvent extends Event { public Config $config; + /** @var array $values */ + public array $values; - public function __construct(Config $config) + /** + * @param array $values + */ + public function __construct(Config $config, array $values) { parent::__construct(); $this->config = $config; + $this->values = $values; } } @@ -340,7 +346,7 @@ class Setup extends Extension send_event(new SetupBuildingEvent($panel)); $this->theme->display_page($page, $panel); } elseif ($event->get_arg(0) == "save" && $user->check_auth_token()) { - send_event(new ConfigSaveEvent($config)); + send_event(new ConfigSaveEvent($config, $event->POST)); $config->save(); $page->flash("Config saved"); $page->set_mode(PageMode::REDIRECT); @@ -384,11 +390,11 @@ class Setup extends Extension public function onConfigSave(ConfigSaveEvent $event): void { $config = $event->config; - foreach ($_POST as $_name => $junk) { + foreach ($event->values as $_name => $junk) { if (substr($_name, 0, 6) == "_type_") { $name = substr($_name, 6); - $type = $_POST["_type_$name"]; - $value = isset($_POST["_config_$name"]) ? $_POST["_config_$name"] : null; + $type = $event->values["_type_$name"]; + $value = isset($event->values["_config_$name"]) ? $event->values["_config_$name"] : null; switch ($type) { case "string": $config->set_string($name, $value); diff --git a/ext/user_config/main.php b/ext/user_config/main.php index e92dc1ac..06e2df20 100644 --- a/ext/user_config/main.php +++ b/ext/user_config/main.php @@ -160,7 +160,7 @@ class UserConfig extends Extension } $target_config = UserConfig::get_for_user($duser->id); - send_event(new ConfigSaveEvent($target_config)); + send_event(new ConfigSaveEvent($target_config, $event->POST)); $target_config->save(); $page->flash("Config saved"); $page->set_mode(PageMode::REDIRECT);