Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: provide old content to Revised event #3789

Merged
merged 1 commit into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion framework/core/src/Post/CommentPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ public static function reply($discussionId, $content, $userId, $ipAddress, User
public function revise($content, User $actor)
{
if ($this->content !== $content) {
$oldContent = $this->content;

$this->setContentAttribute($content, $actor);

$this->edited_at = Carbon::now();
$this->edited_user_id = $actor->id;

$this->raise(new Revised($this));
$this->raise(new Revised($this, $actor, $oldContent));
}

return $this;
Expand Down
13 changes: 10 additions & 3 deletions framework/core/src/Post/Event/Revised.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class Revised
{
/**
* @var \Flarum\Post\CommentPost
* @var CommentPost
*/
public $post;

Expand All @@ -25,11 +25,18 @@ class Revised
public $actor;

/**
* @param \Flarum\Post\CommentPost $post
* We manually set the old content because at this stage the post
* has already been updated with the new content. So the original
* content is not available anymore.
*
* @var string
*/
public function __construct(CommentPost $post, User $actor = null)
public $oldContent;

public function __construct(CommentPost $post, User $actor, string $oldContent)
{
$this->post = $post;
$this->actor = $actor;
$this->oldContent = $oldContent;
}
}