Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Http/Controllers/CP/Collections/EntriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,11 @@ public function update(Request $request, $collection, $entry)
$parent = null;
}

$tree
->move($entry->id(), $parent)
->save();
if (! $tree->isAlreadyInParent($entry->id(), $parent)) {
$tree
->move($entry->id(), $parent)
->save();
}
});

$entry->remove('parent');
Expand Down
8 changes: 5 additions & 3 deletions src/Revisions/Revisable.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ public function publishWorkingCopy($options = [])
$parent = null;
}

$tree
->move($this->id(), $parent)
->save();
if ($tree->isAlreadyInParent($item->id(), $parent)) {
$tree
->move($this->id(), $parent)
->save();
}
}

$item
Expand Down
5 changes: 5 additions & 0 deletions src/Structures/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ public function setChildren(array $children): self
return $this;
}

public function getChildren(): array
{
return $this->children;
}

public function setPageData(array $data): self
{
$this->data = $data;
Expand Down
15 changes: 15 additions & 0 deletions src/Structures/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,19 @@ public function getCurrentDirtyStateAttributes(): array
'tree' => $this->tree,
];
}

public function isAlreadyInParent($entryId, $parentId = null): bool
{
if ($parentId) {
$parentPage = $this->find($parentId);
if (! $parentPage) {
return false;
}
$childrenIds = Arr::pluck($parentPage->getChildren(), $this->idKey());
} else {
$childrenIds = collect($this->tree)->pluck($this->idKey())->all();
}

return in_array($entryId, $childrenIds);
}
}