Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
JobComponentUninstall.php
Go to the documentation of this file.
1 <?php
7 
11 
18 {
22  const COMPONENT_NAME = 'name';
23 
27  const DATA_OPTION = 'dataOption';
28 
32  protected $objectManager;
33 
37  private $updater;
38 
42  private $composerInformation;
43 
47  private $moduleUninstall;
48 
52  private $themeUninstall;
53 
57  private $queue;
58 
73  public function __construct(
74  \Magento\Framework\Composer\ComposerInformation $composerInformation,
75  Helper\ModuleUninstall $moduleUninstall,
76  Helper\ThemeUninstall $themeUninstall,
77  \Magento\Setup\Model\ObjectManagerProvider $objectManagerProvider,
78  \Symfony\Component\Console\Output\OutputInterface $output,
79  \Magento\Setup\Model\Cron\Queue $queue,
81  \Magento\Setup\Model\Updater $updater,
82  $name,
83  $params = []
84  ) {
85  $this->composerInformation = $composerInformation;
86  $this->moduleUninstall = $moduleUninstall;
87  $this->themeUninstall = $themeUninstall;
88  $this->objectManager = $objectManagerProvider->get();
89  $this->updater = $updater;
90  $this->queue = $queue;
91  parent::__construct($output, $status, $objectManagerProvider, $name, $params);
92  }
93 
100  public function execute()
101  {
102  if (!isset($this->params['components']) || !is_array($this->params['components'])) {
103  $this->status->toggleUpdateError(true);
104  throw new \RuntimeException('Job parameter format is incorrect');
105  }
106  $components = $this->params['components'];
107  foreach ($components as $component) {
108  $this->executeComponent($component);
109  }
110  $this->queue->addJobs(
111  [['name' => JobFactory::JOB_STATIC_REGENERATE, 'params' => []]]
112  );
113  $errorMessage = $this->updater->createUpdaterTask($components, Updater::TASK_TYPE_UNINSTALL);
114  if ($errorMessage) {
115  $this->status->toggleUpdateError(true);
116  throw new \RuntimeException($errorMessage);
117  }
118  }
119 
127  private function executeComponent(array $component)
128  {
129  if (!isset($component[self::COMPONENT_NAME])) {
130  $this->status->toggleUpdateError(true);
131  throw new \RuntimeException('Job parameter format is incorrect');
132  }
133 
134  $componentName = $component[self::COMPONENT_NAME];
135  $installedPackages = $this->composerInformation->getInstalledMagentoPackages();
136  if (isset($installedPackages[$componentName]['type'])) {
137  $type = $installedPackages[$componentName]['type'];
138  } else {
139  $this->status->toggleUpdateError(true);
140  throw new \RuntimeException('Component type not set');
141  }
142 
143  if (!in_array($type, [
148  ])) {
149  $this->status->toggleUpdateError(true);
150  throw new \RuntimeException('Unknown component type');
151  }
152 
153  switch ($type) {
155  $dataOption = isset($this->params[self::DATA_OPTION]) && $this->params[self::DATA_OPTION] === 'true';
156  $this->moduleUninstall->uninstall(
157  $this->output,
158  $componentName,
159  $dataOption
160  );
161  break;
163  $this->themeUninstall->uninstall($this->output, $componentName);
164  break;
165  }
166  }
167 }
__construct(\Magento\Framework\Composer\ComposerInformation $composerInformation, Helper\ModuleUninstall $moduleUninstall, Helper\ThemeUninstall $themeUninstall, \Magento\Setup\Model\ObjectManagerProvider $objectManagerProvider, \Symfony\Component\Console\Output\OutputInterface $output, \Magento\Setup\Model\Cron\Queue $queue, \Magento\Setup\Model\Cron\Status $status, \Magento\Setup\Model\Updater $updater, $name, $params=[])
output($string, $level=INFO, $label='')
$queue
Definition: queue.php:21
$type
Definition: item.phtml:13