1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup\Model;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\Module\ModuleList\Loader;
use Magento\Setup\Module\DataSetupFactory;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Used to uninstall registry from the database and deployment config
*/
class ModuleRegistryUninstaller
{
/**
* @var DataSetupFactory
*/
private $dataSetupFactory;
/**
* @var DeploymentConfig
*/
private $deploymentConfig;
/**
* @var DeploymentConfig\Writer
*/
private $writer;
/**
* @var Loader
*/
private $loader;
/**
* Constructor
*
* @param DataSetupFactory $dataSetupFactory
* @param DeploymentConfig $deploymentConfig
* @param DeploymentConfig\Writer $writer
* @param Loader $loader
*/
public function __construct(
DataSetupFactory $dataSetupFactory,
DeploymentConfig $deploymentConfig,
DeploymentConfig\Writer $writer,
Loader $loader
) {
$this->dataSetupFactory = $dataSetupFactory;
$this->deploymentConfig = $deploymentConfig;
$this->writer = $writer;
$this->loader = $loader;
}
/**
* Removes module from setup_module table
*
* @param OutputInterface $output
* @param string[] $modules
* @return void
*/
public function removeModulesFromDb(OutputInterface $output, array $modules)
{
$output->writeln(
'<info>Removing ' . implode(', ', $modules) . ' from module registry in database</info>'
);
/** @var \Magento\Framework\Setup\ModuleDataSetupInterface $setup */
$setup = $this->dataSetupFactory->create();
foreach ($modules as $module) {
$setup->deleteTableRow('setup_module', 'module', $module);
}
}
/**
* Removes module from deployment configuration
*
* @param OutputInterface $output
* @param string[] $modules
* @return void
*/
public function removeModulesFromDeploymentConfig(OutputInterface $output, array $modules)
{
$output->writeln(
'<info>Removing ' . implode(', ', $modules) . ' from module list in deployment configuration</info>'
);
$configuredModules = $this->deploymentConfig->getConfigData(
\Magento\Framework\Config\ConfigOptionsListConstants::KEY_MODULES
);
$existingModules = $this->loader->load($modules);
$newModules = [];
foreach (array_keys($existingModules) as $module) {
$newModules[$module] = isset($configuredModules[$module]) ? $configuredModules[$module] : 0;
}
$this->writer->saveConfig(
[
\Magento\Framework\Config\File\ConfigFilePool::APP_CONFIG =>
[\Magento\Framework\Config\ConfigOptionsListConstants::KEY_MODULES => $newModules]
],
true
);
}
}