Skip to content

Commit b3f2f1f

Browse files
Fallback Magento version detection when magento/magento2-base is not available
1 parent 9420451 commit b3f2f1f

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
# 1.7.2 : Use official Magento version detection when magento/magento2-base is not available
4+
5+
As mentioned by Pieter Hoste, magento/magento2-base may not be available; in this case the official version detection will now be used.
6+
37
# 1.7.1 : More robust when handling non-existing categories.
48

59
Stronger getCategoryInfo check when fetching parent categories. Pull request by Duckↄhip.

Model/Resource/MetaData.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use BigBridge\ProductImport\Model\Resource\Serialize\SerializeValueSerializer;
1313
use BigBridge\ProductImport\Model\Resource\Serialize\ValueSerializer;
1414
use Exception;
15+
use Magento\Framework\App\ObjectManager;
16+
use Magento\Framework\App\ProductMetadata;
1517

1618
/**
1719
* Pre-loads all meta data needed for the core processes once.
@@ -415,14 +417,20 @@ protected function detectMagentoVersion()
415417
// $productMetadata = new \Magento\Framework\App\ProductMetadata();
416418
// $version = $productMetadata->getVersion();
417419
//
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
419421
// 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
420425

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';
423427

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)) {
424433
$magentoVersion = $matches[1];
425-
426434
} else {
427435
throw new Exception("Magento version could not be detected.");
428436
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This library imports product data into Magento 2 via direct database queries. It
66

77
* A programming library to import products
88
* An CLI command for product import via XML file
9-
* An Web API service for product import via Post Request with XML
9+
* A web API service for product import via Post Request with XML
1010
* A tool to update url_rewrites
1111

1212
## Note

0 commit comments

Comments
 (0)