diff options
Diffstat (limited to 'src/application/mystic')
-rw-r--r-- | src/application/mystic/forum/Database.php | 5 | ||||
-rw-r--r-- | src/application/mystic/forum/orm/User.php | 3 | ||||
-rw-r--r-- | src/application/mystic/forum/utils/RequestUtils.php | 15 |
3 files changed, 16 insertions, 7 deletions
diff --git a/src/application/mystic/forum/Database.php b/src/application/mystic/forum/Database.php index 7a417be..632b2d6 100644 --- a/src/application/mystic/forum/Database.php +++ b/src/application/mystic/forum/Database.php @@ -319,8 +319,11 @@ class Database { $tableName = self::getTableName($entityClassName); $reflClass = new ReflectionClass($entityClassName); $cols = self::getColumns($reflClass); + $values = ArrayUtils::fill(fn($i) => null, count($cols)); + foreach (self::getColumnValues($entity, $cols) as $i => $value) + $values[$i] = $value; $query = "INSERT INTO $tableName VALUES (" . implode(",", ArrayUtils::fill(fn($i) => "$" . ($i + 1), count($cols))) . ");"; - $result = \pg_query_params($this->connection, $query, self::getColumnValues($entity, $cols)); + $result = \pg_query_params($this->connection, $query, $values); if ($result === false) throw new \RuntimeException("Insert failed: " . \pg_last_error($this->connection)); \pg_free_result($result); diff --git a/src/application/mystic/forum/orm/User.php b/src/application/mystic/forum/orm/User.php index 868f385..a1414c3 100644 --- a/src/application/mystic/forum/orm/User.php +++ b/src/application/mystic/forum/orm/User.php @@ -12,8 +12,7 @@ use mystic\forum\attributes\Unique; class User extends Entity { public const SUPERUSER_ID = "SUPERUSER"; - #[PrimaryKey] - public string $id; + #[PrimaryKey] public string $id; #[Unique] public string $name; public string $displayName; #[Unique] public string $email; diff --git a/src/application/mystic/forum/utils/RequestUtils.php b/src/application/mystic/forum/utils/RequestUtils.php index 796a476..11253aa 100644 --- a/src/application/mystic/forum/utils/RequestUtils.php +++ b/src/application/mystic/forum/utils/RequestUtils.php @@ -23,7 +23,7 @@ final class RequestUtils { public static function ensureRequestMethod(string $method): void { if (!self::isRequestMethod($method)) { - http_response_code(415); + http_response_code(405); Messaging::error("Invalid request method " . self::getRequestMethod()); exit; } @@ -40,9 +40,10 @@ final class RequestUtils { return $fieldValue; } - public static function storeForm(): void { + public static function storeForm(string $formId): void { $_SESSION["lastForm"] = $_POST ?? []; $_SESSION["lastForm_uri"] = $_SERVER["REQUEST_URI"]; + $_SESSION["lastForm_id"] = $formId; } public static function setFormErrorDestination(?string $dest): ?string { @@ -55,7 +56,7 @@ final class RequestUtils { $next ??= self::$formErrorDestination ?? $_SERVER["REQUEST_URI"]; $_SESSION["formError/$formId"] = $message; // store last form submission - self::storeForm(); + self::storeForm($formId); header("Location: $next"); exit; } @@ -66,14 +67,20 @@ final class RequestUtils { return $err; } - public static function getLastForm(string &$lastFormUri): ?array { + public static function getLastForm_legacy(string &$lastFormUri): ?array { $lastFormUri = $_SESSION["lastForm_uri"] ?? ""; return $_SESSION["lastForm"] ?? null; } + public static function getLastForm(string &$lastFormId): ?array { + $lastFormId = $_SESSION["lastForm_id"] ?? ""; + return $_SESSION["lastForm"] ?? null; + } + public static function clearLastForm(): void { unset($_SESSION["lastForm"]); unset($_SESSION["lastForm_uri"]); + unset($_SESSION["lastForm_id"]); } public static function getAuthorizedUser(Database &$db): ?User { |