diff options
author | Jonas Kohl | 2024-09-19 16:32:18 +0200 |
---|---|---|
committer | Jonas Kohl | 2024-09-19 16:32:18 +0200 |
commit | 4a6e12bf1fc7837699f780674c33cba5f2b1223c (patch) | |
tree | 0636da538f47b285774525418c1730789c650607 /src/application/mystic/forum | |
parent | 5c707597ba936b1b82ee9a1cf546e720d1a490bd (diff) |
Add log messages
Diffstat (limited to 'src/application/mystic/forum')
-rw-r--r-- | src/application/mystic/forum/Database.php | 9 | ||||
-rw-r--r-- | src/application/mystic/forum/orm/TopicLogMessage.php | 23 |
2 files changed, 31 insertions, 1 deletions
diff --git a/src/application/mystic/forum/Database.php b/src/application/mystic/forum/Database.php index 8ebc36b..7a417be 100644 --- a/src/application/mystic/forum/Database.php +++ b/src/application/mystic/forum/Database.php @@ -142,6 +142,7 @@ class Database { return "text"; case "object": case "array": + return "jsonb"; case "iterable": case "callable": case "mixed": @@ -241,8 +242,10 @@ class Database { return strval($value); elseif (is_a($value, \DateTimeInterface::class)) return $value->format("c"); + elseif (is_array($value) || is_object($value)) + return json_encode($value, JSON_UNESCAPED_SLASHES); else - throw new \RuntimeException("Don't know how to stringify " . is_object($value) ? get_class($value) : gettype($value)); + throw new \RuntimeException("Don't know how to stringify " . ((is_object($value) && !is_array($value)) ? get_class($value) : gettype($value))); } private static function assignValue(Entity &$entity, array $colProps, ?string $value): void { @@ -285,7 +288,11 @@ class Database { } break; case "object": + $typedValue = json_decode($value); + break; case "array": + $typedValue = json_decode($value, true); + break; case "iterable": case "callable": case "mixed": diff --git a/src/application/mystic/forum/orm/TopicLogMessage.php b/src/application/mystic/forum/orm/TopicLogMessage.php new file mode 100644 index 0000000..1caa3c5 --- /dev/null +++ b/src/application/mystic/forum/orm/TopicLogMessage.php @@ -0,0 +1,23 @@ +<?php +declare(strict_types=1); + +namespace mystic\forum\orm; + +use mystic\forum\attributes\DefaultValue; +use mystic\forum\attributes\PrimaryKey; +use mystic\forum\attributes\References; +use mystic\forum\attributes\Table; + +#[Table("public.topic_log")] +class TopicLogMessage extends Entity { + public const TITLE_CHANGED = 200; + public const LOCKED = 201; + public const UNLOCKED = 202; + + #[PrimaryKey] public string $id; + #[References("public.topics", onDelete: References::CASCADE)] public string $topicId; + public int $type; + public \DateTimeImmutable $postDate; + public array $params; + #[References("public.users", onDelete: References::SET_NULL)] public ?string $authorId; +} |