Skip to content

Commit bc2c3b9

Browse files
eddielauOlga Kopylova
authored andcommitted
Merge branch 'MAGETWO-5081-manage-modules' into develop
2 parents 89ca324 + 37291ab commit bc2c3b9

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

dev/tests/unit/testsuite/Magento/Framework/Module/ConflictCheckerTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ public function checkConflictWhenEnableModuleDataProvider()
9393
['Vendor_B', 'Vendor_C'],
9494
['Vendor_B' => ['Vendor_C'], 'Vendor_C' => ['Vendor_B']]
9595
],
96+
[
97+
[['Vendor_A', ['Vendor_B' => '>=0.1']], ['Vendor_B', []]],
98+
['Vendor_A'],
99+
['Vendor_B'],
100+
['Vendor_B' => ['Vendor_A']]
101+
],
102+
[
103+
[['Vendor_A', ['Vendor_B' => '~0.1']], ['Vendor_B', []]],
104+
['Vendor_A'],
105+
['Vendor_B'],
106+
['Vendor_B' => ['Vendor_A']]
107+
],
96108
];
97109
}
98110

@@ -108,7 +120,7 @@ public function testCheckConflictWhenEnableModuleDifferentVersion()
108120
->will($this->returnValueMap([
109121
['Vendor_A', []],
110122
['Vendor_B', []],
111-
['Vendor_C', ['Vendor_A' => '0.2', 'Vendor_B' => '0.3']]
123+
['Vendor_C', ['Vendor_A' => '>=0.2,<0.3', 'Vendor_B' => '<0.4']]
112124
]));
113125
$packageInfoMock->expects($this->any())
114126
->method('getVersion')

lib/internal/Magento/Framework/Module/ConflictChecker.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Framework\Module;
77

8+
use Composer\Package\LinkConstraint\VersionConstraint;
9+
use Composer\Package\Version\VersionParser;
10+
811
/**
912
* Checks for conflicts between modules
1013
*/
@@ -68,15 +71,21 @@ public function checkConflictsWhenEnableModules($moduleNames)
6871
*/
6972
private function checkIfConflict($moduleA, $moduleB)
7073
{
71-
if (isset($this->packageInfo->getConflict($moduleB)[$moduleA]) &&
72-
$this->packageInfo->getConflict($moduleB)[$moduleA] === $this->packageInfo->getVersion($moduleA)) {
73-
return true;
74+
$versionParser = new VersionParser();
75+
if (isset($this->packageInfo->getConflict($moduleB)[$moduleA]) && $this->packageInfo->getVersion($moduleA)) {
76+
$constraintA = $versionParser->parseConstraints($this->packageInfo->getConflict($moduleB)[$moduleA]);
77+
$constraintB = $versionParser->parseConstraints($this->packageInfo->getVersion($moduleA));
78+
if ($constraintA->matches($constraintB)) {
79+
return true;
80+
}
7481
}
75-
if (isset($this->packageInfo->getConflict($moduleA)[$moduleB]) &&
76-
$this->packageInfo->getConflict($moduleA)[$moduleB] === $this->packageInfo->getVersion($moduleB)) {
77-
return true;
82+
if (isset($this->packageInfo->getConflict($moduleA)[$moduleB]) && $this->packageInfo->getVersion($moduleB)) {
83+
$constraintA = $versionParser->parseConstraints($this->packageInfo->getConflict($moduleA)[$moduleB]);
84+
$constraintB = $versionParser->parseConstraints($this->packageInfo->getVersion($moduleB));
85+
if ($constraintA->matches($constraintB)) {
86+
return true;
87+
}
7888
}
79-
8089
return false;
8190
}
8291
}

lib/internal/Magento/Framework/Module/PackageInfo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class PackageInfo
3333
private $requireMap;
3434

3535
/**
36-
* "conflict" field of each module, contains conflicting modules' name and version
36+
* "conflict" field of each module, contains conflicting modules' name and version constraint
3737
*
3838
* @var array[]
3939
*/

0 commit comments

Comments
 (0)