Preserve asset data from fields when running statamic:assets:meta generation command #6854
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #4595
The fix in the issue description works fine. It also affects
focusbeing saved as it goes underdataproperty too.I thought that
generateMetamethod inAssetclass already accounts for existing asset data and merges it together here:https://github.com/ncla/cms/blob/3ed1e592b309f34379db07fb95af406b97fe87f8/src/Assets/Asset.php#L235-L253
But with line
$meta = ['data' => $this->data->all()];, as far as I understood it is for use cases where you are creatingAssetobject manually? So as that is not the case here, we have to simply hydrate the asset, asAssetRepository::save()does not account for such situation.It is an additional call to file system for generating meta. No matter how I look at it, the command will have to look up the meta file, unless we can pull this
datafrom stache/cache or something?I think most people are fine with this behavior (?) so there's no need to include a separate command flag like
--without-hydrationfor disregarding existing data, or to make the command create less file system calls. I am just wondering as there's lately been some issues with the asset hydration, so just want to be considerate.As bonus I have added tests to sleep better at night. Borrowed, inspired logic from other asset tests.