Magento 2 Module Uninstall Scripts
Any module installed using composer can be uninstalled using
bin/magento module:uninstall [Vendor]_[ModuleName]
During the uninstall process Magento looks for an uninstall class located in the module being uninstalled. Specifically for Setup/Uninstall.php. It does this in the \Magento\Setup\Model\UninstallCollector.php class (collectUninstall()).
If it finds an Uninstall file and that file is a subclass of Magento\Framework\Setup\UninstallInterface it will run it very similar to how it runs install files. What does an Uninstall script look like?
What can i use this for?
Well if your module installed some database tables you could use this to remove those tables from the database as if the module was never installed in the first place.
This is in stark contrast to Magento 1.x whereby uninstalling a module left traces of itself that you had to clear up manually.
Note At time of writing there seems to be a bug in Magento whereby the uninstall process never completes leaving the site in maintenance mode. See Github issue that i raised earlier.
Like this post? Share it :)