|
12 | 12 | use BigBridge\ProductImport\Model\Resource\Serialize\SerializeValueSerializer; |
13 | 13 | use BigBridge\ProductImport\Model\Resource\Serialize\ValueSerializer; |
14 | 14 | use Exception; |
| 15 | +use Magento\Framework\App\ObjectManager; |
| 16 | +use Magento\Framework\App\ProductMetadata; |
15 | 17 |
|
16 | 18 | /** |
17 | 19 | * Pre-loads all meta data needed for the core processes once. |
@@ -415,14 +417,20 @@ protected function detectMagentoVersion() |
415 | 417 | // $productMetadata = new \Magento\Framework\App\ProductMetadata(); |
416 | 418 | // $version = $productMetadata->getVersion(); |
417 | 419 | // |
418 | | - // But is takes 0.2 seconds to execute, this is too long |
| 420 | + // But it takes up to 0.2 seconds to execute, this is too long |
419 | 421 | // See also https://magento.stackexchange.com/questions/96858/how-to-get-magento-version-in-magento2-equivalent-of-magegetversion |
| 422 | + // |
| 423 | + // However, if magento/magento2-base is not deployed, it falls back to the official method |
| 424 | + // See https://github.com/bigbridge-nl/product-import/issues/45 |
420 | 425 |
|
421 | | - if (preg_match('/"version": "([^\"]+)"/', |
422 | | - file_get_contents(BP . '/vendor/magento/magento2-base/composer.json'), $matches)) { |
| 426 | + $composerFile = BP . '/vendor/magento/magento2-base/composer.json'; |
423 | 427 |
|
| 428 | + if (!file_exists($composerFile)) { |
| 429 | + $productMetadata = ObjectManager::getInstance()->get(ProductMetadata::class); |
| 430 | + $magentoVersion = $productMetadata->getVersion(); |
| 431 | + } else if (preg_match('/"version": "([^\"]+)"/', |
| 432 | + file_get_contents($composerFile), $matches)) { |
424 | 433 | $magentoVersion = $matches[1]; |
425 | | - |
426 | 434 | } else { |
427 | 435 | throw new Exception("Magento version could not be detected."); |
428 | 436 | } |
|
0 commit comments