Skip to content

Conversation

@rhoerr
Copy link
Contributor

@rhoerr rhoerr commented Jan 13, 2025

Description (*)

Some extensions use version comparison in Magento to determine what code to run. This is a problem for Mage-OS, where we replace Magento's getVersion() number (IE 2.4.7) with the Mage-OS version (IE 1.0.5), which makes some extensions think it's an old version of Magento and run old incompatible code.

The idea here is:

  • Magento gets the version from composer.lock for magento/product-community-edition, via https://github.com/rhoerr/mageos-magento2/blob/7bed30c9ea2b6e31130d4cead3e191871fb9b98e/lib/internal/Magento/Framework/App/ProductMetadata.php#L118
  • Mage-OS replaces that version number during our existing build/release process.
  • To fix it, we change getVersion to return the equivalent Magento version, and add a separate method to get the Mage-OS version.
  • feat: add upstream version to metapackage composer.json for runtime use generate-mirror-repo-js#189 will store the upstream version as extra.magento_version on the product metapackage composer JSON, which is stored in composer.lock and already read by Magento.
  • getVersion() (via getSystemPackageVersion()) is changed to read that upstream version (like 2.4.7-p3), for intercompatibility with Magento. That will return the equivalent version for releases going forward. Side benefit: it'll be easier to know what the equivalent version being run actually is.
  • A new getDistributionVersion() (via getSystemDistroVersion()) will return the distribution version (like 1.0.5), from the metapackage version. If any code needs to know the exact Mage-OS version, it can use this to get it.
  • All references to version number (admin footer, CLI, /magento_version, swagger) have to be changed to use getDistributionVersion() instead of getVersion().

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes MageOS version #108

Manual testing scenarios (*)

  1. Build a Mage-OS preview release (currently unable to; see related PR above).
  2. Run CLI command bin/magento --version; see output like: Mage-OS CLI 1.0.5 (based on Magento 2.4.7-p3)
  3. Open the admin panel and log in; view the footer. See output like: Mage-OS ver. 1.0.5

Questions or comments

Opening this as a draft PR due to inability to test it end to end, as the build process is currently broken.

Unit/integration tests might be affected and require further attention. I didn't get there yet.

I split getVersion(), but not getName(), which returns Mage-OS rather than Magento. Should that be split too?

I created a new interface DistributionMetadataInterface, on the thinking that third parties could use that (instanceof DistributionMetadataInterface) to help determine whether an install is Mage-OS, and that this would be better for backwards compatibility by not introducing new methods to ProductMetadataInterface. Thoughts?

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Copy link
Contributor

@fballiano fballiano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the fact that the original getVersion() goes back to return the magento version. I see that there's a getDistributionVersion(), is there also a getDistributionName()?

@rhoerr
Copy link
Contributor Author

rhoerr commented Jan 14, 2025

Code changes, for further consideration.

I was able to create a test build with the composer data, so I can try the actual UX aspect now (maybe later this week).

@rhoerr
Copy link
Contributor Author

rhoerr commented Jan 15, 2025

Tested end-to-end with generated packages from the associated PR.

Admin footer:
image

CLI:

$ bin/magento -V
Mage-OS CLI 1.0.5-p24 (based on Magento 2.4.7-p3)

@rhoerr rhoerr marked this pull request as ready for review January 15, 2025 02:06
@rhoerr rhoerr requested a review from a team as a code owner January 15, 2025 02:06
Copy link
Contributor

@fballiano fballiano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this a lot

@rhoerr
Copy link
Contributor Author

rhoerr commented Jan 19, 2025

I fixed unit test errors, those pass now.

Integration tests keep failing for unrelated process errors. I'm not sure if there are any issues caused by these changes.

@fballiano fballiano merged commit 4eb2b41 into mage-os:release/1.x Jan 28, 2025
7 of 8 checks passed
rhoerr added a commit to rhoerr/mageos-magento2 that referenced this pull request Feb 5, 2025
@peterjaap
Copy link
Contributor

peterjaap commented Feb 14, 2025

Just ran into another version check mismatch (I was upgrading to Mage-OS 1.0.6 and trying to test it out on an automated review environment):

[pluim-renovate-mage-os-pro.37-72-165-250.magento2.elgentos.io] run magerun2 -n --root-dir=/data/web/releases/20250214073444 db:add-default-authorization-entries
[pluim-renovate-mage-os-pro.37-72-165-250.magento2.elgentos.io] You are running an incompatible version of n98-magerun2!
[pluim-renovate-mage-os-pro.37-72-165-250.magento2.elgentos.io] Your shop version has to be >2.3.0
[pluim-renovate-mage-os-pro.37-72-165-250.magento2.elgentos.io] Current Magento Version     : 1.0.5
[pluim-renovate-mage-os-pro.37-72-165-250.magento2.elgentos.io] Current n98-magerun2 Version: 7.4.0
[pluim-renovate-mage-os-pro.37-72-165-250.magento2.elgentos.io] Please download an older version of n98-magerun2.
[pluim-renovate-mage-os-pro.37-72-165-250.magento2.elgentos.io] Visit: https://files.magerun.net/old_versions.php
[pluim-renovate-mage-os-pro.37-72-165-250.magento2.elgentos.io]     Magento 2.2.x => n98-magerun2 v3.2.0
[pluim-renovate-mage-os-pro.37-72-165-250.magento2.elgentos.io]     Magento 2.1.x => n98-magerun2 v3.2.0
[pluim-renovate-mage-os-pro.37-72-165-250.magento2.elgentos.io]     Magento 2.0.x => n98-magerun2 v2.3.3
[pluim-renovate-mage-os-pro.37-72-165-250.magento2.elgentos.io]  error  in review.php on line 231:
[pluim-renovate-mage-os-pro.37-72-165-250.magento2.elgentos.io] exit code 1 (General error)

This wasn't an issue with 1.0.5;

~/current$ cat composer.json |grep mage-os/product
        "mage-os/product-community-edition": "1.0.5",
~/current$ magerun2 sys:info
| Name                                             | Mage-OS                                                                                                                                                                                                                                       |
| Version                                          | 1.0.5   

But it is on 1.0.6 (same magerun2 version);

~/release$ cat composer.json |grep mage-os/product
        "mage-os/product-community-edition": "1.0.6",
~/release$ magerun2 sys:info

You are running an incompatible version of n98-magerun2!
Your shop version has to be >2.3.0


Current Magento Version     : 1.0.5
Current n98-magerun2 Version: 7.4.0


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

Using the latest magerun2 doesn't help;

~/release$ ./n98-magerun2.phar db:add-default-authorization-entries

You are running an incompatible version of n98-magerun2!
Your shop version has to be >2.3.0


Current Magento Version     : 1.0.5
Current n98-magerun2 Version: 7.5.0

Workaround for now is; magerun2 db:add-default-authorization-entries --skip-magento-compatibility-check

@rhoerr
Copy link
Contributor Author

rhoerr commented Feb 14, 2025

@peterjaap That's strange. Any idea why it's picking up the version as 1.0.5 despite updating to 1.0.6?

Probably Magerun2 has its own detection code for Mage-OS that got broken by the changes here. We'll have to coordinate that with them.

@fballiano
Copy link
Contributor

Hey @cmuench, sorry to bother but I think you're the right person to see what's happening here 😅🙏

@fballiano fballiano mentioned this pull request Feb 18, 2025
@cmuench
Copy link
Contributor

cmuench commented Feb 18, 2025

@fballiano I will have a look on that. Magerun is already prepared in the code. We can then add a logic in that method.

\N98\Magento\Application\Console\EventSubscriber\CheckCompatibility::checkMageOsDistribution

image

@rhoerr rhoerr deleted the feat/getversion-compatibility branch March 10, 2025 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants