We have created an APP for Nextcloud which works resonably well. We store some information in both the system values and the app values which works great. However upon deinstallation of the APP i would like to cleanup properly as to not leave unnecessary configs behind.
For this i looked into the repair-steps where there is a “uninstall”-hook available which could be used for this. I however have some questions regarding this topic:
The uninstall hook seems to only be called on “disable” and not on “remove”. Is this intended and therefore the expected behavior would be to delete all data on “disable”?
A lot of official APPs do not seem to implement the “uninstall”-hook and I am wondering what the official stance on data/config cleanup is and how this is implemented in other apps. Is there a best practice?
you face a general problem here. In NC the notion of enabling and installing is somewhat intervened. This has to do with the fact, that an administrator is generally allowed (and encouraged to a certain degree) to not only use the NC app store (where the update has control over install/uninstall), but to use the zip archive directly or plainly copy the sources of an app to the NC install. Then, the admin only needs to enable the app. In fact, the Updater app also just downloads, unpacks, and enables an app if you click on install.
Upon enabling, the core checks if all DB migrations have been deployed. If not, these are carried out. So, the actual install process is somewhat hidden from the user and admin.
For the uninstall this notion imposes the problem, that the core allows only to disable the app. This removes the app’s code from the bootstrap process. I am not aware for the admin to tell the core that the app is to be permanently disabled. This is especially a problem as it is rather often that an app (from the community) breaks and needs some fixing. To keep the main server running, you can temporarily disable the app in question. It would be fatal if the core would remove all app data in the event.
The official apps (from NC company) are less effected by the problem as these are typically better tested and maintained. Thus there is typically no need to uninstall them. Either the admin uses them or not, which will not increase the footprint much.
According to the docs, the uninstall will be called upon disabling as well. Thus, I’d be careful with destructive operations, to be honest.
So, long story short: I am not aware of a clean uninstall way in the NC ecosystem. Maybe someone from the NC company can shed some light on how this was/is intended.
@christianlupus That’s what I feared was the case. My empirical experiments even show that uninstall is called only on “disable” and not on “remove” contradicting the docs but maybe i did something wrong in my tests or misunderstood the documentation.
I really do not like when apps (in general) do not clean up after themselves which leads to incremental slowdown over time.
I agree with you that removing app data on “disable” would probably not be a good idea since disabling an app can come in handy for many reasons and might only be temporary.
So i will probably need to think of a app-specific solution on how i can cleanup storage in a sensible manner.
Although the slight hope remains that someone from NC offers a solution to this dilemma
This probably has technical reasons. I don’t think nextcloud ever calls code of a disabled app, which the app AFAIK is when it is being removed. Hooks are only registered for enabled apps.
While it would be possible to call this hook specifically for a disabled app on it’s removal, what should happen for example when removing an app not compatible with the current nextcloud version ? There is a good chance the auto-wiring for the uninstall hook class would not even work. And then we would be in a situation, where sometimes data gets deleted on uninstall and sometimes not.
I personally think an acceptable solution would be to include a couple sql statements in the app readme, that scrubs the database of any data of the app for admins that really want to delete every trace of an app (I personally do not mind, i think it is unlikely it has a noticeable effect on performance to leave it in the db).