Skip to content

Commit 01acf35

Browse files
authored
Store updated_at in terms as timestamp (#409)
* Store updated_at in terms as timestamp * hmm
1 parent 57f8fd2 commit 01acf35

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Taxonomies/Term.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ public static function fromModel(Model $model)
3838
$term->data($data);
3939

4040
if (config('statamic.system.track_last_update')) {
41-
$term->set('updated_at', $model->updated_at ?? $model->created_at);
41+
$updatedAt = ($model->updated_at ?? $model->created_at);
42+
43+
$term->set('updated_at', $updatedAt instanceof Carbon ? $updatedAt->timestamp : $updatedAt);
4244
}
4345

4446
return $term->syncOriginal();

tests/Terms/TermTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,22 @@ public function it_doesnt_create_a_new_model_when_slug_is_changed()
2929
$this->assertCount(1, TermModel::all());
3030
$this->assertSame('new-slug', TermModel::first()->slug);
3131
}
32+
33+
#[Test]
34+
public function it_saves_updated_at_value_correctly()
35+
{
36+
$this->freezeSecond();
37+
38+
Taxonomy::make('test')->title('test')->save();
39+
40+
tap(TermFacade::make('test-term')->taxonomy('test')->data([]))->save();
41+
42+
/** @var LocalizedTerm $term */
43+
$term = TermFacade::query()->first();
44+
$term->set('foo', 'bar');
45+
$term->save();
46+
47+
$this->assertEquals(now(), $term->updated_at);
48+
$this->assertEquals(now(), TermFacade::query()->first()->updated_at);
49+
}
3250
}

0 commit comments

Comments
 (0)