How to disable module programmatically using UpgradeData script?
Edit 2
Code that I'm trying to use to disable modules:
<?php
namespace Config\Bakalland\Setup;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Config\Model\ResourceModel\Config;
use Magento\Framework\Module\StatusFactory;
class UpgradeData implements UpgradeDataInterface
{
/**
* @var StatusFactory
*/
protected $moduleStatusFactory;
/**
* UpgradeData constructor
*
* @param StatusFactory $moduleStatusFactory
*/
public function __construct(StatusFactory $moduleStatusFactory)
{
$this->moduleStatusFactory = $moduleStatusFactory->create();
}
/**
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
*/
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
if (version_compare($context->getVersion(), '2.1.22', '<')) {
$this->moduleStatusFactory->setIsEnabled(false, ['Magento_Downloadable', 'Magento_Paypal', 'Magento_Vault']);
}
$setup->endSetup();
}
}