diff --git a/Model/SupportPackage.php b/Model/SupportPackage.php index 0ce0c6b..bb76ab1 100644 --- a/Model/SupportPackage.php +++ b/Model/SupportPackage.php @@ -10,6 +10,7 @@ use Magento\Framework\Filesystem\Driver\File; use Magento\Framework\Module\Dir as ModuleDir; use Magento\Framework\Module\FullModuleList; +use Magento\Framework\Module\PackageInfo; use Magento\Framework\Module\ResourceInterface; use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\UrlInterface; @@ -31,6 +32,11 @@ class SupportPackage */ private $moduleResource; + /** + * @var PackageInfo + */ + private $packageInfo; + /** * @var DeploymentConfig */ @@ -86,6 +92,7 @@ class SupportPackage * * @param FullModuleList $fullModuleList * @param ResourceInterface $moduleResource + * @param PackageInfo $packageInfo * @param DeploymentConfig $deploymentConfig * @param ResourceConnection $resourceConnection * @param XmlParser $xmlParser @@ -100,6 +107,7 @@ class SupportPackage public function __construct( FullModuleList $fullModuleList, ResourceInterface $moduleResource, + PackageInfo $packageInfo, DeploymentConfig $deploymentConfig, ResourceConnection $resourceConnection, XmlParser $xmlParser, @@ -112,6 +120,7 @@ public function __construct( ZipArchive $zipArchive, ) { $this->moduleResource = $moduleResource; + $this->packageInfo = $packageInfo; $this->fullModuleList = $fullModuleList; $this->deploymentConfig = $deploymentConfig; $this->resourceConnection = $resourceConnection; @@ -127,6 +136,8 @@ public function __construct( /** * Prepares the support download archive + * + * @return string */ public function prepareDownloadArchive() { @@ -169,24 +180,36 @@ public function prepareSupportDetails() /** * Get the Bitpay module version + * + * @return string */ public function getBitpayModuleVersion() { - return $this->moduleResource->getDbVersion('Bitpay_BPCheckout'); + return $this->getModuleVersion('Bitpay_BPCheckout'); } /** * Get the installed modules list + * + * @return array */ public function getModuleList() { $modules = []; $allModules = $this->fullModuleList->getAll(); foreach ($allModules as $module) { + $schemaVersion = $this->moduleResource->getDbVersion($module['name']); + $dataVersion = $this->moduleResource->getDataVersion($module['name']); + if (empty($module['setup_version'])) { + $moduleVersion = $this->getModuleVersion($module['name']); + $schemaVersion = $moduleVersion; + $dataVersion = $moduleVersion; + } + $modules[] = [ 'name' => $module['name'], - 'schema_version' => $this->moduleResource->getDbVersion($module['name']) ?: 'N/A', - 'data_version' => $this->moduleResource->getDataVersion($module['name']) ?: 'N/A', + 'schema_version' => $schemaVersion ?: 'N/A', + 'data_version' => $dataVersion ?: 'N/A', ]; } @@ -195,6 +218,8 @@ public function getModuleList() /** * Get the database details + * + * @return array */ public function getDbDetails() { @@ -278,6 +303,8 @@ public function getDbDetails() /** * Get Magento details + * + * @return array */ public function getMagentoDetails() { @@ -289,6 +316,8 @@ public function getMagentoDetails() /** * Get server details + * + * @return array */ public function getServerDetails() { @@ -306,6 +335,8 @@ public function getServerDetails() /** * Get PHP details + * + * @return array */ public function getPhpDetails() { @@ -324,4 +355,15 @@ public function getPhpDetails() 'extensions' => get_loaded_extensions(), ]; } + + /** + * Get the version of a module + * + * @param string $moduleName + * @return string + */ + protected function getModuleVersion(string $moduleName) + { + return $this->packageInfo->getVersion($moduleName); + } } diff --git a/Test/Unit/Model/SupportPackageTest.php b/Test/Unit/Model/SupportPackageTest.php index 00183b5..a6e9bf1 100644 --- a/Test/Unit/Model/SupportPackageTest.php +++ b/Test/Unit/Model/SupportPackageTest.php @@ -11,6 +11,7 @@ use Magento\Framework\Filesystem\Driver\File; use Magento\Framework\Module\Dir as ModuleDir; use Magento\Framework\Module\FullModuleList; +use Magento\Framework\Module\PackageInfo; use Magento\Framework\Module\ResourceInterface; use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\UrlInterface; @@ -36,6 +37,11 @@ class SupportPackageTest extends TestCase */ private $moduleResourceMock; + /** + * @var PackageInfo|MockObject + */ + private $packageInfoMock; + /** * @var DeploymentConfig|MockObject */ @@ -96,6 +102,10 @@ protected function setUp(): void * @var ResourceInterface */ $this->moduleResourceMock = $this->createMock(ResourceInterface::class); + /** + * @var PackageInfo + */ + $this->packageInfoMock = $this->createMock(PackageInfo::class); /** * @var DeploymentConfig */ @@ -140,6 +150,7 @@ protected function setUp(): void $this->supportPackage = new SupportPackage( $this->fullModuleListMock, $this->moduleResourceMock, + $this->packageInfoMock, $this->deploymentConfigMock, $this->resourceConnectionMock, $this->xmlParserMock, @@ -289,7 +300,7 @@ public function testPrepareSupportDetails() public function testGetBitpayModuleVersion() { - $this->moduleResourceMock->method('getDbVersion') + $this->packageInfoMock->method('getVersion') ->with('Bitpay_BPCheckout') ->willReturn('1.0.0');