From b4dd56d7102470ba4aa81067e6a57436015528a8 Mon Sep 17 00:00:00 2001 From: Arthur Perton Date: Tue, 22 Jun 2021 11:05:20 +0200 Subject: [PATCH 1/5] When deleting a collection delete its tree(s) too --- src/Entries/Collection.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Entries/Collection.php b/src/Entries/Collection.php index 6ab3fb4f71..cd36d0dcf5 100644 --- a/src/Entries/Collection.php +++ b/src/Entries/Collection.php @@ -4,6 +4,7 @@ use Statamic\Contracts\Data\Augmentable as AugmentableContract; use Statamic\Contracts\Entries\Collection as Contract; +use Statamic\Contracts\Structures\CollectionTreeRepository; use Statamic\Data\ContainsCascadingData; use Statamic\Data\ExistsAsFile; use Statamic\Data\HasAugmentedData; @@ -602,6 +603,12 @@ public function delete() { $this->queryEntries()->get()->each->delete(); + if ($this->structure()) { + $this->structure()->trees()->each(function ($tree) { + app(CollectionTreeRepository::class)->delete($tree); + }); + } + Facades\Collection::delete($this); CollectionDeleted::dispatch($this); From 2c40f3adcf815287ac7c0a9a4dd7fda1a5bd33a4 Mon Sep 17 00:00:00 2001 From: Arthur Perton Date: Tue, 22 Jun 2021 19:41:40 +0200 Subject: [PATCH 2/5] Simplify --- src/Entries/Collection.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Entries/Collection.php b/src/Entries/Collection.php index cd36d0dcf5..0cd87fa817 100644 --- a/src/Entries/Collection.php +++ b/src/Entries/Collection.php @@ -603,10 +603,8 @@ public function delete() { $this->queryEntries()->get()->each->delete(); - if ($this->structure()) { - $this->structure()->trees()->each(function ($tree) { - app(CollectionTreeRepository::class)->delete($tree); - }); + if ($structure = $this->structure()) { + $structure->trees()->each->delete(); } Facades\Collection::delete($this); From 861bba9766ff187b6df383fd0d5907a52704d589 Mon Sep 17 00:00:00 2001 From: Arthur Perton Date: Tue, 22 Jun 2021 19:42:48 +0200 Subject: [PATCH 3/5] Remove unused import --- src/Entries/Collection.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Entries/Collection.php b/src/Entries/Collection.php index 0cd87fa817..8b969fc8a2 100644 --- a/src/Entries/Collection.php +++ b/src/Entries/Collection.php @@ -4,7 +4,6 @@ use Statamic\Contracts\Data\Augmentable as AugmentableContract; use Statamic\Contracts\Entries\Collection as Contract; -use Statamic\Contracts\Structures\CollectionTreeRepository; use Statamic\Data\ContainsCascadingData; use Statamic\Data\ExistsAsFile; use Statamic\Data\HasAugmentedData; From 7b3b24e2f591994773de598cec0c0b551cb6472d Mon Sep 17 00:00:00 2001 From: Arthur Perton Date: Tue, 22 Jun 2021 20:24:15 +0200 Subject: [PATCH 4/5] Properly delete localized entries when deleting collection --- src/Entries/Collection.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Entries/Collection.php b/src/Entries/Collection.php index 8b969fc8a2..a7a228a155 100644 --- a/src/Entries/Collection.php +++ b/src/Entries/Collection.php @@ -600,7 +600,10 @@ public function hasStructure() public function delete() { - $this->queryEntries()->get()->each->delete(); + $this->queryEntries()->get()->each(function ($entry) { + $entry->deleteDescendants(); + $entry->delete(); + }); if ($structure = $this->structure()) { $structure->trees()->each->delete(); From c67f815998ff4f97816977684773f93533eed21a Mon Sep 17 00:00:00 2001 From: Arthur Perton Date: Sat, 17 Jul 2021 21:36:58 +0200 Subject: [PATCH 5/5] Delete trees before deleting entries --- src/Entries/Collection.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Entries/Collection.php b/src/Entries/Collection.php index a7a228a155..c76b234e29 100644 --- a/src/Entries/Collection.php +++ b/src/Entries/Collection.php @@ -600,15 +600,15 @@ public function hasStructure() public function delete() { + if ($structure = $this->structure()) { + $structure->trees()->each->delete(); + } + $this->queryEntries()->get()->each(function ($entry) { $entry->deleteDescendants(); $entry->delete(); }); - if ($structure = $this->structure()) { - $structure->trees()->each->delete(); - } - Facades\Collection::delete($this); CollectionDeleted::dispatch($this);