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();
        }
    }

1 Answer 1

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
);
5
  • I have an Uninstall Class in my module and the commands in there are getting called when uninstalling. But I am not doing anything manually with the configuration in there. Does that mean I have to remove the normal configuration data by hand in the Uninstall file? How do I do that?
    – alobeejay
    Commented Jun 26, 2017 at 12:08
  • Can you post your code? Commented Jun 26, 2017 at 14:06
  • I don't have any code that deletes the configuration. That is what I need.
    – alobeejay
    Commented Jun 27, 2017 at 10:46
  • Can you please share your uninstall class? Commented Jun 27, 2017 at 10:47
  • Sure. I edited my post above.
    – alobeejay
    Commented Jun 27, 2017 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.