Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ModuleUninstaller.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Setup\Model;
7 
9 use Symfony\Component\Console\Output\OutputInterface;
10 
15 {
19  private $objectManager;
20 
24  private $remove;
25 
29  private $collector;
30 
34  private $setupFactory;
38  private $patchApplier;
39 
49  public function __construct(
50  ObjectManagerProvider $objectManagerProvider,
51  \Magento\Framework\Composer\Remove $remove,
52  UninstallCollector $collector,
53  \Magento\Setup\Module\SetupFactory $setupFactory
54  ) {
55  $this->objectManager = $objectManagerProvider->get();
56  $this->remove = $remove;
57  $this->collector = $collector;
58  $this->setupFactory = $setupFactory;
59  }
60 
64  private function getPatchApplier()
65  {
66  if (!$this->patchApplier) {
67  $this->patchApplier = $this->objectManager->get(PatchApplier::class);
68  }
69 
70  return $this->patchApplier;
71  }
72 
80  public function uninstallData(OutputInterface $output, array $modules)
81  {
82  $uninstalls = $this->collector->collectUninstall($modules);
83  $setupModel = $this->setupFactory->create();
84  $resource = $this->objectManager->get(\Magento\Framework\Module\ModuleResource::class);
85  foreach ($modules as $module) {
86  if (isset($uninstalls[$module])) {
87  $output->writeln("<info>Removing data of $module</info>");
88  $uninstalls[$module]->uninstall(
89  $setupModel,
90  new ModuleContext($resource->getDbVersion($module) ?: '')
91  );
92  }
93 
94  $this->getPatchApplier()->revertDataPatches($module);
95  }
96  }
97 
105  public function uninstallCode(OutputInterface $output, array $modules)
106  {
107  $output->writeln('<info>Removing code from Magento codebase:</info>');
108  $packages = [];
110  $packageInfo = $this->objectManager->get(\Magento\Framework\Module\PackageInfoFactory::class)->create();
111  foreach ($modules as $module) {
112  $packages[] = $packageInfo->getPackageName($module);
113  }
114  $this->remove->remove($packages);
115  }
116 }
__construct(ObjectManagerProvider $objectManagerProvider, \Magento\Framework\Composer\Remove $remove, UninstallCollector $collector, \Magento\Setup\Module\SetupFactory $setupFactory)
$resource
Definition: bulk.php:12
uninstallData(OutputInterface $output, array $modules)