mirror of
https://github.com/flarum/core.git
synced 2025-08-02 14:37:49 +02:00
feat: provide old content to Revised
event (#3789)
Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
@@ -75,12 +75,14 @@ class CommentPost extends Post
|
|||||||
public function revise($content, User $actor)
|
public function revise($content, User $actor)
|
||||||
{
|
{
|
||||||
if ($this->content !== $content) {
|
if ($this->content !== $content) {
|
||||||
|
$oldContent = $this->content;
|
||||||
|
|
||||||
$this->setContentAttribute($content, $actor);
|
$this->setContentAttribute($content, $actor);
|
||||||
|
|
||||||
$this->edited_at = Carbon::now();
|
$this->edited_at = Carbon::now();
|
||||||
$this->edited_user_id = $actor->id;
|
$this->edited_user_id = $actor->id;
|
||||||
|
|
||||||
$this->raise(new Revised($this));
|
$this->raise(new Revised($this, $actor, $oldContent));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@@ -15,7 +15,7 @@ use Flarum\User\User;
|
|||||||
class Revised
|
class Revised
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Flarum\Post\CommentPost
|
* @var CommentPost
|
||||||
*/
|
*/
|
||||||
public $post;
|
public $post;
|
||||||
|
|
||||||
@@ -25,11 +25,18 @@ class Revised
|
|||||||
public $actor;
|
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->post = $post;
|
||||||
$this->actor = $actor;
|
$this->actor = $actor;
|
||||||
|
$this->oldContent = $oldContent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user