Repository navigation
fix: persist created_at on first approval for resources and forum posts #489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,14 +80,15 @@ public function updateModerationStatus(Request $request, ForumPost $post) | |
| $oldStatus = $post->moderation_status; | ||
| $newStatus = $validated['moderation_status']; | ||
|
|
||
| $updateData = ['moderation_status' => $newStatus]; | ||
| $post->update(['moderation_status' => $newStatus]); | ||
|
|
||
| // First-time approval: reset created_at so it is fresh in Trending & Feed | ||
| // Direct assignment used because created_at is not in $fillable | ||
| if ($newStatus === 'approved' && $oldStatus === 'pending') { | ||
| $updateData['created_at'] = now(); | ||
| $post->created_at = now(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Track whether the post was previously approved. A moderator can move an approved post back to pending and approve it again. This assignment then resets
|
||
| $post->save(); | ||
| } | ||
|
|
||
| $post->update($updateData); | ||
|
|
||
| if ($oldStatus !== $newStatus && $post->user_id && $post->user_id !== auth()->id()) { | ||
| $post->user->notify(new ForumStatusNotification($post, $newStatus)); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Save the status and timestamp together.
If the second save fails, the post remains approved with its old timestamp. Retrying skips the timestamp update because the status is already approved. Assign both fields before one save. (github.com)