Skip to content

Commit 070feab

Browse files
authored
Ensure template is stored when importing entries (#404)
* Ensure template is imported * 🍺 * fix unrelated pint issue
1 parent ec98930 commit 070feab

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/Entries/Entry.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ public static function makeModelFromContract(EntryContract $source)
127127
'order' => $source->order(),
128128
];
129129

130+
if ($source->template) {
131+
$attributes['data']->put('template', $source->template);
132+
}
133+
130134
foreach ($dataMappings as $key) {
131135
$attributes[$key] = $data->get($key);
132136
}

tests/Commands/ImportEntriesTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,21 @@ public function it_imports_localized_entries()
8282
$this->assertDatabaseHas('entries', ['collection' => 'pages', 'site' => 'en', 'slug' => 'foo', 'data' => '{"foo":"bar"}']);
8383
$this->assertDatabaseHas('entries', ['collection' => 'pages', 'site' => 'fr', 'slug' => 'foo', 'data' => '{"foo":"bar","baz":"qux","__localized_fields":[]}']);
8484
}
85+
86+
#[Test]
87+
public function it_imports_template_correctly()
88+
{
89+
$collection = tap(Collection::make('pages')->title('Pages'))->save();
90+
Entry::make()->collection($collection)->slug('template-test')->data(['foo' => 'bar'])->template('some.template')->save();
91+
92+
$this->assertCount(0, EntryModel::all());
93+
94+
$this->artisan('statamic:eloquent:import-entries')
95+
->expectsOutputToContain('Entries imported successfully.')
96+
->assertExitCode(0);
97+
98+
$this->assertCount(1, EntryModel::all());
99+
100+
$this->assertDatabaseHas('entries', ['collection' => 'pages', 'slug' => 'template-test', 'data' => '{"foo":"bar","template":"some.template"}']);
101+
}
85102
}

tests/Data/Entries/EntryQueryBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ public function filtering_using_where_status_column_writes_deprecation_log()
850850
}
851851

852852
#[Test]
853-
public function filtering_using_whereIn_status_column_writes_deprecation_log()
853+
public function filtering_using_where_in_status_column_writes_deprecation_log()
854854
{
855855
$this->withoutDeprecationHandling();
856856
$this->expectException(\ErrorException::class);

0 commit comments

Comments
 (0)