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
|
- fav
|
||||||
- score (see notes about scoring)
|
- score (see notes about scoring)
|
||||||
- editing
|
- editing
|
||||||
- concurrency
|
|
||||||
- relations
|
- relations
|
||||||
- ability to loop video posts
|
- ability to loop video posts
|
||||||
- post edit history (think
|
- post edit history (think
|
||||||
|
|
|
@ -168,6 +168,7 @@ App.Presenters.PostPresenter = function(
|
||||||
function editPost() {
|
function editPost() {
|
||||||
var $form = $el.find('form');
|
var $form = $el.find('form');
|
||||||
var formData = {};
|
var formData = {};
|
||||||
|
formData.seenEditTime = post.lastEditTime;
|
||||||
|
|
||||||
if (editPrivileges.canChangeContent && postContent) {
|
if (editPrivileges.canChangeContent && postContent) {
|
||||||
formData.content = postContent;
|
formData.content = postContent;
|
||||||
|
|
|
@ -9,6 +9,8 @@ class PostEditFormData implements \Szurubooru\IValidatable
|
||||||
public $source;
|
public $source;
|
||||||
public $tags;
|
public $tags;
|
||||||
|
|
||||||
|
public $seenEditTime;
|
||||||
|
|
||||||
public function __construct($inputReader = null)
|
public function __construct($inputReader = null)
|
||||||
{
|
{
|
||||||
if ($inputReader !== null)
|
if ($inputReader !== null)
|
||||||
|
@ -18,6 +20,7 @@ class PostEditFormData implements \Szurubooru\IValidatable
|
||||||
$this->safety = \Szurubooru\Helpers\EnumHelper::postSafetyFromString($inputReader->safety);
|
$this->safety = \Szurubooru\Helpers\EnumHelper::postSafetyFromString($inputReader->safety);
|
||||||
$this->source = $inputReader->source;
|
$this->source = $inputReader->source;
|
||||||
$this->tags = preg_split('/[\s+]/', $inputReader->tags);
|
$this->tags = preg_split('/[\s+]/', $inputReader->tags);
|
||||||
|
$this->seenEditTime = $inputReader->seenEditTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,10 @@ class PostService
|
||||||
$transactionFunc = function() use ($post, $formData)
|
$transactionFunc = function() use ($post, $formData)
|
||||||
{
|
{
|
||||||
$this->validator->validate($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());
|
$post->setLastEditTime($this->timeService->getCurrentTime());
|
||||||
|
|
||||||
if ($formData->content !== null)
|
if ($formData->content !== null)
|
||||||
|
|
Loading…
Reference in a new issue