Skip to content

Decouple setup/ runtime classes from production artifact#40696

Open
lbajsarowicz wants to merge 1 commit intomagento:2.4-developfrom
lbajsarowicz:refactor/decouple-setup-from-runtime
Open

Decouple setup/ runtime classes from production artifact#40696
lbajsarowicz wants to merge 1 commit intomagento:2.4-developfrom
lbajsarowicz:refactor/decouple-setup-from-runtime

Conversation

@lbajsarowicz
Copy link
Copy Markdown
Contributor

Summary

Moves runtime-critical classes out of the setup/ directory into lib/internal/Magento/Framework/ so that setup/ can be safely excluded from production deployments without breaking bin/magento.

Currently, every bin/magento invocation — including cache:flush, indexer:reindex, cron:run — crashes if setup/ is missing, because Cli.php unconditionally requires setup/config/application.config.php and app/etc/di.xml maps core interfaces to Magento\Setup\* classes.

This is the first backwards-compatible step toward fully removing setup/ from production artifacts.

Changes

1. Move runtime DI implementations to Framework

  • Magento\Setup\Module\SetupMagento\Framework\Setup\SchemaSetup
  • Magento\Setup\Module\DataSetupMagento\Framework\Setup\ModuleDataSetup
  • Magento\Setup\Module\Setup\SetupCacheMagento\Framework\Setup\SetupCache
  • Updated app/etc/di.xml preferences to point to new Framework classes

2. Move AbstractSetupCommand to Framework

  • Magento\Setup\Console\Command\AbstractSetupCommandMagento\Framework\Console\Command\AbstractSetupCommand
  • Updated Magento\Backend maintenance commands to use new namespace

3. Make Cli.php setup-tolerant

  • Cli::__construct() now checks file_exists() before loading setup/config/application.config.php
  • When setup/ is absent, non-setup commands (cache:*, indexer:*, cron:*) work normally
  • Setup commands are simply unavailable (not registered) — no crash

4. Backwards compatibility

All old classes in setup/src/ now extend their new Framework counterparts:

// setup/src/Magento/Setup/Module/Setup.php
/** @deprecated Use \Magento\Framework\Setup\SchemaSetup instead */
class Setup extends \Magento\Framework\Setup\SchemaSetup {}

Third-party extensions using Magento\Setup\* classes continue to work without changes.

Test plan

  • bin/magento setup:upgrade works with setup/ present
  • bin/magento setup:di:compile works with setup/ present
  • bin/magento cache:flush works with setup/ present
  • bin/magento cache:flush works with setup/ removed (new capability)
  • bin/magento indexer:reindex works with setup/ removed
  • Extensions extending Magento\Setup\Module\Setup still work (BC alias)
  • Extensions extending Magento\Setup\Console\Command\AbstractSetupCommand still work (BC alias)
  • maintenance:status, maintenance:enable, maintenance:allow-ips commands work

Resolves #40695

⭐ Support my work

Do you like the fix? Remember to react with "👍🏻" to get it merged faster,
Then Sponsor me on Github so I can spend more time on fixing issues like this one.

Learn more at https://github.com/sponsors/lbajsarowicz

…pendency

Move runtime-critical classes out of setup/ into Framework so that
setup/ can be excluded from production deployments without breaking
bin/magento.

Changes:
- Move SchemaSetupInterface impl to Framework\Setup\SchemaSetup
- Move ModuleDataSetupInterface impl to Framework\Setup\ModuleDataSetup
- Move SetupCache to Framework\Setup\SetupCache
- Move AbstractSetupCommand to Framework\Console\Command
- Update app/etc/di.xml preferences to point to Framework classes
- Update Backend maintenance commands to use Framework namespace
- Make Cli.php tolerant of missing setup/ directory (file_exists guard)
- Old setup/ classes now extend Framework ones (backwards compatible)

Resolves: magento#40695
@m2-assistant
Copy link
Copy Markdown

m2-assistant Bot commented Apr 12, 2026

Hi @lbajsarowicz. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@lbajsarowicz
Copy link
Copy Markdown
Contributor Author

@magento run all tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: P3 May be fixed according to the position in the backlog. Progress: pending review

Projects

Status: Pending Review

Development

Successfully merging this pull request may close these issues.

Remove setup/ directory dependency from production artifacts

2 participants