Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SP-939: if the module uses declarative schema and there is no row in the setup_module table, get the version from composer.json #119

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions Model/SupportPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,11 @@ class SupportPackage
*/
private $moduleResource;

/**
* @var PackageInfo
*/
private $packageInfo;

/**
* @var DeploymentConfig
*/
Expand Down Expand Up @@ -86,6 +92,7 @@ class SupportPackage
*
* @param FullModuleList $fullModuleList
* @param ResourceInterface $moduleResource
* @param PackageInfo $packageInfo
* @param DeploymentConfig $deploymentConfig
* @param ResourceConnection $resourceConnection
* @param XmlParser $xmlParser
Expand All @@ -100,6 +107,7 @@ class SupportPackage
public function __construct(
FullModuleList $fullModuleList,
ResourceInterface $moduleResource,
PackageInfo $packageInfo,
DeploymentConfig $deploymentConfig,
ResourceConnection $resourceConnection,
XmlParser $xmlParser,
Expand All @@ -112,6 +120,7 @@ public function __construct(
ZipArchive $zipArchive,
) {
$this->moduleResource = $moduleResource;
$this->packageInfo = $packageInfo;
$this->fullModuleList = $fullModuleList;
$this->deploymentConfig = $deploymentConfig;
$this->resourceConnection = $resourceConnection;
Expand All @@ -127,6 +136,8 @@ public function __construct(

/**
* Prepares the support download archive
*
* @return string
*/
public function prepareDownloadArchive()
{
Expand Down Expand Up @@ -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',
];
}

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

/**
* Get the database details
*
* @return array
*/
public function getDbDetails()
{
Expand Down Expand Up @@ -278,6 +303,8 @@ public function getDbDetails()

/**
* Get Magento details
*
* @return array
*/
public function getMagentoDetails()
{
Expand All @@ -289,6 +316,8 @@ public function getMagentoDetails()

/**
* Get server details
*
* @return array
*/
public function getServerDetails()
{
Expand All @@ -306,6 +335,8 @@ public function getServerDetails()

/**
* Get PHP details
*
* @return array
*/
public function getPhpDetails()
{
Expand All @@ -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);
}
}
13 changes: 12 additions & 1 deletion Test/Unit/Model/SupportPackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,6 +37,11 @@ class SupportPackageTest extends TestCase
*/
private $moduleResourceMock;

/**
* @var PackageInfo|MockObject
*/
private $packageInfoMock;

/**
* @var DeploymentConfig|MockObject
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -140,6 +150,7 @@ protected function setUp(): void
$this->supportPackage = new SupportPackage(
$this->fullModuleListMock,
$this->moduleResourceMock,
$this->packageInfoMock,
$this->deploymentConfigMock,
$this->resourceConnectionMock,
$this->xmlParserMock,
Expand Down Expand Up @@ -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');

Expand Down
Loading