processwire / processwire-requests

ProcessWire feature requests.
39 stars 0 forks source link

Use $page->meta() rather than page name to store metadata for pages in trash #441

Open Toutouwai opened 2 years ago

Toutouwai commented 2 years ago

Short description of the enhancement

When a page has been sent to the trash, PW currently uses the page name to store some metadata about the page in case it later needs to be restored to its original position.

2022-05-01_150139

Using the page name for this purpose is not ideal in my opinion for a couple of reasons.

1. It's not intuitive or obvious that PW would use the page name for this purpose. I don't think this usage is documented anywhere and a PW developer will only discover this use of the page name if they happen to be poking around on the Settings tab of pages that are in the trash, which is not something everyone will do.

2. You have to be careful if you are using the API to set page names that you give special treatment pages that are in the trash. I frequently set page names in a Pages::saveReady() hook but this hook gets called immediately after a page is trashed and so if you don't remember to specifically test if the page is trashed then you can inadvertently destroy the metadata needed for the trash restore feature. But as per item 1, why would it occur to a developer that a page's name would be used by trashed pages in this way?

It seems like $page->meta() would be better suited to the purpose of storing metadata about trashed pages and the metadata would be less vulnerable there.