Skip to content

Commit

Permalink
feat: add support for fof/merge-discussions
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaucau committed Nov 18, 2024
1 parent 2c55079 commit ca7e546
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
14 changes: 9 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -94,5 +95,8 @@
},
"scripts-descriptions": {
"analyse:phpstan": "Run static analysis"
},
"config": {
"sort-packages": true
}
}
4 changes: 4 additions & 0 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Flarum\LikesEventSubscriber,
Flarum\TagsEventSubscriber,
FoF\MasqueradePurgeCacheMiddleware,
FoF\MergeDiscussionsEventSubscriber,
SychO\MovePostsSubscriber,
v17development\FlarumBlogEventSubscriber
};
Expand Down Expand Up @@ -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),
])
Expand Down
38 changes: 38 additions & 0 deletions src/Compatibility/FoF/MergeDiscussionsEventSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace ACPL\FlarumLSCache\Compatibility\FoF;

use ACPL\FlarumLSCache\Listener\{
AbstractCachePurgeSubscriber,
DiscussionCachePurgeTrait
};
use Flarum\Discussion\Discussion;
use Flarum\Post\Post;
use FoF\MergeDiscussions\Events\DiscussionWasMerged;
use Illuminate\Contracts\Events\Dispatcher;

class MergeDiscussionsEventSubscriber extends AbstractCachePurgeSubscriber
{
use DiscussionCachePurgeTrait;

public function subscribe(Dispatcher $events): void
{
$this->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}",
]);
});
}
}

0 comments on commit ca7e546

Please sign in to comment.