Searching the codebase for UninstallInterface
gives \Magento\Setup\Model\UninstallCollector
.
If you search for UninstallCollector
then, you'll find that's used in \Magento\Setup\Console\Command\ModuleUninstallCommand
. Particularly relevant:
$uninstalls = $this->collector->collectUninstall();
$setupModel = $this->objectManager->get('Magento\Setup\Module\Setup');
foreach ($modules as $module) {
if (isset($uninstalls[$module])) {
$output->writeln("<info>Removing data of $module</info>");
$uninstalls[$module]->uninstall(
$setupModel,
new ModuleContext($this->moduleResource->getDbVersion($module) ?: '')
);
} else {
$output->writeln("<info>No data to clear in $module</info>");
}
}
Put together, we can surmise:
- Your module should contain an
Uninstall
class at {module}\Setup\Uninstall.php
.
- This class should implement
Magento\Framework\Setup\UninstallInterface
.
- This class should have an
uninstall
method containing any necessary logic.
- The same objects and methods are available to you as in any setup or upgrade script.
So, here's your skeleton:
<?php
namespace \Custom\Module\Setup;
class Uninstall implements \Magento\Framework\Setup\UninstallInterface
{
/**
* Module uninstall code
*
* @param \Magento\Framework\Setup\SchemaSetupInterface $setup
* @param \Magento\Framework\Setup\ModuleContextInterface $context
* @return void
*/
public function uninstall(
\Magento\Framework\Setup\SchemaSetupInterface $setup,
\Magento\Framework\Setup\ModuleContextInterface $context
) {
$setup->startSetup();
// Uninstall logic here
$setup->endSetup();
}
}
Remove any tables, columns, or data using the appropriate methods. See \Magento\Framework\DB\Adapter\AdapterInterface
, available as $setup->getConnection()
.
it says in the documentation you linked, this:
This command works only with modules defined as Composer packages.
If you did not install the module via composer, it won't work.
You can only disable it via bin/magento module:disable SP_Gridthumbs
.
To remove the module, remove the folder SP/Gridthumbs
, remove the record with module = 'SP_Gridthumbs' from the table setup_module
and remove any other tables or records added by the install of the module.
Also remove the line with SP_Gridthumbs
from app/etc/config.php
Best Answer
You can uninstall a module through composer if it was installed using composer. If yes then issue command:
-r flag removes module data. then issue:
If module was not installed through composer:
app/code/<Vendor>/<Module>
Run command