Improved API for post editing

This commit is contained in:
rr- 2015-08-03 19:27:25 +02:00
parent 1ad5d7475c
commit 465a61ff4a
3 changed files with 7 additions and 4 deletions

View file

@ -109,7 +109,7 @@ App.Presenters.PostEditPresenter = function(
function editPost() {
var $form = $target.find('form');
var formData = new FormData();
formData.append('seenEditTime', post.lastEditTime);
formData.append('lastEditTime', post.lastEditTime);
if (privileges.canChangeContent && postContent) {
formData.append('content', postContent);

View file

@ -14,7 +14,7 @@ class PostEditFormData implements IValidatable
public $relations;
public $flags;
public $seenEditTime;
public $lastEditTime;
public function __construct($inputReader = null)
{
@ -29,7 +29,7 @@ class PostEditFormData implements IValidatable
$this->tags = preg_split('/[\s+]/', $inputReader->tags);
if ($inputReader->relations !== null)
$this->relations = array_filter(preg_split('/[\s+]/', $inputReader->relations));
$this->seenEditTime = $inputReader->seenEditTime;
$this->lastEditTime = $inputReader->lastEditTime;
$this->flags = new \StdClass;
$this->flags->loop = !empty($inputReader->loop);
}

View file

@ -140,7 +140,10 @@ class PostService
{
$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.');
$post->setLastEditTime($this->timeService->getCurrentTime());