From 4c1560574e443813f64ecf9cc0d46dc5ebdadab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCnch?= Date: Tue, 10 Oct 2023 17:40:05 +0200 Subject: [PATCH] Add Compatibility Check for Mage-OS --- .../EventSubscriber/CheckCompatibility.php | 82 +++++++++++++------ 1 file changed, 58 insertions(+), 24 deletions(-) diff --git a/src/N98/Magento/Application/Console/EventSubscriber/CheckCompatibility.php b/src/N98/Magento/Application/Console/EventSubscriber/CheckCompatibility.php index 52eee13c..a078580b 100644 --- a/src/N98/Magento/Application/Console/EventSubscriber/CheckCompatibility.php +++ b/src/N98/Magento/Application/Console/EventSubscriber/CheckCompatibility.php @@ -84,30 +84,18 @@ public function checkCompatibility(ConsoleEvent $event) $productMetadata = $objectManager->get(\Magento\Framework\App\ProductMetadataInterface::class); $currentMagentoVersion = $productMetadata->getVersion(); - if ($this->isStableVersion($currentMagentoVersion) && version_compare($currentMagentoVersion, '2.3.0', '<')) { - $output = $event->getOutput(); - $output->writeln([ - '', - 'You are running an incompatible version of n98-magerun2!', - 'Your shop version has to be >2.3.0', - '', - '', - 'Current Magento Version : ' . $currentMagentoVersion . '', - 'Current n98-magerun2 Version: ' . $this->application->getVersion() . '', - '', - '', - 'Please download an older version of n98-magerun2.', - '', - 'Visit: https://files.magerun.net/old_versions.php', - '', - ' Magento 2.2.x => n98-magerun2 v3.2.0', - ' Magento 2.1.x => n98-magerun2 v3.2.0', - ' Magento 2.0.x => n98-magerun2 v2.3.3', - '', - '', - ]); - - exit(1); + // We cannot check if no version is defined + if (!$this->isStableVersion($currentMagentoVersion)) { + return; + } + + if ($productMetadata->getName() === 'Mage-OS') { + $this->checkMageOsDistribution($currentMagentoVersion, $event); + return; + } + + if ($productMetadata->getName() === 'Magento') { + $this->checkMagentoDistribution($currentMagentoVersion, $event); } } catch (\Exception $e) { // @@ -127,4 +115,50 @@ private function isStableVersion(string $currentMagentoVersion): bool { return preg_match('/^\d+\.\d+\.\d+$/', $currentMagentoVersion); } + + /** + * Check if the current Mage-OS version is compatible with the current n98-magerun2 version + * + * @param $currentMagentoVersion + * @param ConsoleEvent $event + * @return void + */ + protected function checkMageOsDistribution($currentMagentoVersion, ConsoleEvent $event): void + { + // currently there is no incompatible version available + } + + /** + * @param $currentMagentoVersion + * @param ConsoleEvent $event + * @return void + */ + protected function checkMagentoDistribution($currentMagentoVersion, ConsoleEvent $event): void + { + if (version_compare($currentMagentoVersion, '2.3.0', '<')) { + $output = $event->getOutput(); + $output->writeln([ + '', + 'You are running an incompatible version of n98-magerun2!', + 'Your shop version has to be >2.3.0', + '', + '', + 'Current Magento Version : ' . $currentMagentoVersion . '', + 'Current n98-magerun2 Version: ' . $this->application->getVersion() . '', + '', + '', + 'Please download an older version of n98-magerun2.', + '', + 'Visit: https://files.magerun.net/old_versions.php', + '', + ' Magento 2.2.x => n98-magerun2 v3.2.0', + ' Magento 2.1.x => n98-magerun2 v3.2.0', + ' Magento 2.0.x => n98-magerun2 v2.3.3', + '', + '', + ]); + + exit(1); + } + } }