Skip to content

Commit ebe1948

Browse files
author
Ivan Gavryshko
committed
MAGETWO-43265: An exception if try to get to the Web Wizard without writable file permissions
- simplified check if application is installed in setup to avoid using ObjectManager - moved dependency related checks from Environment to DependencyCheck controller
1 parent bce20df commit ebe1948

File tree

7 files changed

+181
-191
lines changed

7 files changed

+181
-191
lines changed

setup/config/di.config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
'Magento\Setup\Controller\ReadinessCheckInstaller',
2020
'Magento\Setup\Controller\ReadinessCheckUpdater',
2121
'Magento\Setup\Controller\Environment',
22+
'Magento\Setup\Controller\DependencyCheck',
2223
'Magento\Setup\Controller\DatabaseCheck',
2324
'Magento\Setup\Controller\AddDatabase',
2425
'Magento\Setup\Controller\WebConfiguration',

setup/pub/magento/setup/readiness-check.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ angular.module('readiness-check', [])
2424
};
2525
switch ($state.current.type) {
2626
case 'uninstall':
27-
$scope.dependencyUrl = 'index.php/environment/uninstall-dependency-check';
27+
$scope.dependencyUrl = 'index.php/dependency-check/uninstall-dependency-check';
2828
if ($localStorage.packages) {
2929
$scope.componentDependency.packages = $localStorage.packages;
3030
}
3131
break;
3232
case 'enable':
3333
case 'disable':
34-
$scope.dependencyUrl = 'index.php/environment/enable-disable-dependency-check';
34+
$scope.dependencyUrl = 'index.php/dependency-check/enable-disable-dependency-check';
3535
if ($localStorage.packages) {
3636
$scope.componentDependency.packages = {
3737
type: $state.current.type,
@@ -40,7 +40,7 @@ angular.module('readiness-check', [])
4040
}
4141
break;
4242
default:
43-
$scope.dependencyUrl = 'index.php/environment/component-dependency';
43+
$scope.dependencyUrl = 'index.php/dependency-check/component-dependency';
4444
if ($localStorage.packages) {
4545
$scope.componentDependency.packages = $localStorage.packages;
4646
}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Setup\Controller;
8+
9+
use Magento\Setup\Model\DependencyReadinessCheck;
10+
use Magento\Setup\Model\UninstallDependencyCheck;
11+
use Zend\Json\Json;
12+
use Zend\Mvc\Controller\AbstractActionController;
13+
use Zend\View\Model\JsonModel;
14+
use Magento\Framework\Filesystem;
15+
use Magento\Setup\Model\ModuleStatusFactory;
16+
use Magento\Framework\Module\Status;
17+
18+
/**
19+
* Class DependencyCheck
20+
*
21+
* Checks dependencies.
22+
*/
23+
class DependencyCheck extends AbstractActionController
24+
{
25+
/**
26+
* Dependency Readiness Check
27+
*
28+
* @var DependencyReadinessCheck
29+
*/
30+
protected $dependencyReadinessCheck;
31+
32+
/**
33+
* Uninstall Dependency Readiness Check
34+
*
35+
* @var UninstallDependencyCheck
36+
*/
37+
protected $uninstallDependencyCheck;
38+
39+
/**
40+
* Module/Status Object
41+
*
42+
* @var Status
43+
*/
44+
protected $moduleStatus;
45+
46+
/**
47+
* Constructor
48+
*
49+
* @param DependencyReadinessCheck $dependencyReadinessCheck
50+
* @param UninstallDependencyCheck $uninstallDependencyCheck
51+
* @param ModuleStatusFactory $moduleStatusFactory
52+
*/
53+
public function __construct(
54+
DependencyReadinessCheck $dependencyReadinessCheck,
55+
UninstallDependencyCheck $uninstallDependencyCheck,
56+
ModuleStatusFactory $moduleStatusFactory
57+
) {
58+
$this->dependencyReadinessCheck = $dependencyReadinessCheck;
59+
$this->uninstallDependencyCheck = $uninstallDependencyCheck;
60+
$this->moduleStatus = $moduleStatusFactory->create();
61+
}
62+
63+
/**
64+
* Verifies component dependency
65+
*
66+
* @return JsonModel
67+
*/
68+
public function componentDependencyAction()
69+
{
70+
$responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS;
71+
$packages = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
72+
$data = [];
73+
foreach ($packages as $package) {
74+
$data[] = implode(' ', $package);
75+
}
76+
$dependencyCheck = $this->dependencyReadinessCheck->runReadinessCheck($data);
77+
$data = [];
78+
if (!$dependencyCheck['success']) {
79+
$responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR;
80+
$data['errorMessage'] = $dependencyCheck['error'];
81+
}
82+
$data['responseType'] = $responseType;
83+
return new JsonModel($data);
84+
}
85+
86+
/**
87+
* Verifies component dependency for uninstall
88+
*
89+
* @return JsonModel
90+
*/
91+
public function uninstallDependencyCheckAction()
92+
{
93+
$responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS;
94+
$packages = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
95+
96+
$packagesToDelete = [];
97+
foreach ($packages as $package) {
98+
$packagesToDelete[] = $package['name'];
99+
}
100+
101+
$dependencyCheck = $this->uninstallDependencyCheck->runUninstallReadinessCheck($packagesToDelete);
102+
$data = [];
103+
if (!$dependencyCheck['success']) {
104+
$responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR;
105+
$data['errorMessage'] = $dependencyCheck['error'];
106+
}
107+
$data['responseType'] = $responseType;
108+
return new JsonModel($data);
109+
}
110+
111+
/**
112+
* Verifies component dependency for enable/disable actions
113+
*
114+
* @return JsonModel
115+
*/
116+
public function enableDisableDependencyCheckAction()
117+
{
118+
$responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS;
119+
$data = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
120+
121+
try {
122+
if (empty($data['packages'])) {
123+
throw new \Exception('No packages have been found.');
124+
}
125+
126+
if (empty($data['type'])) {
127+
throw new \Exception('Can not determine the flow.');
128+
}
129+
130+
$modules = $data['packages'];
131+
132+
$isEnable = ($data['type'] !== 'disable');
133+
134+
$modulesToChange = [];
135+
foreach ($modules as $module) {
136+
if (!isset($module['name'])) {
137+
throw new \Exception('Can not find module name.');
138+
}
139+
$modulesToChange[] = $module['name'];
140+
}
141+
142+
$constraints = $this->moduleStatus->checkConstraints($isEnable, $modulesToChange);
143+
$data = [];
144+
145+
if ($constraints) {
146+
$data['errorMessage'] = "Unable to change status of modules because of the following constraints: "
147+
. implode("<br>", $constraints);
148+
$responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR;
149+
}
150+
151+
} catch (\Exception $e) {
152+
$responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR;
153+
$data['errorMessage'] = $e->getMessage();
154+
}
155+
156+
$data['responseType'] = $responseType;
157+
return new JsonModel($data);
158+
}
159+
}

setup/src/Magento/Setup/Controller/Environment.php

Lines changed: 6 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,17 @@
77

88
use Magento\Setup\Model\Cron\ReadinessCheck;
99
use Magento\Setup\Model\CronScriptReadinessCheck;
10-
use Magento\Setup\Model\DependencyReadinessCheck;
11-
use Magento\Setup\Model\UninstallDependencyCheck;
1210
use Magento\Setup\Model\PhpReadinessCheck;
13-
use Zend\Json\Json;
1411
use Zend\Mvc\Controller\AbstractActionController;
1512
use Zend\View\Model\JsonModel;
1613
use Magento\Setup\Model\FilePermissions;
1714
use Magento\Framework\App\Filesystem\DirectoryList;
1815
use Magento\Framework\Filesystem;
19-
use Magento\Setup\Model\ModuleStatusFactory;
20-
use Magento\Framework\Module\Status;
2116

2217
/**
2318
* Class Environment
2419
*
2520
* Provides information and checks about the environment.
26-
*
27-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2821
*/
2922
class Environment extends AbstractActionController
3023
{
@@ -33,6 +26,11 @@ class Environment extends AbstractActionController
3326
*/
3427
const UPDATER_DIR = 'update';
3528

29+
/**
30+
* Path to Magento config
31+
*/
32+
const PATH_TO_CONFIG = '/app/etc/config.php';
33+
3634
/**
3735
* File system
3836
*
@@ -47,61 +45,31 @@ class Environment extends AbstractActionController
4745
*/
4846
protected $cronScriptReadinessCheck;
4947

50-
/**
51-
* Dependency Readiness Check
52-
*
53-
* @var DependencyReadinessCheck
54-
*/
55-
protected $dependencyReadinessCheck;
56-
57-
/**
58-
* Uninstall Dependency Readiness Check
59-
*
60-
* @var UninstallDependencyCheck
61-
*/
62-
protected $uninstallDependencyCheck;
63-
6448
/**
6549
* PHP Readiness Check
6650
*
6751
* @var PhpReadinessCheck
6852
*/
6953
protected $phpReadinessCheck;
7054

71-
/**
72-
* Module/Status Object
73-
*
74-
* @var Status
75-
*/
76-
protected $moduleStatus;
77-
7855
/**
7956
* Constructor
8057
*
8158
* @param FilePermissions $permissions
8259
* @param Filesystem $filesystem
8360
* @param CronScriptReadinessCheck $cronScriptReadinessCheck
84-
* @param DependencyReadinessCheck $dependencyReadinessCheck
85-
* @param UninstallDependencyCheck $uninstallDependencyCheck
8661
* @param PhpReadinessCheck $phpReadinessCheck
87-
* @param ModuleStatusFactory $moduleStatusFactory
8862
*/
8963
public function __construct(
9064
FilePermissions $permissions,
9165
Filesystem $filesystem,
9266
CronScriptReadinessCheck $cronScriptReadinessCheck,
93-
DependencyReadinessCheck $dependencyReadinessCheck,
94-
UninstallDependencyCheck $uninstallDependencyCheck,
95-
PhpReadinessCheck $phpReadinessCheck,
96-
ModuleStatusFactory $moduleStatusFactory
67+
PhpReadinessCheck $phpReadinessCheck
9768
) {
9869
$this->permissions = $permissions;
9970
$this->filesystem = $filesystem;
10071
$this->cronScriptReadinessCheck = $cronScriptReadinessCheck;
101-
$this->dependencyReadinessCheck = $dependencyReadinessCheck;
102-
$this->uninstallDependencyCheck = $uninstallDependencyCheck;
10372
$this->phpReadinessCheck = $phpReadinessCheck;
104-
$this->moduleStatus = $moduleStatusFactory->create();
10573
}
10674

10775
/**
@@ -249,101 +217,4 @@ public function cronScriptAction()
249217
$data['responseType'] = $responseType;
250218
return new JsonModel($data);
251219
}
252-
253-
/**
254-
* Verifies component dependency
255-
*
256-
* @return JsonModel
257-
*/
258-
public function componentDependencyAction()
259-
{
260-
$responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS;
261-
$packages = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
262-
$data = [];
263-
foreach ($packages as $package) {
264-
$data[] = implode(' ', $package);
265-
}
266-
$dependencyCheck = $this->dependencyReadinessCheck->runReadinessCheck($data);
267-
$data = [];
268-
if (!$dependencyCheck['success']) {
269-
$responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR;
270-
$data['errorMessage'] = $dependencyCheck['error'];
271-
}
272-
$data['responseType'] = $responseType;
273-
return new JsonModel($data);
274-
}
275-
276-
/**
277-
* Verifies component dependency for uninstall
278-
*
279-
* @return JsonModel
280-
*/
281-
public function uninstallDependencyCheckAction()
282-
{
283-
$responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS;
284-
$packages = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
285-
286-
$packagesToDelete = [];
287-
foreach ($packages as $package) {
288-
$packagesToDelete[] = $package['name'];
289-
}
290-
291-
$dependencyCheck = $this->uninstallDependencyCheck->runUninstallReadinessCheck($packagesToDelete);
292-
$data = [];
293-
if (!$dependencyCheck['success']) {
294-
$responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR;
295-
$data['errorMessage'] = $dependencyCheck['error'];
296-
}
297-
$data['responseType'] = $responseType;
298-
return new JsonModel($data);
299-
}
300-
301-
/**
302-
* Verifies component dependency for enable/disable actions
303-
*
304-
* @return JsonModel
305-
*/
306-
public function enableDisableDependencyCheckAction()
307-
{
308-
$responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS;
309-
$data = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
310-
311-
try {
312-
if (empty($data['packages'])) {
313-
throw new \Exception('No packages have been found.');
314-
}
315-
316-
if (empty($data['type'])) {
317-
throw new \Exception('Can not determine the flow.');
318-
}
319-
320-
$modules = $data['packages'];
321-
322-
$isEnable = ($data['type'] !== 'disable');
323-
324-
$modulesToChange = [];
325-
foreach ($modules as $module) {
326-
if (!isset($module['name'])) {
327-
throw new \Exception('Can not find module name.');
328-
}
329-
$modulesToChange[] = $module['name'];
330-
}
331-
332-
$constraints = $this->moduleStatus->checkConstraints($isEnable, $modulesToChange);
333-
$data = [];
334-
335-
if ($constraints) {
336-
$data['errorMessage'] = "Unable to change status of modules because of the following constraints: "
337-
. implode("<br>", $constraints);
338-
$responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR;
339-
}
340-
341-
} catch (\Exception $e) {
342-
$responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR;
343-
$data['errorMessage'] = $e->getMessage();
344-
}
345-
346-
$data['responseType'] = $responseType;
347-
return new JsonModel($data);
348-
}
349220
}

0 commit comments

Comments
 (0)