From ca7e54670de5d631fef6ba2ecbb1b82080351782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ca=C5=82ka?= <25438601+rafaucau@users.noreply.github.com> Date: Mon, 18 Nov 2024 13:51:15 +0100 Subject: [PATCH] feat: add support for fof/merge-discussions --- composer.json | 14 ++++--- extend.php | 4 ++ .../FoF/MergeDiscussionsEventSubscriber.php | 38 +++++++++++++++++++ 3 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 src/Compatibility/FoF/MergeDiscussionsEventSubscriber.php diff --git a/composer.json b/composer.json index c670720..ff85384 100644 --- a/composer.json +++ b/composer.json @@ -25,14 +25,15 @@ "php": ">=8.1" }, "require-dev": { - "flarum/phpstan": "^1.8", - "flarum/tags": "^1.8", - "v17development/flarum-blog": "^0.7.7", + "clarkwinkelmann/flarum-ext-author-change": "^1.0", "flarum/approval": "^1.8", "flarum/likes": "^1.8", + "flarum/phpstan": "^1.8", + "flarum/tags": "^1.8", "fof/masquerade": "^2.1", - "clarkwinkelmann/flarum-ext-author-change": "^1.0", - "sycho/flarum-move-posts": "^0.1.7" + "fof/merge-discussions": "^1.4", + "sycho/flarum-move-posts": "^0.1.7", + "v17development/flarum-blog": "^v0.8.0" }, "suggest": { "blomstra/flarum-redis": "This library allows using Redis as cache, session and for the queue. https://github.com/blomstra/flarum-redis#set-up" @@ -94,5 +95,8 @@ }, "scripts-descriptions": { "analyse:phpstan": "Run static analysis" + }, + "config": { + "sort-packages": true } } diff --git a/extend.php b/extend.php index c99f59c..00c08ea 100644 --- a/extend.php +++ b/extend.php @@ -18,6 +18,7 @@ Flarum\LikesEventSubscriber, Flarum\TagsEventSubscriber, FoF\MasqueradePurgeCacheMiddleware, + FoF\MergeDiscussionsEventSubscriber, SychO\MovePostsSubscriber, v17development\FlarumBlogEventSubscriber }; @@ -97,6 +98,9 @@ ->whenExtensionEnabled('fof-masquerade', [ (new Extend\Middleware('api'))->add(MasqueradePurgeCacheMiddleware::class), ]) + ->whenExtensionEnabled('fof-merge-discussions', [ + (new Extend\Event)->subscribe(MergeDiscussionsEventSubscriber::class), + ]) ->whenExtensionEnabled('v17development-blog', [ (new Extend\Event)->subscribe(FlarumBlogEventSubscriber::class), ]) diff --git a/src/Compatibility/FoF/MergeDiscussionsEventSubscriber.php b/src/Compatibility/FoF/MergeDiscussionsEventSubscriber.php new file mode 100644 index 0000000..a01e0ad --- /dev/null +++ b/src/Compatibility/FoF/MergeDiscussionsEventSubscriber.php @@ -0,0 +1,38 @@ +addPurgeListener($events, DiscussionWasMerged::class, [$this, 'handleDiscussionWasMerged']); + } + + protected function handleDiscussionWasMerged(DiscussionWasMerged $event): void + { + $this->handleDiscussionRelatedPurge(); + + $discussions = $event->mergedDiscussions; + $discussions->each(fn (Discussion $discussion) => $this->purger->addPurgeTag("discussion_$discussion->id")); + + $event->posts->each(function (Post $post) { + $this->purger->addPurgeTags([ + "post_$post->id", + "user_$post->user_id", + "user_{$post->user->username}", + ]); + }); + } +}