1

I have my own module installed via composer and I can uninstall it with

php bin/magento module:uninstall XXX_XXX

But when I reinstall the module the configuration (values in system.xml) is still the same as it was setup while it was installed before. Do I have to remove the configurations manually? How?

EDIT: My current Uninstall class:

<?php

namespace XXXX\XXXXX\Setup;

use Magento\Framework\Setup\UninstallInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;

    class Uninstall implements UninstallInterface
    {
        public function uninstall(SchemaSetupInterface $setup, ModuleContextInterface $context) {
            $setup->startSetup();

            $connection = $setup->getConnection();
            $connection->dropTable($connection->getTableName('mytable_data'));

            $setup->endSetup();
        }
    }
alobeejay
  • 467
  • 7
  • 18

1 Answers1

3

The uninstall-command actually only removes anything when you invoke it with --remove-data and your module has an Uninstall class that implements Magento\Framework\Setup\UninstallInterface. I believe if you want to remove configuration values, you can also do this here.

The official documentation is a place to start: http://devdocs.magento.com/guides/v2.0/install-gde/install/cli/install-cli-uninstall-mods.html

EDIT

As far as I can see, the Uninstall class does not have access to the configuration by default, so you should define an own constructor to fix this. Code is shortened and untested:

<?php

class Uninstall implements UninstallInterface
{
    /**
     * @var \Magento\Framework\App\Config\ConfigResource\ConfigInterface
     */
    protected $resourceConfig;

    public function __construct(  
        \Magento\Framework\App\Config\ConfigResource\ConfigInterface $resourceConfig
    ) {
        $this->resourceConfig = $resourceConfig;
    }

    ...
}

Then, in your uninstall()-function, use that interface's deleteConfig() method to delete your configuration:

$this->resourceConfig->deleteConfig(
    'my/config_path',
    \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 
    \Magento\Store\Model\Store::DEFAULT_STORE_ID
);
sv3n
  • 11,657
  • 7
  • 40
  • 73
simonthesorcerer
  • 4,813
  • 2
  • 19
  • 32