@@ -31,6 +31,10 @@ class SystemPackage
31
31
*/
32
32
private $ composerInfo ;
33
33
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
+
34
38
/**
35
39
* Constructor
36
40
*
@@ -58,8 +62,7 @@ public function getPackageVersions()
58
62
$ currentEE = $ currentCE ;
59
63
60
64
$ result = [];
61
- $ systemPackages = [];
62
- $ systemPackages = $ this ->getInstalledSystemPackages ($ systemPackages );
65
+ $ systemPackages = $ this ->getInstalledSystemPackages ();
63
66
foreach ($ systemPackages as $ systemPackage ) {
64
67
$ systemPackageInfo = $ this ->infoCommand ->run ($ systemPackage );
65
68
if (!$ systemPackageInfo ) {
@@ -68,11 +71,11 @@ public function getPackageVersions()
68
71
69
72
$ versions = $ this ->getSystemPackageVersions ($ systemPackageInfo );
70
73
71
- if ($ systemPackageInfo ['name ' ] == ' magento/product-community-edition ' ) {
74
+ if ($ systemPackageInfo ['name ' ] == static :: EDITION_COMMUNITY ) {
72
75
$ currentCE = $ systemPackageInfo [InfoCommand::CURRENT_VERSION ];
73
76
}
74
77
75
- if ($ systemPackageInfo ['name ' ] == ' magento/product-enterprise-edition ' ) {
78
+ if ($ systemPackageInfo ['name ' ] == static :: EDITION_ENTERPRISE ) {
76
79
$ currentEE = $ systemPackageInfo [InfoCommand::CURRENT_VERSION ];
77
80
}
78
81
@@ -86,13 +89,13 @@ public function getPackageVersions()
86
89
];
87
90
}
88
91
89
- if (!in_array (' magento/product-enterprise-edition ' , $ systemPackages )) {
92
+ if (!in_array (static :: EDITION_ENTERPRISE , $ systemPackages )) {
90
93
$ result = array_merge ($ this ->getAllowedEnterpriseVersions ($ currentCE ), $ result );
91
94
}
92
95
93
96
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 )
96
99
) {
97
100
$ result = array_merge ($ this ->getAllowedB2BVersions ($ currentEE ), $ result );
98
101
}
@@ -111,20 +114,20 @@ public function getPackageVersions()
111
114
public function getAllowedEnterpriseVersions ($ currentCE )
112
115
{
113
116
$ result = [];
114
- $ enterpriseVersions = $ this ->infoCommand ->run (' magento/product-enterprise-edition ' );
117
+ $ enterpriseVersions = $ this ->infoCommand ->run (static :: EDITION_ENTERPRISE );
115
118
$ eeVersions = [];
116
119
$ maxVersion = '' ;
117
- if (is_array ($ enterpriseVersions ) && array_key_exists (' available_versions ' , $ enterpriseVersions )) {
120
+ if (is_array ($ enterpriseVersions ) && array_key_exists (InfoCommand:: AVAILABLE_VERSIONS , $ enterpriseVersions )) {
118
121
$ 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 ];
121
124
}
122
125
$ eeVersions = $ this ->filterEeVersions ($ currentCE , $ enterpriseVersions , $ maxVersion );
123
126
}
124
127
125
128
if (!empty ($ eeVersions )) {
126
129
$ result [] = [
127
- 'package ' => ' magento/product-enterprise-edition ' ,
130
+ 'package ' => static :: EDITION_ENTERPRISE ,
128
131
'versions ' => $ eeVersions ,
129
132
];
130
133
}
@@ -140,7 +143,7 @@ public function getAllowedEnterpriseVersions($currentCE)
140
143
public function getAllowedB2BVersions ($ currentEE )
141
144
{
142
145
$ result = [];
143
- $ versions = $ this ->fetchInfoVersions (' magento/product-b2b-edition ' );
146
+ $ versions = $ this ->fetchInfoVersions (static :: EDITION_B2B );
144
147
$ versionsPrepared = [];
145
148
$ maxVersion = '' ;
146
149
@@ -154,7 +157,7 @@ public function getAllowedB2BVersions($currentEE)
154
157
155
158
if ($ versionsPrepared ) {
156
159
$ result [] = [
157
- 'package ' => ' magento/product-b2b-edition ' ,
160
+ 'package ' => static :: EDITION_B2B ,
158
161
'versions ' => $ versionsPrepared ,
159
162
];
160
163
}
@@ -163,8 +166,7 @@ public function getAllowedB2BVersions($currentEE)
163
166
}
164
167
165
168
/**
166
- * Fetching info command response to
167
- * display all correct versions
169
+ * Fetching of info command response to display all correct versions
168
170
*
169
171
* @param string $command
170
172
* @return array
@@ -176,6 +178,9 @@ private function fetchInfoVersions($command)
176
178
$ versions [InfoCommand::CURRENT_VERSION ] = isset ($ versions [InfoCommand::CURRENT_VERSION ])
177
179
? $ versions [InfoCommand::CURRENT_VERSION ]
178
180
: null ;
181
+ $ versions [InfoCommand::AVAILABLE_VERSIONS ] = isset ($ versions [InfoCommand::AVAILABLE_VERSIONS ])
182
+ ? $ versions [InfoCommand::AVAILABLE_VERSIONS ]
183
+ : null ;
179
184
$ versions [InfoCommand::AVAILABLE_VERSIONS ] = array_unique (
180
185
array_merge (
181
186
(array )$ versions [InfoCommand::CURRENT_VERSION ],
@@ -197,11 +202,11 @@ public function getSystemPackageVersions($systemPackageInfo)
197
202
$ editionType = '' ;
198
203
$ versions = [];
199
204
200
- if ($ systemPackageInfo ['name ' ] == ' magento/product-community-edition ' ) {
205
+ if ($ systemPackageInfo ['name ' ] == static :: EDITION_COMMUNITY ) {
201
206
$ editionType .= 'CE ' ;
202
- } elseif ($ systemPackageInfo ['name ' ] == ' magento/product-enterprise-edition ' ) {
207
+ } elseif ($ systemPackageInfo ['name ' ] == static :: EDITION_ENTERPRISE ) {
203
208
$ editionType .= 'EE ' ;
204
- } elseif ($ systemPackageInfo ['name ' ] == ' magento/product-b2b-edition ' ) {
209
+ } elseif ($ systemPackageInfo ['name ' ] == static :: EDITION_B2B ) {
205
210
$ editionType .= 'B2B ' ;
206
211
}
207
212
@@ -220,20 +225,18 @@ public function getSystemPackageVersions($systemPackageInfo)
220
225
}
221
226
222
227
/**
223
- * @param array $systemPackages
224
228
* @return array
225
229
* @throws \RuntimeException
226
230
*/
227
- public function getInstalledSystemPackages ($ systemPackages )
231
+ public function getInstalledSystemPackages ()
228
232
{
229
- $ systemPackages = [];
230
233
$ locker = $ this ->magentoComposerApplication ->createComposer ()->getLocker ();
231
234
232
235
/** @var \Composer\Package\CompletePackage $package */
233
236
foreach ($ locker ->getLockedRepository ()->getPackages () as $ package ) {
234
237
$ packageName = $ package ->getName ();
235
238
if ($ this ->composerInfo ->isSystemPackage ($ packageName )) {
236
- if ($ packageName == ' magento/product-community-edition ' ) {
239
+ if ($ packageName == static :: EDITION_COMMUNITY ) {
237
240
if ($ this ->composerInfo ->isPackageInComposerJson ($ packageName )) {
238
241
$ systemPackages [] = $ packageName ;
239
242
}
@@ -259,7 +262,7 @@ public function getInstalledSystemPackages($systemPackages)
259
262
*/
260
263
public function sortVersions ($ enterpriseVersions )
261
264
{
262
- usort ($ enterpriseVersions [' available_versions ' ], function ($ versionOne , $ versionTwo ) {
265
+ usort ($ enterpriseVersions [InfoCommand:: AVAILABLE_VERSIONS ], function ($ versionOne , $ versionTwo ) {
263
266
if (version_compare ($ versionOne , $ versionTwo , '== ' )) {
264
267
return 0 ;
265
268
}
@@ -296,7 +299,7 @@ private function formatPackages($packages)
296
299
297
300
usort ($ versions , function ($ versionOne , $ versionTwo ) {
298
301
if (version_compare ($ versionOne ['id ' ], $ versionTwo ['id ' ], '== ' )) {
299
- if ($ versionOne ['package ' ] === ' magento/product-community-edition ' ) {
302
+ if ($ versionOne ['package ' ] === static :: EDITION_COMMUNITY ) {
300
303
return 1 ;
301
304
}
302
305
return 0 ;
@@ -316,11 +319,11 @@ private function formatPackages($packages)
316
319
public function filterEeVersions ($ currentCE , $ enterpriseVersions , $ maxVersion )
317
320
{
318
321
$ 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 )) {
322
325
/** @var \Composer\Package\Link $ceRequire */
323
- $ ceRequire = $ requires [' magento/product-community-edition ' ];
326
+ $ ceRequire = $ requires [static :: EDITION_COMMUNITY ];
324
327
if (version_compare (
325
328
$ ceRequire ->getConstraint ()->getPrettyString (),
326
329
$ currentCE ,
@@ -348,11 +351,11 @@ public function filterEeVersions($currentCE, $enterpriseVersions, $maxVersion)
348
351
public function filterB2bVersions ($ currentEE , $ b2bVersions , $ maxVersion )
349
352
{
350
353
$ 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 )) {
354
357
/** @var \Composer\Package\Link $eeRequire */
355
- $ eeRequire = $ requires [' magento/product-enterprise-edition ' ];
358
+ $ eeRequire = $ requires [static :: EDITION_ENTERPRISE ];
356
359
if (version_compare (
357
360
$ eeRequire ->getConstraint ()->getPrettyString (),
358
361
$ currentEE ,
0 commit comments