Skip to content

Commit d1c5d7d

Browse files
jakubdibalapionl
authored andcommitted
Fix deleted event in PositionObserver to correctly handle position recalculate
1 parent 89043bf commit d1c5d7d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/PositionObserver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function saving($model)
4545
if ($model->isPositionUpdateDisabled() === false) {
4646
// Get the position for current and old value
4747
$position = $model->getPosition();
48-
48+
4949
// Prevent modifying position column when updating and position columns has not changed
5050
if ($model->exists === true && $model->isDirty($model->getPositionColumn()) === false) {
5151
return;
@@ -70,7 +70,7 @@ public function saving($model)
7070
*
7171
* @param Model|PositionTrait $model
7272
*/
73-
public function deleting($model)
73+
public function deleted($model)
7474
{
7575
if ($model->isPositionUpdateDisabled() === false) {
7676
// Get the old position

src/Query/LastPositionQuery.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public function runQuery($query)
4141
$lastPosition = $query->max($this->model()->getPositionColumn()) ?: 0;
4242

4343
if (empty($this->oldPosition) === false) {
44+
if ($this->oldPosition === $this->model->getPosition() && $lastPosition < $this->model->getPosition()) {
45+
return;
46+
}
47+
4448
(new MoveQuery($this->model, $lastPosition, $this->oldPosition))->run();
4549
} else if ($this->oldPosition === null || $lastPosition != $this->oldPosition) {
4650
// Check if the last position is not same as original position - the same object

0 commit comments

Comments
 (0)