Skip to content

Commit 49a08f2

Browse files
MAGETWO-56873: B2B does not supports in Web Setup Wizard
1 parent 798ab00 commit 49a08f2

File tree

3 files changed

+71
-67
lines changed

3 files changed

+71
-67
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function installedSystemPackageAction()
7171
{
7272
$data = [];
7373
try {
74-
$data['packages'] = $this->systemPackage->getInstalledSystemPackages([]);
74+
$data['packages'] = $this->systemPackage->getInstalledSystemPackages();
7575
$data['responseType'] = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS;
7676
} catch (\Exception $e) {
7777
$data['error'] = $e->getMessage();

setup/src/Magento/Setup/Model/SystemPackage.php

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class SystemPackage
3131
*/
3232
private $composerInfo;
3333

34+
const EDITION_COMMUNITY = 'magento/product-community-edition';
35+
const EDITION_ENTERPRISE = 'magento/product-enterprise-edition';
36+
const EDITION_B2B = 'magento/product-b2b-edition';
37+
3438
/**
3539
* Constructor
3640
*
@@ -58,8 +62,7 @@ public function getPackageVersions()
5862
$currentEE = $currentCE;
5963

6064
$result = [];
61-
$systemPackages = [];
62-
$systemPackages = $this->getInstalledSystemPackages($systemPackages);
65+
$systemPackages = $this->getInstalledSystemPackages();
6366
foreach ($systemPackages as $systemPackage) {
6467
$systemPackageInfo = $this->infoCommand->run($systemPackage);
6568
if (!$systemPackageInfo) {
@@ -68,11 +71,11 @@ public function getPackageVersions()
6871

6972
$versions = $this->getSystemPackageVersions($systemPackageInfo);
7073

71-
if ($systemPackageInfo['name'] == 'magento/product-community-edition') {
74+
if ($systemPackageInfo['name'] == static::EDITION_COMMUNITY) {
7275
$currentCE = $systemPackageInfo[InfoCommand::CURRENT_VERSION];
7376
}
7477

75-
if ($systemPackageInfo['name'] == 'magento/product-enterprise-edition') {
78+
if ($systemPackageInfo['name'] == static::EDITION_ENTERPRISE) {
7679
$currentEE = $systemPackageInfo[InfoCommand::CURRENT_VERSION];
7780
}
7881

@@ -86,13 +89,13 @@ public function getPackageVersions()
8689
];
8790
}
8891

89-
if (!in_array('magento/product-enterprise-edition', $systemPackages)) {
92+
if (!in_array(static::EDITION_ENTERPRISE, $systemPackages)) {
9093
$result = array_merge($this->getAllowedEnterpriseVersions($currentCE), $result);
9194
}
9295

9396
if (
94-
in_array('magento/product-enterprise-edition', $systemPackages)
95-
&& !in_array('magento/product-b2b-edition', $systemPackages)
97+
in_array(static::EDITION_ENTERPRISE, $systemPackages)
98+
&& !in_array(static::EDITION_B2B, $systemPackages)
9699
) {
97100
$result = array_merge($this->getAllowedB2BVersions($currentEE), $result);
98101
}
@@ -111,20 +114,20 @@ public function getPackageVersions()
111114
public function getAllowedEnterpriseVersions($currentCE)
112115
{
113116
$result = [];
114-
$enterpriseVersions = $this->infoCommand->run('magento/product-enterprise-edition');
117+
$enterpriseVersions = $this->infoCommand->run(static::EDITION_ENTERPRISE);
115118
$eeVersions = [];
116119
$maxVersion = '';
117-
if (is_array($enterpriseVersions) && array_key_exists('available_versions', $enterpriseVersions)) {
120+
if (is_array($enterpriseVersions) && array_key_exists(InfoCommand::AVAILABLE_VERSIONS, $enterpriseVersions)) {
118121
$enterpriseVersions = $this->sortVersions($enterpriseVersions);
119-
if (isset($enterpriseVersions['available_versions'][0])) {
120-
$maxVersion = $enterpriseVersions['available_versions'][0];
122+
if (isset($enterpriseVersions[InfoCommand::AVAILABLE_VERSIONS][0])) {
123+
$maxVersion = $enterpriseVersions[InfoCommand::AVAILABLE_VERSIONS][0];
121124
}
122125
$eeVersions = $this->filterEeVersions($currentCE, $enterpriseVersions, $maxVersion);
123126
}
124127

125128
if (!empty($eeVersions)) {
126129
$result[] = [
127-
'package' => 'magento/product-enterprise-edition',
130+
'package' => static::EDITION_ENTERPRISE,
128131
'versions' => $eeVersions,
129132
];
130133
}
@@ -140,7 +143,7 @@ public function getAllowedEnterpriseVersions($currentCE)
140143
public function getAllowedB2BVersions($currentEE)
141144
{
142145
$result = [];
143-
$versions = $this->fetchInfoVersions('magento/product-b2b-edition');
146+
$versions = $this->fetchInfoVersions(static::EDITION_B2B);
144147
$versionsPrepared = [];
145148
$maxVersion = '';
146149

@@ -154,7 +157,7 @@ public function getAllowedB2BVersions($currentEE)
154157

155158
if ($versionsPrepared) {
156159
$result[] = [
157-
'package' => 'magento/product-b2b-edition',
160+
'package' => static::EDITION_B2B,
158161
'versions' => $versionsPrepared,
159162
];
160163
}
@@ -163,8 +166,7 @@ public function getAllowedB2BVersions($currentEE)
163166
}
164167

165168
/**
166-
* Fetching info command response to
167-
* display all correct versions
169+
* Fetching of info command response to display all correct versions
168170
*
169171
* @param string $command
170172
* @return array
@@ -176,6 +178,9 @@ private function fetchInfoVersions($command)
176178
$versions[InfoCommand::CURRENT_VERSION] = isset($versions[InfoCommand::CURRENT_VERSION])
177179
? $versions[InfoCommand::CURRENT_VERSION]
178180
: null;
181+
$versions[InfoCommand::AVAILABLE_VERSIONS] = isset($versions[InfoCommand::AVAILABLE_VERSIONS])
182+
? $versions[InfoCommand::AVAILABLE_VERSIONS]
183+
: null;
179184
$versions[InfoCommand::AVAILABLE_VERSIONS] = array_unique(
180185
array_merge(
181186
(array)$versions[InfoCommand::CURRENT_VERSION],
@@ -197,11 +202,11 @@ public function getSystemPackageVersions($systemPackageInfo)
197202
$editionType = '';
198203
$versions = [];
199204

200-
if ($systemPackageInfo['name'] == 'magento/product-community-edition') {
205+
if ($systemPackageInfo['name'] == static::EDITION_COMMUNITY) {
201206
$editionType .= 'CE';
202-
} elseif ($systemPackageInfo['name'] == 'magento/product-enterprise-edition') {
207+
} elseif ($systemPackageInfo['name'] == static::EDITION_ENTERPRISE) {
203208
$editionType .= 'EE';
204-
} elseif ($systemPackageInfo['name'] == 'magento/product-b2b-edition') {
209+
} elseif ($systemPackageInfo['name'] == static::EDITION_B2B) {
205210
$editionType .= 'B2B';
206211
}
207212

@@ -220,20 +225,18 @@ public function getSystemPackageVersions($systemPackageInfo)
220225
}
221226

222227
/**
223-
* @param array $systemPackages
224228
* @return array
225229
* @throws \RuntimeException
226230
*/
227-
public function getInstalledSystemPackages($systemPackages)
231+
public function getInstalledSystemPackages()
228232
{
229-
$systemPackages = [];
230233
$locker = $this->magentoComposerApplication->createComposer()->getLocker();
231234

232235
/** @var \Composer\Package\CompletePackage $package */
233236
foreach ($locker->getLockedRepository()->getPackages() as $package) {
234237
$packageName = $package->getName();
235238
if ($this->composerInfo->isSystemPackage($packageName)) {
236-
if ($packageName == 'magento/product-community-edition') {
239+
if ($packageName == static::EDITION_COMMUNITY) {
237240
if ($this->composerInfo->isPackageInComposerJson($packageName)) {
238241
$systemPackages[] = $packageName;
239242
}
@@ -259,7 +262,7 @@ public function getInstalledSystemPackages($systemPackages)
259262
*/
260263
public function sortVersions($enterpriseVersions)
261264
{
262-
usort($enterpriseVersions['available_versions'], function ($versionOne, $versionTwo) {
265+
usort($enterpriseVersions[InfoCommand::AVAILABLE_VERSIONS], function ($versionOne, $versionTwo) {
263266
if (version_compare($versionOne, $versionTwo, '==')) {
264267
return 0;
265268
}
@@ -296,7 +299,7 @@ private function formatPackages($packages)
296299

297300
usort($versions, function ($versionOne, $versionTwo) {
298301
if (version_compare($versionOne['id'], $versionTwo['id'], '==')) {
299-
if ($versionOne['package'] === 'magento/product-community-edition') {
302+
if ($versionOne['package'] === static::EDITION_COMMUNITY) {
300303
return 1;
301304
}
302305
return 0;
@@ -316,11 +319,11 @@ private function formatPackages($packages)
316319
public function filterEeVersions($currentCE, $enterpriseVersions, $maxVersion)
317320
{
318321
$eeVersions = [];
319-
foreach ($enterpriseVersions['available_versions'] as $version) {
320-
$requires = $this->composerInfo->getPackageRequirements('magento/product-enterprise-edition', $version);
321-
if (array_key_exists('magento/product-community-edition', $requires)) {
322+
foreach ($enterpriseVersions[InfoCommand::AVAILABLE_VERSIONS] as $version) {
323+
$requires = $this->composerInfo->getPackageRequirements(static::EDITION_ENTERPRISE, $version);
324+
if (array_key_exists(static::EDITION_COMMUNITY, $requires)) {
322325
/** @var \Composer\Package\Link $ceRequire */
323-
$ceRequire = $requires['magento/product-community-edition'];
326+
$ceRequire = $requires[static::EDITION_COMMUNITY];
324327
if (version_compare(
325328
$ceRequire->getConstraint()->getPrettyString(),
326329
$currentCE,
@@ -348,11 +351,11 @@ public function filterEeVersions($currentCE, $enterpriseVersions, $maxVersion)
348351
public function filterB2bVersions($currentEE, $b2bVersions, $maxVersion)
349352
{
350353
$b2bVersionsPrepared = [];
351-
foreach ($b2bVersions['available_versions'] as $version) {
352-
$requires = $this->composerInfo->getPackageRequirements('magento/product-b2b-edition', $version);
353-
if (array_key_exists('magento/product-enterprise-edition', $requires)) {
354+
foreach ($b2bVersions[InfoCommand::AVAILABLE_VERSIONS] as $version) {
355+
$requires = $this->composerInfo->getPackageRequirements(static::EDITION_B2B, $version);
356+
if (array_key_exists(static::EDITION_ENTERPRISE, $requires)) {
354357
/** @var \Composer\Package\Link $eeRequire */
355-
$eeRequire = $requires['magento/product-enterprise-edition'];
358+
$eeRequire = $requires[static::EDITION_ENTERPRISE];
356359
if (version_compare(
357360
$eeRequire->getConstraint()->getPrettyString(),
358361
$currentEE,

0 commit comments

Comments
 (0)