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
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.
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
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.