Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply syncOriginal for dirty state tracking #248

Merged
merged 8 commits into from
Feb 28, 2024
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"require": {
"php": "^8.0",
"statamic/cms": "^4.48"
"statamic/cms": "^4.51"
},
"require-dev": {
"doctrine/dbal": "^3.3",
Expand Down
16 changes: 15 additions & 1 deletion src/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,26 @@
use Statamic\Assets\Asset as FileAsset;
use Statamic\Assets\AssetUploader as Uploader;
use Statamic\Contracts\Assets\Asset as AssetContract;
use Statamic\Data\HasDirtyState;
use Statamic\Facades\Blink;
use Statamic\Facades\Path;
use Statamic\Support\Arr;
use Statamic\Support\Str;

class Asset extends FileAsset
{
use HasDirtyState {
syncOriginal as traitSyncOriginal;
}

public function syncOriginal()
{
// FileAsset overrides the trait method in order to add the "pending
// data" logic. We don't need it here since everything comes from
// the model so we'll just use the original trait method again.
return $this->traitSyncOriginal();
}

protected $existsOnDisk = false;
protected $removedData = [];

Expand All @@ -22,7 +35,8 @@ public static function fromModel(Model $model)
return (new static())
->container($model->container)
->path(Str::replace('//', '/', $model->folder.'/'.$model->basename))
->hydrateMeta($model->meta);
->hydrateMeta($model->meta)
->syncOriginal();
}

public function meta($key = null)
Expand Down
2 changes: 1 addition & 1 deletion src/Entries/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function fromModel(Model $model)
}
}

return $entry;
return $entry->syncOriginal();
}

public function toModel()
Expand Down
3 changes: 1 addition & 2 deletions src/Taxonomies/Term.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ public static function fromModel(Model $model)
unset($data['collection']);
}

$term->syncOriginal();
$term->data($data);

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

return $term;
return $term->syncOriginal();
}

public function toModel()
Expand Down
2 changes: 1 addition & 1 deletion tests/Data/Entries/EntryQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function entry_is_found_within_all_created_entries_using_entry_facade_wit
public function entry_is_found_within_all_created_entries_and_select_query_columns_are_set_using_entry_facade_with_find_method_with_columns_param()
{
$searchedEntry = $this->createDummyCollectionAndEntries();
$columns = ['title'];
$columns = ['foo', 'collection'];
jasonvarga marked this conversation as resolved.
Show resolved Hide resolved
$retrievedEntry = Entry::query()->find($searchedEntry->id(), $columns);

$retrievedEntry->model(null);
Expand Down
3 changes: 3 additions & 0 deletions tests/Entries/EntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class EntryTest extends TestCase
/** @test */
public function it_loads_from_entry_model()
{
Collection::make('blog')->title('blog')->save();

$model = new EntryModel([
'collection' => 'blog',
'slug' => 'the-slug',
'data' => [
'foo' => 'bar',
Expand Down
Loading