Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
DependencyCheck Class Reference
Inheritance diagram for DependencyCheck:

Public Member Functions

 __construct (DependencyReadinessCheck $dependencyReadinessCheck, UninstallDependencyCheck $uninstallDependencyCheck, ModuleStatusFactory $moduleStatusFactory)
 
 componentDependencyAction ()
 
 uninstallDependencyCheckAction ()
 
 enableDisableDependencyCheckAction ()
 

Protected Attributes

 $dependencyReadinessCheck
 
 $uninstallDependencyCheck
 
 $moduleStatus
 

Detailed Description

Class DependencyCheck

Checks dependencies.

Definition at line 22 of file DependencyCheck.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( DependencyReadinessCheck  $dependencyReadinessCheck,
UninstallDependencyCheck  $uninstallDependencyCheck,
ModuleStatusFactory  $moduleStatusFactory 
)

Constructor

Parameters
DependencyReadinessCheck$dependencyReadinessCheck
UninstallDependencyCheck$uninstallDependencyCheck
ModuleStatusFactory$moduleStatusFactory

Definition at line 52 of file DependencyCheck.php.

56  {
57  $this->dependencyReadinessCheck = $dependencyReadinessCheck;
58  $this->uninstallDependencyCheck = $uninstallDependencyCheck;
59  $this->moduleStatus = $moduleStatusFactory->create();
60  }

Member Function Documentation

◆ componentDependencyAction()

componentDependencyAction ( )

Verifies component dependency

Returns
JsonModel

Definition at line 67 of file DependencyCheck.php.

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  }

◆ enableDisableDependencyCheckAction()

enableDisableDependencyCheckAction ( )

Verifies component dependency for enable/disable actions

Returns
JsonModel

Definition at line 115 of file DependencyCheck.php.

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  }

◆ uninstallDependencyCheckAction()

uninstallDependencyCheckAction ( )

Verifies component dependency for uninstall

Returns
JsonModel

Definition at line 90 of file DependencyCheck.php.

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  }

Field Documentation

◆ $dependencyReadinessCheck

$dependencyReadinessCheck
protected

Definition at line 29 of file DependencyCheck.php.

◆ $moduleStatus

$moduleStatus
protected

Definition at line 43 of file DependencyCheck.php.

◆ $uninstallDependencyCheck

$uninstallDependencyCheck
protected

Definition at line 36 of file DependencyCheck.php.


The documentation for this class was generated from the following file: