Data migration: Change to determine M2 version

Currently the M2 version is retrieved from the root composer.json version attribute of the project. When you use that number to update the version number of your project, or that attribute is not available at all it will fail do determine the correct Magento 2 version. 
It’s better to look at the actual version number defined in the require section. Here’s the updated code. 

    public static function getM2Version()
{
$version = '';
$composerFile = Yii::app()->basePath . "/../../../composer.json";
if (file_exists($composerFile)) {
$data = @file_get_contents($composerFile);
$data = json_decode($data);
if (isset($data->require->{'magento/product-community-edition'})) {
$version = trim($data->require->{'magento/product-community-edition'});
}
}
return $version;
}

3 answers

Profile photo of Mall Staff 184060.00 $tone October 31, 2020
Public

Hi Danny,

When you use that number to update the version number of your project, or that attribute is not available at all it will fail do determine the correct Magento 2 version. 
It’s better to look at the actual version number defined in the require section. Here’s the updated code. 

The case you mentioned appears not to be a popular case. Anyway, you can apply that tweak code at your end. Thanks for your sharing though.

Regards,
Mall.
 

#1
Profile photo of Danny Verkade 20.00 $tone November 2, 2020
Public

Even if it’s not popular please note that the version field in the root of the composer.json is not a required field. It’s safer to parse the actual Magento version and this change should be included in the next release of the tool 

#2
Profile photo of Mall Staff 184060.00 $tone November 4, 2020
Public

Hi Danny,

It’s safer to parse the actual Magento version and this change should be included in the next release of the tool 

Yes, we will consider updating that in the next release of our migration tool.
Many thanks for your suggestion.

Regards,
Mall.

#3

Please login or Register to Submit Answer

Written By

Comments