diff --git a/src/Ushahidi/Modules/V5/Actions/Post/Handlers/UpdatePostLockCommandHandler.php b/src/Ushahidi/Modules/V5/Actions/Post/Handlers/UpdatePostLockCommandHandler.php index 741e19e0d..a6ba24545 100644 --- a/src/Ushahidi/Modules/V5/Actions/Post/Handlers/UpdatePostLockCommandHandler.php +++ b/src/Ushahidi/Modules/V5/Actions/Post/Handlers/UpdatePostLockCommandHandler.php @@ -43,7 +43,7 @@ private function updatePostLock($post_id) // if user can break the lock "has admin role" then release the old lock if it from other user // If the lock is inactive and the lock is not for current user release old one and create new one - $this->setCurrentPostLock($post_id); + $this->getCurrentPostLock($post_id); if ($this->current_post_lock) { if (($this->lockIsBreakable()) || (!$this->currentLockIsActive() && !$this->userOwnsCurrentLock())) { @@ -76,7 +76,7 @@ private function userOwnsCurrentLock() $user = Auth::user(); return intval($user->id) === intval($this->current_post_lock->user_id); } - private function setCurrentPostLock($post_id): void + private function getCurrentPostLock($post_id): void { try { $this->current_post_lock = $this->post_lock_repository->findByPostId($post_id); diff --git a/src/Ushahidi/Modules/V5/Http/Controllers/PostController.php b/src/Ushahidi/Modules/V5/Http/Controllers/PostController.php index ebdacbf81..a00de20a2 100644 --- a/src/Ushahidi/Modules/V5/Http/Controllers/PostController.php +++ b/src/Ushahidi/Modules/V5/Http/Controllers/PostController.php @@ -479,8 +479,7 @@ public function showPostGeoJson($id, Request $request): PostGeometryResource public function updateLock(int $post_id, Request $request) { - - $post = $this->queryBus->handle(new FindPostByIdQuery($post_id, ['id', 'user_id', 'form_id'])); + $post = $this->getPost($post_id, ['id', 'status','user_id','form_id'], []); $this->authorize('update', $post); $this->commandBus->handle(new UpdatePostLockCommand($post_id)); @@ -491,7 +490,7 @@ public function updateLock(int $post_id, Request $request) public function deleteLock(int $post_id, Request $request) { - $post = $this->queryBus->handle(new FindPostByIdQuery($post_id, ['id', 'user_id', 'form_id'])); + $post = $this->getPost($post_id, ['id', 'status','user_id','form_id'], []); $this->authorize('update', $post); $this->commandBus->handle(new DeletePostLockCommand($post_id)); diff --git a/src/Ushahidi/Modules/V5/Repository/Post/EloquentPostLockRepository.php b/src/Ushahidi/Modules/V5/Repository/Post/EloquentPostLockRepository.php index 55f586a96..9a3b2fe37 100644 --- a/src/Ushahidi/Modules/V5/Repository/Post/EloquentPostLockRepository.php +++ b/src/Ushahidi/Modules/V5/Repository/Post/EloquentPostLockRepository.php @@ -38,7 +38,10 @@ public function deleteById(int $id): void } public function deleteByPostId(int $post_id): void { - $this->findByPostId($post_id)->delete(); + $post_locks = PostLock::where('post_id', '=', $post_id)->get(); + foreach ($post_locks as $post_lock) { + $post_lock->delete(); + } } public function deleteByUserId(int $user_id): void {