swiftmade / statamic-clear-assets

Clean up unused images and assets from your Statamic site. Saves storage, keep things tidy.
MIT License
15 stars 4 forks source link

Compability with revisions? #16

Open mmodler opened 7 months ago

mmodler commented 7 months ago

Hey,

thanks for this great addon! Yesterday i was thinking about using it in a bigger project with revisions. As far as i see there might be issues with revisions? I looked at https://statamic.dev/revisions#workflow and i think the working copy might be a problem:

Saving a published entry https://statamic.dev/revisions#saving-a-published-entry The working copy is saved. The actual entry is not saved.

It is therefore possible that I am using an asset in the working copy, which may be deleted. When I then publish the entry, I am surprised that the asset is gone.

Of course, this is an edge case and you could also argue that "in use" is the same as "published".

Hm, could the solution be to scan all working.yaml files in the revisions folder as well?

aozisik commented 7 months ago

Hi @mmodler

Thanks for raising this issue.

I'm not familiar with this revisions feature myself yet. But a quick look at the docs tells me the revisions are stored under content/revisions. The add-on recursively scans the content folder, so any files in revisions folder referencing the assets should be picked up and those assets should be marked as used.

From the docs:

Revision# Revisions are stored as YAML files and include all the data for your entries at the time of revisions, including additional meta data about the author, timestamp, and so on. Revisions can be previewed and restored as the working copy so you can edit and/or publish them if you wish.

Please let me know if this is not how it works, and the assets in the working copy are not picked up by the add-on as being used.

mmodler commented 7 months ago

I don't think its so easy:

aozisik commented 7 months ago

@mmodler these are valid points, unfortunately I don't have answers. I'm not using revisions actively myself yet.

About every asset ever used in the past part, how would you expect it to work? We could perhaps not protect assets in past revisions, and plus the package user could use the minimum_age_in_days setting to preserve assets uploaded recently (in case they want to roll back or something).

Would you be willing to contribute a PR for this?