Skip to content

Commit 8e56ab8

Browse files
authored
Merge pull request #119 from swlodarski-sumoheavy/10.1.x
SP-939: if the module uses declarative schema and there is no row in the setup_module table, get the version from composer.json
2 parents 1d64708 + d589ec6 commit 8e56ab8

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

Model/SupportPackage.php

+45-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\Filesystem\Driver\File;
1111
use Magento\Framework\Module\Dir as ModuleDir;
1212
use Magento\Framework\Module\FullModuleList;
13+
use Magento\Framework\Module\PackageInfo;
1314
use Magento\Framework\Module\ResourceInterface;
1415
use Magento\Framework\Serialize\Serializer\Json;
1516
use Magento\Framework\UrlInterface;
@@ -31,6 +32,11 @@ class SupportPackage
3132
*/
3233
private $moduleResource;
3334

35+
/**
36+
* @var PackageInfo
37+
*/
38+
private $packageInfo;
39+
3440
/**
3541
* @var DeploymentConfig
3642
*/
@@ -86,6 +92,7 @@ class SupportPackage
8692
*
8793
* @param FullModuleList $fullModuleList
8894
* @param ResourceInterface $moduleResource
95+
* @param PackageInfo $packageInfo
8996
* @param DeploymentConfig $deploymentConfig
9097
* @param ResourceConnection $resourceConnection
9198
* @param XmlParser $xmlParser
@@ -100,6 +107,7 @@ class SupportPackage
100107
public function __construct(
101108
FullModuleList $fullModuleList,
102109
ResourceInterface $moduleResource,
110+
PackageInfo $packageInfo,
103111
DeploymentConfig $deploymentConfig,
104112
ResourceConnection $resourceConnection,
105113
XmlParser $xmlParser,
@@ -112,6 +120,7 @@ public function __construct(
112120
ZipArchive $zipArchive,
113121
) {
114122
$this->moduleResource = $moduleResource;
123+
$this->packageInfo = $packageInfo;
115124
$this->fullModuleList = $fullModuleList;
116125
$this->deploymentConfig = $deploymentConfig;
117126
$this->resourceConnection = $resourceConnection;
@@ -127,6 +136,8 @@ public function __construct(
127136

128137
/**
129138
* Prepares the support download archive
139+
*
140+
* @return string
130141
*/
131142
public function prepareDownloadArchive()
132143
{
@@ -169,24 +180,36 @@ public function prepareSupportDetails()
169180

170181
/**
171182
* Get the Bitpay module version
183+
*
184+
* @return string
172185
*/
173186
public function getBitpayModuleVersion()
174187
{
175-
return $this->moduleResource->getDbVersion('Bitpay_BPCheckout');
188+
return $this->getModuleVersion('Bitpay_BPCheckout');
176189
}
177190

178191
/**
179192
* Get the installed modules list
193+
*
194+
* @return array
180195
*/
181196
public function getModuleList()
182197
{
183198
$modules = [];
184199
$allModules = $this->fullModuleList->getAll();
185200
foreach ($allModules as $module) {
201+
$schemaVersion = $this->moduleResource->getDbVersion($module['name']);
202+
$dataVersion = $this->moduleResource->getDataVersion($module['name']);
203+
if (empty($module['setup_version'])) {
204+
$moduleVersion = $this->getModuleVersion($module['name']);
205+
$schemaVersion = $moduleVersion;
206+
$dataVersion = $moduleVersion;
207+
}
208+
186209
$modules[] = [
187210
'name' => $module['name'],
188-
'schema_version' => $this->moduleResource->getDbVersion($module['name']) ?: 'N/A',
189-
'data_version' => $this->moduleResource->getDataVersion($module['name']) ?: 'N/A',
211+
'schema_version' => $schemaVersion ?: 'N/A',
212+
'data_version' => $dataVersion ?: 'N/A',
190213
];
191214
}
192215

@@ -195,6 +218,8 @@ public function getModuleList()
195218

196219
/**
197220
* Get the database details
221+
*
222+
* @return array
198223
*/
199224
public function getDbDetails()
200225
{
@@ -278,6 +303,8 @@ public function getDbDetails()
278303

279304
/**
280305
* Get Magento details
306+
*
307+
* @return array
281308
*/
282309
public function getMagentoDetails()
283310
{
@@ -289,6 +316,8 @@ public function getMagentoDetails()
289316

290317
/**
291318
* Get server details
319+
*
320+
* @return array
292321
*/
293322
public function getServerDetails()
294323
{
@@ -306,6 +335,8 @@ public function getServerDetails()
306335

307336
/**
308337
* Get PHP details
338+
*
339+
* @return array
309340
*/
310341
public function getPhpDetails()
311342
{
@@ -324,4 +355,15 @@ public function getPhpDetails()
324355
'extensions' => get_loaded_extensions(),
325356
];
326357
}
358+
359+
/**
360+
* Get the version of a module
361+
*
362+
* @param string $moduleName
363+
* @return string
364+
*/
365+
protected function getModuleVersion(string $moduleName)
366+
{
367+
return $this->packageInfo->getVersion($moduleName);
368+
}
327369
}

Test/Unit/Model/SupportPackageTest.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\Filesystem\Driver\File;
1212
use Magento\Framework\Module\Dir as ModuleDir;
1313
use Magento\Framework\Module\FullModuleList;
14+
use Magento\Framework\Module\PackageInfo;
1415
use Magento\Framework\Module\ResourceInterface;
1516
use Magento\Framework\Serialize\Serializer\Json;
1617
use Magento\Framework\UrlInterface;
@@ -36,6 +37,11 @@ class SupportPackageTest extends TestCase
3637
*/
3738
private $moduleResourceMock;
3839

40+
/**
41+
* @var PackageInfo|MockObject
42+
*/
43+
private $packageInfoMock;
44+
3945
/**
4046
* @var DeploymentConfig|MockObject
4147
*/
@@ -96,6 +102,10 @@ protected function setUp(): void
96102
* @var ResourceInterface
97103
*/
98104
$this->moduleResourceMock = $this->createMock(ResourceInterface::class);
105+
/**
106+
* @var PackageInfo
107+
*/
108+
$this->packageInfoMock = $this->createMock(PackageInfo::class);
99109
/**
100110
* @var DeploymentConfig
101111
*/
@@ -140,6 +150,7 @@ protected function setUp(): void
140150
$this->supportPackage = new SupportPackage(
141151
$this->fullModuleListMock,
142152
$this->moduleResourceMock,
153+
$this->packageInfoMock,
143154
$this->deploymentConfigMock,
144155
$this->resourceConnectionMock,
145156
$this->xmlParserMock,
@@ -289,7 +300,7 @@ public function testPrepareSupportDetails()
289300

290301
public function testGetBitpayModuleVersion()
291302
{
292-
$this->moduleResourceMock->method('getDbVersion')
303+
$this->packageInfoMock->method('getVersion')
293304
->with('Bitpay_BPCheckout')
294305
->willReturn('1.0.0');
295306

0 commit comments

Comments
 (0)