diff --git a/src/Actions/DuplicateEntry.php b/src/Actions/DuplicateEntry.php index f278fd6482a..68189e408e5 100644 --- a/src/Actions/DuplicateEntry.php +++ b/src/Actions/DuplicateEntry.php @@ -66,6 +66,8 @@ public function run($items, $values) private function duplicateEntry(Entry $original, ?string $origin = null) { + $this->suspendPropagation($original); + $originalParent = $this->getEntryParentFromStructure($original); [$title, $slug] = $this->generateTitleAndSlug($original); @@ -175,4 +177,9 @@ public function redirect($items, $values) return $this->newItems->first()->editUrl(); } + + private function suspendPropagation(Entry $original): void + { + $original->collection()->propagate(false); + } } diff --git a/tests/Actions/DuplicateEntryTest.php b/tests/Actions/DuplicateEntryTest.php index c4ffe0a4a95..80982519ff4 100644 --- a/tests/Actions/DuplicateEntryTest.php +++ b/tests/Actions/DuplicateEntryTest.php @@ -433,6 +433,42 @@ public function it_duplicates_an_entry_from_a_non_default_site() ], $this->entryData()); } + #[Test] + public function it_duplicates_an_entry_with_localizations_without_propagating() + { + $this->setSites([ + 'en' => ['url' => 'http://domain.com/', 'locale' => 'en'], + 'fr' => ['url' => 'http://domain.com/fr/', 'locale' => 'fr'], + ]); + + $collection = Collection::make('test')->sites(['en', 'fr']); + $collection->save(); + + $entry = EntryFactory::id('alfa-id')->locale('en')->collection('test')->slug('alfa')->data(['title' => 'Alfa'])->create(); + $entry->makeLocalization('fr')->id('alfa-id-fr')->data(['title' => 'Alfa (French)'])->save(); + + $this->assertEquals([ + ['slug' => 'alfa', 'published' => true, 'data' => ['title' => 'Alfa'], 'locale' => 'en', 'origin' => ''], + ['slug' => 'alfa', 'published' => true, 'data' => ['title' => 'Alfa (French)'], 'locale' => 'fr', 'origin' => 'en.alfa'], + ], $this->entryData()); + + // Make super user since this test isn't concerned with permissions. + $this->actingAs(tap(User::make()->makeSuper())->save()); + + $collection->propagate(true); + + (new DuplicateEntry)->run(collect([ + Entry::find('alfa-id'), + ]), []); + + $this->assertEquals([ + ['slug' => 'alfa', 'published' => true, 'data' => ['title' => 'Alfa'], 'locale' => 'en', 'origin' => null], + ['slug' => 'alfa', 'published' => true, 'data' => ['title' => 'Alfa (French)'], 'locale' => 'fr', 'origin' => 'en.alfa'], + ['slug' => 'alfa-1', 'published' => false, 'data' => ['title' => 'Alfa (Duplicated)', 'duplicated_from' => 'alfa-id'], 'locale' => 'en', 'origin' => null], + ['slug' => 'alfa-1', 'published' => false, 'data' => ['title' => 'Alfa (French) (Duplicated)', 'duplicated_from' => 'alfa-id-fr'], 'locale' => 'fr', 'origin' => 'en.alfa-1'], + ], $this->entryData()); + } + #[Test] public function if_an_entry_has_an_origin_it_duplicates_the_root_origin() {