fix: replace all deprecated Factory::getDbo()/getApplication() with DI #165

Open
opened 2026-06-29 14:05:18 +00:00 by jmiller · 1 comment
Owner

Summary

The codebase has 40+ calls to Factory::getDbo() and Factory::getApplication() — deprecated in Joomla 5 and removed in Joomla 6. All models already use the correct $this->getDatabase() DI pattern; the standalone engine classes, plugins, CLI commands, and API controllers do not.

Locations — Factory::getDbo()

Engine classes

  • BackupEngine.phprun() method
  • SteppedBackupEngine.php — lines 47, 264, 408, 451, 636, 700, 819
  • SnapshotEngine.php — line 61
  • SnapshotRestoreEngine.php — lines 65, 123, 419, 533
  • PreflightCheck.php — line 42
  • NotificationSender.php — line 265
  • AkeebaImporter.php — line 47

API controllers

  • api/src/Controller/SnapshotsController.php — lines 47, 209, 271
  • api/src/Controller/BackupsController.php — line 41 (new BackupEngine() bypasses DI)

Console commands (all 5)

  • ListCommand.php — line 41
  • CleanupCommand.php — line 47
  • ProfilesCommand.php — line 36
  • RestoreCommand.php — line 45
  • SnapshotCommand.php — lines 161, 214

Plugins

  • plg_actionlog_mokosuitebackup — line 240
  • plg_quickicon_mokosuitebackup — line 42
  • plg_system_mokosuitebackup — lines 173, 245

Install script

  • script.php — 10 occurrences (tolerable in install context but still deprecated)

Locations — Factory::getApplication()

  • BackupEngine.phpdispatchAfterRun() line 809
  • RestoreEngine.php — lines 155–157, 301
  • SnapshotEngine.php — lines 177–178, 201–203, 343
  • SnapshotRestoreEngine.php — lines 161–162, 533–534, 583
  • NotificationSender.php — lines 65, 179, 385, 450

What to do

  • Accept DatabaseInterface via constructor injection in all Engine classes
  • Accept CMSApplicationInterface via constructor injection where needed
  • Update all callers (controllers, console commands, task plugin) to pass injected instances
  • Verify plugins use $this->getDatabase() (available in Joomla 6 plugin base class)
  • API controllers should use $this->getDatabase() from the base controller

Why

Factory::getDbo() and Factory::getApplication() are deprecated in Joomla 5+ and planned for removal. Using DI enables proper testability and follows the pattern already established in all Model classes. BackupStatusHelper at line 31 already uses the correct Factory::getContainer()->get('DatabaseDriver') pattern — the engines should follow suit.

## Summary The codebase has 40+ calls to `Factory::getDbo()` and `Factory::getApplication()` — deprecated in Joomla 5 and removed in Joomla 6. All models already use the correct `$this->getDatabase()` DI pattern; the standalone engine classes, plugins, CLI commands, and API controllers do not. ## Locations — `Factory::getDbo()` ### Engine classes - `BackupEngine.php` — `run()` method - `SteppedBackupEngine.php` — lines 47, 264, 408, 451, 636, 700, 819 - `SnapshotEngine.php` — line 61 - `SnapshotRestoreEngine.php` — lines 65, 123, 419, 533 - `PreflightCheck.php` — line 42 - `NotificationSender.php` — line 265 - `AkeebaImporter.php` — line 47 ### API controllers - `api/src/Controller/SnapshotsController.php` — lines 47, 209, 271 - `api/src/Controller/BackupsController.php` — line 41 (`new BackupEngine()` bypasses DI) ### Console commands (all 5) - `ListCommand.php` — line 41 - `CleanupCommand.php` — line 47 - `ProfilesCommand.php` — line 36 - `RestoreCommand.php` — line 45 - `SnapshotCommand.php` — lines 161, 214 ### Plugins - `plg_actionlog_mokosuitebackup` — line 240 - `plg_quickicon_mokosuitebackup` — line 42 - `plg_system_mokosuitebackup` — lines 173, 245 ### Install script - `script.php` — 10 occurrences (tolerable in install context but still deprecated) ## Locations — `Factory::getApplication()` - `BackupEngine.php` — `dispatchAfterRun()` line 809 - `RestoreEngine.php` — lines 155–157, 301 - `SnapshotEngine.php` — lines 177–178, 201–203, 343 - `SnapshotRestoreEngine.php` — lines 161–162, 533–534, 583 - `NotificationSender.php` — lines 65, 179, 385, 450 ## What to do - [ ] Accept `DatabaseInterface` via constructor injection in all Engine classes - [ ] Accept `CMSApplicationInterface` via constructor injection where needed - [ ] Update all callers (controllers, console commands, task plugin) to pass injected instances - [ ] Verify plugins use `$this->getDatabase()` (available in Joomla 6 plugin base class) - [ ] API controllers should use `$this->getDatabase()` from the base controller ## Why `Factory::getDbo()` and `Factory::getApplication()` are deprecated in Joomla 5+ and planned for removal. Using DI enables proper testability and follows the pattern already established in all Model classes. `BackupStatusHelper` at line 31 already uses the correct `Factory::getContainer()->get('DatabaseDriver')` pattern — the engines should follow suit.
jmiller added the component: engine label 2026-06-29 14:05:18 +00:00
Author
Owner

Branch created: feature/165-fix-replace-factory-getdbo-with-dependen

git fetch origin
git checkout feature/165-fix-replace-factory-getdbo-with-dependen
Branch created: [`feature/165-fix-replace-factory-getdbo-with-dependen`](https://git.mokoconsulting.tech/MokoConsulting/MokoSuiteBackup/src/branch/feature/165-fix-replace-factory-getdbo-with-dependen) ```bash git fetch origin git checkout feature/165-fix-replace-factory-getdbo-with-dependen ```
jmiller changed title from fix: replace Factory::getDbo() with dependency-injected database in BackupEngine to refactor: replace all Factory::getDbo() calls with dependency-injected database across entire codebase 2026-06-29 14:19:45 +00:00
jmiller changed title from refactor: replace all Factory::getDbo() calls with dependency-injected database across entire codebase to fix: replace all deprecated Factory::getDbo()/getApplication() with DI 2026-06-29 14:38:51 +00:00
Sign in to join this conversation.