Skip to content

Commit

Permalink
delete all locks for post for delete by post id
Browse files Browse the repository at this point in the history
  • Loading branch information
Mh-Asmi committed Sep 19, 2024
1 parent 2f64bca commit ace4450
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit ace4450

Please sign in to comment.