Skip to content

Commit 662bb12

Browse files
authored
Apply syncOriginal for dirty state tracking (#248)
1 parent 4701263 commit 662bb12

File tree

6 files changed

+22
-6
lines changed

6 files changed

+22
-6
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"require": {
2727
"php": "^8.0",
28-
"statamic/cms": "^4.48"
28+
"statamic/cms": "^4.51"
2929
},
3030
"require-dev": {
3131
"doctrine/dbal": "^3.3",

src/Assets/Asset.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,26 @@
77
use Statamic\Assets\Asset as FileAsset;
88
use Statamic\Assets\AssetUploader as Uploader;
99
use Statamic\Contracts\Assets\Asset as AssetContract;
10+
use Statamic\Data\HasDirtyState;
1011
use Statamic\Facades\Blink;
1112
use Statamic\Facades\Path;
1213
use Statamic\Support\Arr;
1314
use Statamic\Support\Str;
1415

1516
class Asset extends FileAsset
1617
{
18+
use HasDirtyState {
19+
syncOriginal as traitSyncOriginal;
20+
}
21+
22+
public function syncOriginal()
23+
{
24+
// FileAsset overrides the trait method in order to add the "pending
25+
// data" logic. We don't need it here since everything comes from
26+
// the model so we'll just use the original trait method again.
27+
return $this->traitSyncOriginal();
28+
}
29+
1730
protected $existsOnDisk = false;
1831
protected $removedData = [];
1932

@@ -22,7 +35,8 @@ public static function fromModel(Model $model)
2235
return (new static())
2336
->container($model->container)
2437
->path(Str::replace('//', '/', $model->folder.'/'.$model->basename))
25-
->hydrateMeta($model->meta);
38+
->hydrateMeta($model->meta)
39+
->syncOriginal();
2640
}
2741

2842
public function meta($key = null)

src/Entries/Entry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static function fromModel(Model $model)
3636
}
3737
}
3838

39-
return $entry;
39+
return $entry->syncOriginal();
4040
}
4141

4242
public function toModel()

src/Taxonomies/Term.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@ public static function fromModel(Model $model)
3535
unset($data['collection']);
3636
}
3737

38-
$term->syncOriginal();
3938
$term->data($data);
4039

4140
if (config('statamic.system.track_last_update')) {
4241
$term->set('updated_at', $model->updated_at ?? $model->created_at);
4342
}
4443

45-
return $term;
44+
return $term->syncOriginal();
4645
}
4746

4847
public function toModel()

tests/Data/Entries/EntryQueryBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function entry_is_found_within_all_created_entries_using_entry_facade_wit
3939
public function entry_is_found_within_all_created_entries_and_select_query_columns_are_set_using_entry_facade_with_find_method_with_columns_param()
4040
{
4141
$searchedEntry = $this->createDummyCollectionAndEntries();
42-
$columns = ['title'];
42+
$columns = ['foo', 'collection'];
4343
$retrievedEntry = Entry::query()->find($searchedEntry->id(), $columns);
4444

4545
$retrievedEntry->model(null);

tests/Entries/EntryTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ class EntryTest extends TestCase
1919
/** @test */
2020
public function it_loads_from_entry_model()
2121
{
22+
Collection::make('blog')->title('blog')->save();
23+
2224
$model = new EntryModel([
25+
'collection' => 'blog',
2326
'slug' => 'the-slug',
2427
'data' => [
2528
'foo' => 'bar',

0 commit comments

Comments
 (0)