Hello.
I have "Group sequential post moved event posts into one." on.
If I select a single post to move, it does not result in any "EventPost PostMovedPost" posts at all in the original discussion.
However, if I select two or more sequential posts, then I do get the move event logged.
Anyone else seeing this?
I don't fully understand the code but I guess I see the bug?
if ($groupSequentialPosts) {
foreach($posts as $post) {
$nextPost = $posts->firstWhere('number', $post->number+1);
if ($nextPost) {
if (! isset($grouped[$index])) {
$grouped[$index] = new Collection();
}
$grouped[$index]->push($post);
$grouped[$index]->push($nextPost);
$grouped[$index] = $grouped[$index]->unique('id');
} else {
$index++;
}
}
}
The else statement only increments the $index, but it really should do something like:
$grouped[$index++] = new Collection([$post]);
I can test the fix on a dev instance, but assuming it works, what's the safest way to deploy the fix? I could modify the PHP manually but that won't survive upgrades/moves. I could submit a PR and hope it eventually gets approved, or I could fork Move Posts and figure out how to transition to the fork?
Kind of working in the dark here, but this worked for me:
if ($groupSequentialPosts) {
$index = -1;
$previousPostNumber = -10;
$uniqueSortedPosts = $posts->unique('id')->sortBy('number');
foreach ($uniqueSortedPosts as $post) {
$currentPostNumber = $post->number;
$isSequential = ($previousPostNumber+1) == $currentPostNumber;
if ($isSequential) {
$grouped[$index]->push($post);
} else {
$index++;
$grouped[$index] = new Collection([$post]);
}
$previousPostNumber = $currentPostNumber;
}
}
Here's the PR:
SychO9/flarum-move-posts22
And here it's verified in production.
![](https://i.imgur.com/JPcHFKQh.jpeg)
This sub-thread: https://forum.pianotell.com/d/781-piano/37
has spawned this thread:
https://forum.pianotell.com/d/892-fun-exotic-digital-keyboards
You can see there are several instances of single posts and grouped posts, but all the move event messages look correct! 🙂