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}", + ]); + }); + } +}