ideas
ideas copied to clipboard
Give addons a way to clean up before they are removed
Using composer remove to remove an addon only removes the addon's code. It does not remove data that the addon as sprinkled into the system. It would be nice for Statamic to include a call in the addon API to request a cleanup of data as the addon is removed. Of course, doing this should be optional, the user may want to keep the data, but if a user is trying to make a clean break it would be helpful to give them a way to do so.
Another approach might be to allow addons to specify some removal instructions that get shown in addition to the composer remove command when a user looks at the description of an installed addon. Addon authors could use these instructions to alert users to the data they may leave behind in an installation, so that the user can at least manually clean those out if desired.
I'm new here, so I may be missing something, but right now, it looks like there is no way to know, for sure, that you have removed all the bits of an addon data that might be sprinkled in your installation.
So, a bit more reflection (and discord guidance) helps me see that this is probably not a technical change request for Statamic, since the whole addon mechanism is really composer. Rather, this is probably just a plea to addon authors that they include in their readme file a list of the things their addon adds to the Statamic site's directory so that users of the addon might be able to confidently clear this stuff away if they ever decide to remove the addon.
Out of curiosity, which addon were you uninstalling?
Right now, we would generally recommend that addon developers include uninstall instructions in their documentation. Maybe we can do something clever with Composer in the future though.
It may be possible that we could add a pre-package-uninstall to statamic/statamic's composer file which could call something in the addon before it gets uninstalled. I'm not sure though.
Definitely the simplest solution for now though would be to request that the addon developer have some uninstallation instructions, or even a please addonname:uninstall command to clean itself up.
Although I can understand that addon developers might want to focus their efforts on how it works when it is installed rather than spending time on people that won't be using their product.
Either way it would be up to the addon developer to build something that would clean up things.
The addon I tried and removed was rias/statamic-redirect, which left stuff in both /storage and /contents. I caught both of those and deleted the directories, but I could easily imagine other addons leaving things in sneakier places or leaving bits of config hanging around. This addon had no information about what might be left for cleanup after composer remove.
I realize this would be up to the developer. I am just suggesting that Statamic do something to encourage this practice, even if it is only (for now) documentation.
I like please addon:uninstall as a practice, but this would have to be done before composer remove addon, right? In this case, the instructions on the addon page sidebar, which currently show composer remove addon might have to be aware of the existence of the uninstall and show please addon:uninstall instead. Also, would the uninstall be able to do the composer remove automatically, or would that be an additional step?
~Done in statamic/cms#11057~