From b75dfadd22302a774d677e82bce1b567c01e7d50 Mon Sep 17 00:00:00 2001 From: Murtaza Sultani Date: Thu, 2 Oct 2025 13:26:19 +0200 Subject: Add post log and extract post log from admin tag --- .../6.2.2_add_editor_id_to_postings_table.php | 19 ++++++ .../6.2.2_add_forum_posting_logs_table.php | 19 ------ lib/classes/JsonApi/SchemaMap.php | 1 - lib/classes/JsonApi/Schemas/Forum/PostingLog.php | 78 ---------------------- lib/models/Forum/Posting.php | 7 -- lib/models/Forum/PostingLog.php | 37 ---------- 6 files changed, 19 insertions(+), 142 deletions(-) create mode 100644 db/migrations/6.2.2_add_editor_id_to_postings_table.php delete mode 100644 db/migrations/6.2.2_add_forum_posting_logs_table.php delete mode 100644 lib/classes/JsonApi/Schemas/Forum/PostingLog.php delete mode 100644 lib/models/Forum/PostingLog.php diff --git a/db/migrations/6.2.2_add_editor_id_to_postings_table.php b/db/migrations/6.2.2_add_editor_id_to_postings_table.php new file mode 100644 index 0000000..29a8679 --- /dev/null +++ b/db/migrations/6.2.2_add_editor_id_to_postings_table.php @@ -0,0 +1,19 @@ +exec(" + ALTER TABLE `forum_postings` + ADD COLUMN `editor_id` CHAR(32) COLLATE latin1_bin NOT NULL AFTER `user_id` + "); + } + + public function down() + { + DBManager::get()->exec(" + ALTER TABLE `forum_postings` DROP COLUMN `editor_id` + "); + } +} diff --git a/db/migrations/6.2.2_add_forum_posting_logs_table.php b/db/migrations/6.2.2_add_forum_posting_logs_table.php deleted file mode 100644 index bc38d98..0000000 --- a/db/migrations/6.2.2_add_forum_posting_logs_table.php +++ /dev/null @@ -1,19 +0,0 @@ -exec(" - ALTER TABLE `forum_postings` - ADD COLUMN `editor_id` CHAR(32) COLLATE latin1_bin NOT NULL AFTER `user_id` - "); - } - - public function down() - { - DBManager::get()->exec(" - ALTER TABLE `forum_postings` DROP COLUMN `editor_id` - "); - } -} diff --git a/lib/classes/JsonApi/SchemaMap.php b/lib/classes/JsonApi/SchemaMap.php index 2bc26de..d45c6a7 100644 --- a/lib/classes/JsonApi/SchemaMap.php +++ b/lib/classes/JsonApi/SchemaMap.php @@ -44,7 +44,6 @@ class SchemaMap \Forum\Discussion::class => \JsonApi\Schemas\Forum\Discussion::class, \Forum\DiscussionType::class => \JsonApi\Schemas\Forum\DiscussionType::class, \Forum\Posting::class => \JsonApi\Schemas\Forum\Posting::class, - \Forum\PostingLog::class => \JsonApi\Schemas\Forum\PostingLog::class, \Forum\PostingReaction::class => \JsonApi\Schemas\Forum\PostingReaction::class, \Forum\Subscription::class => \JsonApi\Schemas\Forum\Subscription::class, \Forum\DTO\Member::class => \JsonApi\Schemas\Forum\Member::class, diff --git a/lib/classes/JsonApi/Schemas/Forum/PostingLog.php b/lib/classes/JsonApi/Schemas/Forum/PostingLog.php deleted file mode 100644 index 73138ef..0000000 --- a/lib/classes/JsonApi/Schemas/Forum/PostingLog.php +++ /dev/null @@ -1,78 +0,0 @@ -id; - } - - /** - * @param \Forum\PostingLog $resource - */ - public function getAttributes($resource, ContextInterface $context): iterable - { - return [ - 'action' => $resource->action, - 'mkdate' => date('c', $resource->mkdate) - ]; - } - - /** - * @param \Forum\PostingLog $resource - */ - public function getRelationships($resource, ContextInterface $context): iterable - { - $relationships = []; - $relationships = $this->addPostingRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_POSTING)); - $relationships = $this->addUserRelationship($relationships, $resource, $this->shouldInclude($context, self::REL_USER)); - - return $relationships; - } - - - private function addPostingRelationship(array $relationships, \Forum\PostingLog $postingLog, bool $withPosting = false) - { - $posting = $postingLog->posting; - - if ($withPosting && $posting) { - $relationships[self::REL_POSTING] = [ - self::RELATIONSHIP_LINKS => [ - Link::RELATED => $this->createLinkToResource($posting) - ], - self::RELATIONSHIP_DATA => $posting - ]; - } - - return $relationships; - } - - private function addUserRelationship(array $relationships, \Forum\PostingLog $postingLog, bool $withUser = false) - { - $user = $postingLog->user; - - if ($withUser && $user) { - $relationships[self::REL_USER] = [ - self::RELATIONSHIP_LINKS => [ - Link::RELATED => $this->createLinkToResource($user) - ], - self::RELATIONSHIP_DATA => $user - ]; - } - - return $relationships; - } -} diff --git a/lib/models/Forum/Posting.php b/lib/models/Forum/Posting.php index 9d33a88..c2b86a4 100644 --- a/lib/models/Forum/Posting.php +++ b/lib/models/Forum/Posting.php @@ -59,13 +59,6 @@ class Posting extends SimpleORMap 'assoc_foreign_key' => 'posting_id' ]; - $config['has_many']['logs'] = [ - 'class_name' => PostingLog::class, - 'foreign_key' => 'posting_id', - 'assoc_foreign_key' => 'posting_id', - 'order_by' => 'ORDER BY mkdate DESC LIMIT 1', - ]; - $config['additional_fields']['author']['get'] = 'getAuthor'; $config['registered_callbacks']['after_create'][] = 'onCreate'; $config['registered_callbacks']['after_delete'][] = 'onDelete'; diff --git a/lib/models/Forum/PostingLog.php b/lib/models/Forum/PostingLog.php deleted file mode 100644 index 75a05b9..0000000 --- a/lib/models/Forum/PostingLog.php +++ /dev/null @@ -1,37 +0,0 @@ - Posting::class, - 'foreign_key' => 'posting_id', - 'assoc_foreign_key' => 'posting_id' - ]; - - $config['belongs_to']['user'] = [ - 'class_name' => User::class, - 'foreign_key' => 'user_id', - 'assoc_foreign_key' => 'user_id' - ]; - - parent::configure($config); - } -} -- cgit v1.0