Improved API for post editing
This commit is contained in:
parent
1ad5d7475c
commit
465a61ff4a
3 changed files with 7 additions and 4 deletions
|
@ -109,7 +109,7 @@ App.Presenters.PostEditPresenter = function(
|
||||||
function editPost() {
|
function editPost() {
|
||||||
var $form = $target.find('form');
|
var $form = $target.find('form');
|
||||||
var formData = new FormData();
|
var formData = new FormData();
|
||||||
formData.append('seenEditTime', post.lastEditTime);
|
formData.append('lastEditTime', post.lastEditTime);
|
||||||
|
|
||||||
if (privileges.canChangeContent && postContent) {
|
if (privileges.canChangeContent && postContent) {
|
||||||
formData.append('content', postContent);
|
formData.append('content', postContent);
|
||||||
|
|
|
@ -14,7 +14,7 @@ class PostEditFormData implements IValidatable
|
||||||
public $relations;
|
public $relations;
|
||||||
public $flags;
|
public $flags;
|
||||||
|
|
||||||
public $seenEditTime;
|
public $lastEditTime;
|
||||||
|
|
||||||
public function __construct($inputReader = null)
|
public function __construct($inputReader = null)
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,7 @@ class PostEditFormData implements IValidatable
|
||||||
$this->tags = preg_split('/[\s+]/', $inputReader->tags);
|
$this->tags = preg_split('/[\s+]/', $inputReader->tags);
|
||||||
if ($inputReader->relations !== null)
|
if ($inputReader->relations !== null)
|
||||||
$this->relations = array_filter(preg_split('/[\s+]/', $inputReader->relations));
|
$this->relations = array_filter(preg_split('/[\s+]/', $inputReader->relations));
|
||||||
$this->seenEditTime = $inputReader->seenEditTime;
|
$this->lastEditTime = $inputReader->lastEditTime;
|
||||||
$this->flags = new \StdClass;
|
$this->flags = new \StdClass;
|
||||||
$this->flags->loop = !empty($inputReader->loop);
|
$this->flags->loop = !empty($inputReader->loop);
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,10 @@ class PostService
|
||||||
{
|
{
|
||||||
$this->validator->validate($formData);
|
$this->validator->validate($formData);
|
||||||
|
|
||||||
if ($post->getLastEditTime() !== $formData->seenEditTime)
|
if (!$formData->lastEditTime)
|
||||||
|
throw new \DomainException('Last edit time was not provided; cannot edit post.');
|
||||||
|
|
||||||
|
if ($post->getLastEditTime() !== $formData->lastEditTime)
|
||||||
throw new \DomainException('Someone has already edited this post in the meantime.');
|
throw new \DomainException('Someone has already edited this post in the meantime.');
|
||||||
|
|
||||||
$post->setLastEditTime($this->timeService->getCurrentTime());
|
$post->setLastEditTime($this->timeService->getCurrentTime());
|
||||||
|
|
Loading…
Reference in a new issue