Skip to content
Merged
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
7 changes: 7 additions & 0 deletions src/Actions/DuplicateEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -175,4 +177,9 @@ public function redirect($items, $values)

return $this->newItems->first()->editUrl();
}

private function suspendPropagation(Entry $original): void
{
$original->collection()->propagate(false);
}
}
36 changes: 36 additions & 0 deletions tests/Actions/DuplicateEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Loading