Added concurrent editing detection
This commit is contained in:
parent
a7c07d32df
commit
22b30c3e43
4 changed files with 8 additions and 1 deletions
1
TODO
1
TODO
|
@ -6,7 +6,6 @@ everything related to posts:
|
|||
- fav
|
||||
- score (see notes about scoring)
|
||||
- editing
|
||||
- concurrency
|
||||
- relations
|
||||
- ability to loop video posts
|
||||
- post edit history (think
|
||||
|
|
|
@ -168,6 +168,7 @@ App.Presenters.PostPresenter = function(
|
|||
function editPost() {
|
||||
var $form = $el.find('form');
|
||||
var formData = {};
|
||||
formData.seenEditTime = post.lastEditTime;
|
||||
|
||||
if (editPrivileges.canChangeContent && postContent) {
|
||||
formData.content = postContent;
|
||||
|
|
|
@ -9,6 +9,8 @@ class PostEditFormData implements \Szurubooru\IValidatable
|
|||
public $source;
|
||||
public $tags;
|
||||
|
||||
public $seenEditTime;
|
||||
|
||||
public function __construct($inputReader = null)
|
||||
{
|
||||
if ($inputReader !== null)
|
||||
|
@ -18,6 +20,7 @@ class PostEditFormData implements \Szurubooru\IValidatable
|
|||
$this->safety = \Szurubooru\Helpers\EnumHelper::postSafetyFromString($inputReader->safety);
|
||||
$this->source = $inputReader->source;
|
||||
$this->tags = preg_split('/[\s+]/', $inputReader->tags);
|
||||
$this->seenEditTime = $inputReader->seenEditTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -115,6 +115,10 @@ class PostService
|
|||
$transactionFunc = function() use ($post, $formData)
|
||||
{
|
||||
$this->validator->validate($formData);
|
||||
|
||||
if ($post->getLastEditTime() !== $formData->seenEditTime)
|
||||
throw new \DomainException('Someone has already edited this post in the meantime.');
|
||||
|
||||
$post->setLastEditTime($this->timeService->getCurrentTime());
|
||||
|
||||
if ($formData->content !== null)
|
||||
|
|
Loading…
Reference in a new issue