Skip to content

Commit 882be01

Browse files
author
Korshenko, Olexii(okorshenko)
committed
Merge pull request #696 from magento-connect/develop
[Connect] Dependencies list during migration CE to EE
2 parents 96abeda + 07cfb2e commit 882be01

File tree

7 files changed

+321
-55
lines changed

7 files changed

+321
-55
lines changed

lib/internal/Magento/Framework/Composer/ComposerInformation.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,15 @@ public function getPackagesTypes()
275275
{
276276
return self::$packageTypes;
277277
}
278+
279+
/**
280+
* @param string $name
281+
* @param string $version
282+
* @return array
283+
*/
284+
public function getPackageRequirements($name, $version)
285+
{
286+
$package = $this->composer->getRepositoryManager()->findPackage($name, $version);
287+
return $package->getRequires();
288+
}
278289
}

setup/pub/magento/setup/select-version.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,29 @@ angular.module('select-version', ['ngStorage'])
2727
$http.get('index.php/select-version/systemPackage', {'responseType' : 'json'})
2828
.success(function (data) {
2929
if (data.responseType != 'error') {
30-
$scope.versions = data.package.versions;
31-
$scope.packages[0].name = data.package.package;
32-
$scope.packages[0].version = $scope.versions[0].id;
33-
$scope.selectedOption = $scope.versions[0].id;
30+
$scope.selectedOption = [];
31+
$scope.versions = [];
32+
for (var i = 0; i < data.packages.length; i++) {
33+
angular.forEach(data.packages[i].versions, function (value, key) {
34+
$scope.versions.push({
35+
'versionInfo': angular.toJson({
36+
'package': data.packages[i].package,
37+
'version': value
38+
}), 'version': value
39+
});
40+
});
41+
}
42+
43+
$scope.versions = $scope.versions.sort(function (a, b) {
44+
if (a.version.id < b.version.id) {
45+
return 1;
46+
}
47+
if (a.version.id > b.version.id) {
48+
return -1;
49+
}
50+
return 0;
51+
});
52+
$scope.selectedOption = $scope.versions[0].versionInfo;
3453
$scope.upgradeReadyForNext = true;
3554

3655
} else {
@@ -135,7 +154,9 @@ angular.module('select-version', ['ngStorage'])
135154
};
136155

137156
$scope.update = function() {
138-
$scope.packages[0].version = $scope.selectedOption;
157+
var selectedVersionInfo = angular.fromJson($scope.selectedOption);
158+
$scope.packages[0]['name'] = selectedVersionInfo.package;
159+
$scope.packages[0].version = selectedVersionInfo.version.id;
139160
if (angular.equals($scope.updateComponents.no, true)) {
140161
if ($scope.totalForGrid > 0) {
141162
$scope.packages.splice(1, $scope.totalForGrid);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function systemPackageAction()
5151
{
5252
$data = [];
5353
try {
54-
$data['package'] = $this->systemPackage->getPackageVersions();
54+
$data['packages'] = $this->systemPackage->getPackageVersions();
5555
$responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS;
5656
} catch (\Exception $e) {
5757
$responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR;

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class DependencyReadinessCheck
3737
*/
3838
private $file;
3939

40+
/**
41+
* @var MagentoComposerApplication
42+
*/
43+
private $magentoComposerApplication;
44+
4045
/**
4146
* Constructor
4247
*
@@ -55,6 +60,7 @@ public function __construct(
5560
$this->directoryList = $directoryList;
5661
$this->file = $file;
5762
$this->requireUpdateDryRunCommand = $composerAppFactory->createRequireUpdateDryRunCommand();
63+
$this->magentoComposerApplication = $composerAppFactory->create();
5864
}
5965

6066
/**
@@ -70,6 +76,18 @@ public function runReadinessCheck(array $packages)
7076
$this->file->copy($composerJson, $this->directoryList->getPath(DirectoryList::VAR_DIR) . '/composer.json');
7177
$workingDir = $this->directoryList->getPath(DirectoryList::VAR_DIR);
7278
try {
79+
foreach ($packages as $package) {
80+
if (strpos($package, 'magento/product-enterprise-edition') !== false) {
81+
$this->magentoComposerApplication->runComposerCommand(
82+
[
83+
'command' => 'remove',
84+
'packages' => ['magento/product-community-edition'],
85+
'--no-update' => true
86+
],
87+
$workingDir
88+
);
89+
}
90+
}
7391
$this->requireUpdateDryRunCommand->run($packages, $workingDir);
7492
return ['success' => true];
7593
} catch (\RuntimeException $e) {

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

Lines changed: 139 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,51 +54,167 @@ public function __construct(
5454
*/
5555
public function getPackageVersions()
5656
{
57-
$systemPackage = null;
57+
$currentCE = '0';
58+
$result = [];
59+
$systemPackages = [];
60+
$systemPackages = $this->getInstalledSystemPackages($systemPackages);
61+
if (empty($systemPackages)) {
62+
throw new \RuntimeException('System packages not found');
63+
}
64+
foreach ($systemPackages as $systemPackage) {
65+
$versions = [];
66+
$systemPackageInfo = $this->infoCommand->run($systemPackage);
67+
if (!$systemPackageInfo) {
68+
throw new \RuntimeException('System package not found');
69+
}
5870

59-
$locker = $this->magentoComposerApplication->createComposer()->getLocker();
71+
$versions = $this->getSystemPackageVersions($systemPackageInfo, $versions);
6072

61-
foreach ($locker->getLockedRepository()->getPackages() as $package) {
62-
$packageName = $package->getName();
73+
if ($systemPackageInfo['name'] == 'magento/product-community-edition') {
74+
$currentCE = $systemPackageInfo[InfoCommand::CURRENT_VERSION];
75+
}
76+
if (count($versions) > 1) {
77+
$versions[0]['name'] .= ' (latest)';
78+
}
6379

64-
if ($this->composerInfo->isSystemPackage($packageName)) {
65-
$systemPackage = $packageName;
66-
break;
80+
if (count($versions) >= 1) {
81+
$versions[count($versions) - 1]['name'] .= ' (current)';
6782
}
83+
84+
$result[] = [
85+
'package' => $systemPackageInfo['name'],
86+
'versions' => $versions
87+
];
6888
}
6989

70-
$systemPackageInfo = $this->infoCommand->run($systemPackage);
90+
if (!in_array('magento/product-enterprise-edition', $systemPackages)) {
91+
$result = array_merge($this->getAllowedEnterpriseVersions($currentCE), $result);
92+
}
93+
94+
return $result;
95+
}
7196

72-
if (!$systemPackageInfo) {
73-
throw new \RuntimeException('System package not found');
97+
/**
98+
* @param string $currentCE
99+
* @return array
100+
*/
101+
public function getAllowedEnterpriseVersions($currentCE)
102+
{
103+
$result = [];
104+
$enterpriseVersions = $this->infoCommand->run('magento/product-enterprise-edition');
105+
$eeVersions = [];
106+
$maxVersion = '';
107+
if (array_key_exists('available_versions', $enterpriseVersions)) {
108+
$enterpriseVersions = $this->sortVersions($enterpriseVersions);
109+
if (isset($enterpriseVersions['available_versions'][0])) {
110+
$maxVersion = $enterpriseVersions['available_versions'][0];
111+
}
112+
$eeVersions = $this->filterEeVersions($currentCE, $enterpriseVersions, $maxVersion);
74113
}
75114

76-
$versions = [];
115+
if (!empty($eeVersions)) {
116+
$result[] = [
117+
'package' => 'magento/product-enterprise-edition',
118+
'versions' => $eeVersions
119+
];
120+
}
121+
return $result;
122+
}
77123

124+
/**
125+
* @param array $systemPackageInfo
126+
* @param array $versions
127+
* @return array
128+
*/
129+
public function getSystemPackageVersions($systemPackageInfo, $versions)
130+
{
131+
$editionType = '';
132+
if ($systemPackageInfo['name'] == 'magento/product-community-edition') {
133+
$editionType .= 'CE';
134+
} else if ($systemPackageInfo['name'] == 'magento/product-enterprise-edition') {
135+
$editionType .= 'EE';
136+
}
78137
foreach ($systemPackageInfo[InfoCommand::NEW_VERSIONS] as $version) {
79-
$versions[] = ['id' => $version, 'name' => 'Version ' . $version];
138+
$versions[] = ['id' => $version, 'name' => 'Version ' . $version . ' ' . $editionType];
80139
}
81140

82141
if ($systemPackageInfo[InfoCommand::CURRENT_VERSION]) {
83142
$versions[] = [
84143
'id' => $systemPackageInfo[InfoCommand::CURRENT_VERSION],
85-
'name' => 'Version ' . $systemPackageInfo[InfoCommand::CURRENT_VERSION]
144+
'name' => 'Version ' . $systemPackageInfo[InfoCommand::CURRENT_VERSION] . ' ' . $editionType
86145
];
87146
}
147+
return $versions;
148+
}
88149

89-
if (count($versions) > 1) {
90-
$versions[0]['name'] .= ' (latest)';
91-
}
150+
/**
151+
* @param array $systemPackages
152+
* @return array
153+
*/
154+
public function getInstalledSystemPackages($systemPackages)
155+
{
156+
$systemPackages = [];
157+
$locker = $this->magentoComposerApplication->createComposer()->getLocker();
92158

93-
if (count($versions) >= 1) {
94-
$versions[count($versions) - 1]['name'] .= ' (current)';
159+
/** @var \Composer\Package\CompletePackage $package */
160+
foreach ($locker->getLockedRepository()->getPackages() as $package) {
161+
$packageName = $package->getName();
162+
if ($this->composerInfo->isSystemPackage($packageName)) {
163+
if ($packageName == 'magento/product-community-edition') {
164+
if ($this->composerInfo->isPackageInComposerJson($packageName)) {
165+
$systemPackages[] = $packageName;
166+
}
167+
} else {
168+
$systemPackages[] = $packageName;
169+
}
170+
}
95171
}
172+
return $systemPackages;
173+
}
96174

97-
$result = [
98-
'package' => $systemPackageInfo['name'],
99-
'versions' => $versions
100-
];
175+
/**
176+
* @param array $enterpriseVersions
177+
* @return array
178+
*/
179+
public function sortVersions($enterpriseVersions)
180+
{
181+
usort($enterpriseVersions['available_versions'], function ($versionOne, $versionTwo) {
182+
if (version_compare($versionOne, $versionTwo, '==')) {
183+
return 0;
184+
}
185+
return (version_compare($versionOne, $versionTwo, '<')) ? 1 : -1;
186+
});
101187

102-
return $result;
188+
return $enterpriseVersions;
189+
}
190+
191+
/**
192+
* @param string $currentCE
193+
* @param array $enterpriseVersions
194+
* @param string $maxVersion
195+
* @return array
196+
*/
197+
public function filterEeVersions($currentCE, $enterpriseVersions, $maxVersion)
198+
{
199+
$eeVersions = [];
200+
foreach ($enterpriseVersions['available_versions'] as $version) {
201+
$requires = $this->composerInfo->getPackageRequirements('magento/product-enterprise-edition', $version);
202+
if (array_key_exists('magento/product-community-edition', $requires)) {
203+
/** @var \Composer\Package\Link $ceRequire */
204+
$ceRequire = $requires['magento/product-community-edition'];
205+
if (version_compare(
206+
$ceRequire->getConstraint()->getPrettyString(),
207+
$currentCE,
208+
'>='
209+
)) {
210+
$name = 'Version ' . $version . ' EE';
211+
if ($maxVersion == $version) {
212+
$name .= ' (latest)';
213+
}
214+
$eeVersions[] = ['id' => $version, 'name' => $name];
215+
}
216+
}
217+
}
218+
return $eeVersions;
103219
}
104220
}

0 commit comments

Comments
 (0)