diff --git a/TODO b/TODO index 650e1900..32fb1635 100644 --- a/TODO +++ b/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 diff --git a/public_html/js/Presenters/PostPresenter.js b/public_html/js/Presenters/PostPresenter.js index a9a4925a..d8561b07 100644 --- a/public_html/js/Presenters/PostPresenter.js +++ b/public_html/js/Presenters/PostPresenter.js @@ -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; diff --git a/src/FormData/PostEditFormData.php b/src/FormData/PostEditFormData.php index a91e4a03..98f2d4c7 100644 --- a/src/FormData/PostEditFormData.php +++ b/src/FormData/PostEditFormData.php @@ -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; } } diff --git a/src/Services/PostService.php b/src/Services/PostService.php index 57f0ec55..491b593f 100644 --- a/src/Services/PostService.php +++ b/src/Services/PostService.php @@ -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)