Skip to content

Commit

Permalink
Fix invisible posts when deleting first in series
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkwinkelmann committed Aug 7, 2024
1 parent c116e80 commit 77ae61b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Flarum\Api\Serializer\PostSerializer;
use Flarum\Extend;
use Flarum\Post\Event\Deleted;
use Flarum\Post\Event\Saving;
use Flarum\Post\Post;

Expand Down Expand Up @@ -33,7 +34,8 @@
->attributes(PostAttributes::class),

(new Extend\Event())
->listen(Saving::class, Listener\SavePost::class),
->listen(Saving::class, Listener\SavePost::class)
->listen(Deleted::class, Listener\DeletePost::class),

(new Extend\Policy())
->modelPolicy(Post::class, Access\PostPolicy::class),
Expand Down
29 changes: 29 additions & 0 deletions src/Listener/DeletePost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace ClarkWinkelmann\CollapsiblePosts\Listener;

use ClarkWinkelmann\CollapsiblePosts\Job\UpdateCollapseCount;
use Flarum\Post\Event\Deleted;
use Illuminate\Contracts\Queue\Queue;

class DeletePost
{
protected $queue;

public function __construct(Queue $queue)
{
$this->queue = $queue;
}

public function handle(Deleted $event)
{
$discussion = $event->post->discussion;

// The relationship should still be able to load, but just in case we don't want to crash everything
if (!$discussion) {
return;
}

$this->queue->push(new UpdateCollapseCount($discussion));
}
}

0 comments on commit 77ae61b

Please sign in to comment.