diff --git a/app/code/Magento/Backend/Block/Page/Footer.php b/app/code/Magento/Backend/Block/Page/Footer.php index 610d28b0f53e..7818ce7c3edc 100644 --- a/app/code/Magento/Backend/Block/Page/Footer.php +++ b/app/code/Magento/Backend/Block/Page/Footer.php @@ -5,6 +5,8 @@ */ namespace Magento\Backend\Block\Page; +use Magento\Framework\App\DistributionMetadataInterface; + /** * Adminhtml footer block * @@ -20,7 +22,7 @@ class Footer extends \Magento\Backend\Block\Template protected $_template = 'Magento_Backend::page/footer.phtml'; /** - * @var \Magento\Framework\App\ProductMetadataInterface + * @var \Magento\Framework\App\ProductMetadataInterface|DistributionMetadataInterface * @since 100.1.0 */ protected $productMetadata; @@ -55,7 +57,17 @@ protected function _construct() */ public function getMagentoVersion() { - return $this->productMetadata->getVersion(); + return $this->productMetadata->getDistributionVersion(); + } + + /** + * Get product name + * + * @return string + */ + public function getName() + { + return $this->productMetadata->getDistributionName(); } /** diff --git a/app/code/Magento/Backend/view/adminhtml/templates/page/footer.phtml b/app/code/Magento/Backend/view/adminhtml/templates/page/footer.phtml index 7b1f14d28a50..ab20cec1d9bb 100644 --- a/app/code/Magento/Backend/view/adminhtml/templates/page/footer.phtml +++ b/app/code/Magento/Backend/view/adminhtml/templates/page/footer.phtml @@ -11,6 +11,6 @@ use Magento\Framework\Escaper; /** @var Footer $block */ ?>

- escapeHtml(__('Mage-OS')); ?> + escapeHtml(__($block->getName())); ?> escapeHtml(__('ver. %1', $block->getMagentoVersion())); ?>

diff --git a/app/code/Magento/Version/Controller/Index/Index.php b/app/code/Magento/Version/Controller/Index/Index.php index 512dbe13ab3c..b1a62eff7f86 100644 --- a/app/code/Magento/Version/Controller/Index/Index.php +++ b/app/code/Magento/Version/Controller/Index/Index.php @@ -10,6 +10,7 @@ use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\DistributionMetadataInterface; use Magento\Framework\App\ProductMetadataInterface; use Magento\Framework\Controller\Result\RawFactory as RawResponseFactory; @@ -21,7 +22,7 @@ class Index extends Action implements HttpGetActionInterface public const DEV_PREFIX = 'dev-'; /** - * @var ProductMetadataInterface + * @var ProductMetadataInterface|DistributionMetadataInterface */ private $productMetadata; @@ -52,11 +53,11 @@ public function execute() { $rawResponse = $this->rawFactory->create(); - $version = $this->productMetadata->getVersion() ?? ''; + $version = $this->productMetadata->getDistributionVersion() ?? ''; $versionParts = explode('.', $version); if (!$this->isGitBasedInstallation($version) && $this->isCorrectVersion($versionParts)) { $rawResponse->setContents( - $this->productMetadata->getName() . '/' . + $this->productMetadata->getDistributionName() . '/' . $this->getMajorMinorVersion($versionParts) . ' (' . $this->productMetadata->getEdition() . ')' ); diff --git a/app/code/Magento/Version/Test/Unit/Controller/Index/IndexTest.php b/app/code/Magento/Version/Test/Unit/Controller/Index/IndexTest.php index 2667a5b993ef..79d4c2765ab5 100644 --- a/app/code/Magento/Version/Test/Unit/Controller/Index/IndexTest.php +++ b/app/code/Magento/Version/Test/Unit/Controller/Index/IndexTest.php @@ -41,7 +41,7 @@ protected function setUp(): void $this->productMetadataMock = $this->getMockBuilder(ProductMetadataInterface::class) ->disableOriginalConstructor() - ->setMethods(['getName', 'getEdition', 'getVersion']) + ->setMethods(['getName', 'getEdition', 'getVersion', 'getDistributionName', 'getDistributionVersion']) ->getMockForAbstractClass(); $this->rawResponseFactoryMock = $this->createPartialMock(RawFactory::class, ['create']); @@ -78,9 +78,13 @@ public function testCommunityVersionDisplaysMajorMinorVersionAndEditionName(): v $this->productMetadataMock->expects($this->any())->method('getVersion')->willReturn('2.3.3'); $this->productMetadataMock->expects($this->any())->method('getEdition')->willReturn('Community'); $this->productMetadataMock->expects($this->any())->method('getName')->willReturn('Magento'); + $this->productMetadataMock->expects($this->any())->method('getDistributionVersion') + ->willReturn('1.1.0'); + $this->productMetadataMock->expects($this->any())->method('getDistributionName') + ->willReturn('Mage-OS'); $this->rawResponseMock->expects($this->once())->method('setContents') - ->with('Magento/2.3 (Community)') + ->with('Mage-OS/1.1 (Community)') ->willReturnSelf(); $this->versionController->execute(); diff --git a/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php b/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php index c2af90db35d2..4b4f10700f4c 100644 --- a/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php +++ b/app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php @@ -6,6 +6,7 @@ namespace Magento\Webapi\Model\Rest\Swagger; use Magento\Framework\Api\SimpleDataObjectConverter; +use Magento\Framework\App\DistributionMetadataInterface; use Magento\Framework\App\ProductMetadataInterface; use Magento\Framework\Reflection\TypeProcessor; use Magento\Framework\Webapi\Authorization; @@ -52,7 +53,7 @@ class Generator extends AbstractSchemaGenerator /** * Magento product metadata * - * @var ProductMetadataInterface + * @var ProductMetadataInterface|DistributionMetadataInterface */ protected ProductMetadataInterface $productMetadata; @@ -182,7 +183,7 @@ protected function generateSchema($requestedServiceMetadata, $requestScheme, $re */ protected function getGeneralInfo() { - $versionParts = explode('.', $this->productMetadata->getVersion()); + $versionParts = explode('.', $this->productMetadata->getDistributionVersion()); if (!isset($versionParts[0]) || !isset($versionParts[1])) { return []; // Major and minor version are not set - return empty response } @@ -190,7 +191,7 @@ protected function getGeneralInfo() return [ 'version' => $majorMinorVersion, - 'title' => $this->productMetadata->getName() . ' ' . $this->productMetadata->getEdition(), + 'title' => $this->productMetadata->getDistributionName() . ' ' . $this->productMetadata->getEdition(), ]; } diff --git a/app/code/Magento/Webapi/Test/Unit/Model/Rest/Swagger/GeneratorTest.php b/app/code/Magento/Webapi/Test/Unit/Model/Rest/Swagger/GeneratorTest.php index a40d66180666..163d17f7d629 100644 --- a/app/code/Magento/Webapi/Test/Unit/Model/Rest/Swagger/GeneratorTest.php +++ b/app/code/Magento/Webapi/Test/Unit/Model/Rest/Swagger/GeneratorTest.php @@ -181,7 +181,7 @@ public function testGenerate($serviceMetadata, $typeData, $schema) ); $this->productMetadata->expects($this->once()) - ->method('getVersion') + ->method('getDistributionVersion') ->willReturn('UNKNOWN'); $this->assertEquals( diff --git a/dev/tests/integration/testsuite/Magento/Version/Controller/Index/IndexTest.php b/dev/tests/integration/testsuite/Magento/Version/Controller/Index/IndexTest.php index 18c1b5cc9884..a311ab6f621c 100644 --- a/dev/tests/integration/testsuite/Magento/Version/Controller/Index/IndexTest.php +++ b/dev/tests/integration/testsuite/Magento/Version/Controller/Index/IndexTest.php @@ -16,10 +16,10 @@ public function testIndexAction() $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); /** @var \Magento\Framework\App\ProductMetadataInterface $productMetadata */ $productMetadata = $objectManager->get(\Magento\Framework\App\ProductMetadataInterface::class); - $name = $productMetadata->getName(); + $name = $productMetadata->getDistributionName(); $edition = $productMetadata->getEdition(); - $fullVersion = $productMetadata->getVersion(); + $fullVersion = $productMetadata->getDistributionVersion(); if ($this->isComposerBasedInstallation($fullVersion)) { $versionParts = explode('.', $fullVersion); $majorMinor = $versionParts[0] . '.' . $versionParts[1]; diff --git a/lib/internal/Magento/Framework/App/DistributionMetadataInterface.php b/lib/internal/Magento/Framework/App/DistributionMetadataInterface.php new file mode 100644 index 000000000000..0654f5cd59f8 --- /dev/null +++ b/lib/internal/Magento/Framework/App/DistributionMetadataInterface.php @@ -0,0 +1,31 @@ +version; } + /** + * Get Distribution version + * + * @return string + */ + public function getDistributionVersion() + { + $this->distroVersion = $this->distroVersion ?: $this->cache->load(self::DISTRO_VERSION_CACHE_KEY); + if (!$this->distroVersion) { + if (!($this->distroVersion = $this->getSystemDistroVersion())) { + if ($this->getComposerInformation()->isMagentoRoot()) { + $this->distroVersion = $this->getComposerInformation()->getRootPackage()->getPrettyVersion(); + } else { + $this->distroVersion = 'UNKNOWN'; + } + } + $this->cache->save($this->distroVersion, self::DISTRO_VERSION_CACHE_KEY, [Config::CACHE_TAG]); + } + return $this->distroVersion; + } + /** * Get Product edition * @@ -109,6 +147,16 @@ public function getName() return self::PRODUCT_NAME; } + /** + * Get Distribution name + * + * @return string + */ + public function getDistributionName() + { + return self::DISTRIBUTION_NAME; + } + /** * Get version from system package * @@ -116,6 +164,22 @@ public function getName() * @deprecated 100.1.0 */ private function getSystemPackageVersion() + { + $packages = $this->getComposerInformation()->getSystemPackages(); + foreach ($packages as $package) { + if (isset($package['name']) && isset($package['magento_version'])) { + return $package['magento_version']; + } + } + return ''; + } + + /** + * Get distribution version from system package + * + * @return string + */ + private function getSystemDistroVersion() { $packages = $this->getComposerInformation()->getSystemPackages(); foreach ($packages as $package) { diff --git a/lib/internal/Magento/Framework/Composer/ComposerInformation.php b/lib/internal/Magento/Framework/Composer/ComposerInformation.php index a190f5597ca3..a27462241718 100644 --- a/lib/internal/Magento/Framework/Composer/ComposerInformation.php +++ b/lib/internal/Magento/Framework/Composer/ComposerInformation.php @@ -246,7 +246,8 @@ public function getSystemPackages() $packages[$package->getName()] = [ 'name' => $package->getName(), 'type' => $package->getType(), - 'version' => $package->getPrettyVersion() + 'version' => $package->getPrettyVersion(), + 'magento_version' => $package->getExtra()['magento_version'] ?? null, ]; } } diff --git a/lib/internal/Magento/Framework/Console/Cli.php b/lib/internal/Magento/Framework/Console/Cli.php index ca82e495e5a5..b1fb90dd3482 100644 --- a/lib/internal/Magento/Framework/Console/Cli.php +++ b/lib/internal/Magento/Framework/Console/Cli.php @@ -9,6 +9,7 @@ use Magento\Framework\App\Bootstrap; use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\App\DistributionMetadataInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\ProductMetadata; use Magento\Framework\Composer\ComposerJsonFinder; @@ -68,6 +69,11 @@ class Cli extends Console\Application */ private $logger; + /** + * @var ProductMetadata + */ + private $productMetadata; + /** * @param string $name the application name * @param string $version the application version @@ -97,8 +103,9 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') if ($version == 'UNKNOWN') { $directoryList = new DirectoryList(BP); $composerJsonFinder = new ComposerJsonFinder($directoryList); - $productMetadata = new ProductMetadata($composerJsonFinder); - $version = $productMetadata->getVersion(); + $this->productMetadata = new ProductMetadata($composerJsonFinder); + $name = $this->productMetadata->getDistributionName() . ' CLI'; + $version = $this->productMetadata->getDistributionVersion(); } parent::__construct($name, $version); @@ -232,4 +239,25 @@ protected function getVendorCommands($objectManager) return array_merge([], ...$commands); } + + /** + * Get system version info. + * + * @return string + */ + public function getLongVersion() + { + if (isset($this->productMetadata) + && $this->productMetadata instanceof DistributionMetadataInterface + && $this->productMetadata->getDistributionVersion() !== $this->productMetadata->getVersion()) { + return sprintf( + '%s (based on %s %s)', + parent::getLongVersion(), + $this->productMetadata->getName(), + $this->productMetadata->getVersion() + ); + } + + return parent::getLongVersion(); + } } diff --git a/setup/index.php b/setup/index.php index fd338f8f0c6e..93b9cf84d0b1 100644 --- a/setup/index.php +++ b/setup/index.php @@ -41,7 +41,7 @@ /** @var License $license */ $license = $licenseClass->getContents(); /** @var ProductMetadata $version */ -$version = $metaClass->getVersion(); +$version = $metaClass->getDistributionVersion(); $request = new Request(); $basePath = $request->getBasePath();