Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DependencyCheck.php
Go to the documentation of this file.
1 <?php
8 
13 use Zend\Json\Json;
14 use Zend\Mvc\Controller\AbstractActionController;
15 use Zend\View\Model\JsonModel;
16 
22 class DependencyCheck extends AbstractActionController
23 {
30 
37 
43  protected $moduleStatus;
44 
52  public function __construct(
55  ModuleStatusFactory $moduleStatusFactory
56  ) {
57  $this->dependencyReadinessCheck = $dependencyReadinessCheck;
58  $this->uninstallDependencyCheck = $uninstallDependencyCheck;
59  $this->moduleStatus = $moduleStatusFactory->create();
60  }
61 
67  public function componentDependencyAction()
68  {
70  $packages = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
71  $data = [];
72  foreach ($packages as $package) {
73  $data[] = implode(' ', $package);
74  }
75  $dependencyCheck = $this->dependencyReadinessCheck->runReadinessCheck($data);
76  $data = [];
77  if (!$dependencyCheck['success']) {
79  $data['errorMessage'] = $dependencyCheck['error'];
80  }
81  $data['responseType'] = $responseType;
82  return new JsonModel($data);
83  }
84 
91  {
93  $packages = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
94 
95  $packagesToDelete = [];
96  foreach ($packages as $package) {
97  $packagesToDelete[] = $package['name'];
98  }
99 
100  $dependencyCheck = $this->uninstallDependencyCheck->runUninstallReadinessCheck($packagesToDelete);
101  $data = [];
102  if (!$dependencyCheck['success']) {
104  $data['errorMessage'] = $dependencyCheck['error'];
105  }
106  $data['responseType'] = $responseType;
107  return new JsonModel($data);
108  }
109 
116  {
118  $data = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
119 
120  try {
121  if (empty($data['packages'])) {
122  throw new \Exception('No packages have been found.');
123  }
124 
125  if (empty($data['type'])) {
126  throw new \Exception('Can not determine the flow.');
127  }
128 
129  $modules = $data['packages'];
130 
131  $isEnable = ($data['type'] !== 'disable');
132 
133  $modulesToChange = [];
134  foreach ($modules as $module) {
135  if (!isset($module['name'])) {
136  throw new \Exception('Can not find module name.');
137  }
138  $modulesToChange[] = $module['name'];
139  }
140 
141  $constraints = $this->moduleStatus->checkConstraints($isEnable, $modulesToChange);
142  $data = [];
143 
144  if ($constraints) {
145  $data['errorMessage'] = "Unable to change status of modules because of the following constraints: "
146  . implode("<br>", $constraints);
148  }
149  } catch (\Exception $e) {
151  $data['errorMessage'] = $e->getMessage();
152  }
153 
154  $data['responseType'] = $responseType;
155  return new JsonModel($data);
156  }
157 }
__construct(DependencyReadinessCheck $dependencyReadinessCheck, UninstallDependencyCheck $uninstallDependencyCheck, ModuleStatusFactory $moduleStatusFactory)