Refactor Backupper and Updater as services and add more options to name backups#873
Refactor Backupper and Updater as services and add more options to name backups#873
Backupper and Updater as services and add more options to name backups#873Conversation
There was a problem hiding this comment.
Pull request overview
This PR moves Backupper and Updater to be resolved via the app service container (instead of manual instantiation) and expands runtime configurability for update and backup operations, including more descriptive backup naming.
Changes:
- Register
BackupperandUpdateras container services and refactor controllers/commands to receive/resolve them via DI. - Extend
Updaterwith runtime options (force,preferDistAssets,cleanupAfterInstall) and adjust version eligibility logic. - Enhance backup filename generation with interpolated variables (hostname/site/context/version/random) and update the default backup name format.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| formwork/src/Updater/Updater.php | Adds runtime options to update/check flows; refactors release loading and version comparison logic. |
| formwork/src/Services/Loaders/PanelServiceLoader.php | Removes local Updater service definition in favor of global service registration. |
| formwork/src/Panel/Controllers/UpdatesController.php | Injects Backupper via DI for pre-update backups and uses DI-provided Updater. |
| formwork/src/Panel/Controllers/ToolsController.php | Injects Backupper via DI for listing backups. |
| formwork/src/Panel/Controllers/BackupController.php | Injects Backupper via DI for creating panel-triggered backups. |
| formwork/src/Commands/UpdatesCommand.php | Switches to container-resolved Updater/Backupper and passes runtime flags as method options. |
| formwork/src/Commands/BackupCommand.php | Switches to container-resolved Backupper and passes hostname at call time. |
| formwork/src/Cms/App.php | Registers Backupper and Updater in the main container with config-derived options. |
| formwork/src/Backup/Backupper.php | Adds interpolated, length-limited backup filenames and optional name/hostname parameters. |
| formwork/config/system.yaml | Updates default backup naming template to include {{hostname}}. |
Comments suppressed due to low confidence (1)
formwork/src/Updater/Updater.php:214
loadRelease()returns early once$this->releaseis set, even if a later call passes a different$preferDistAssetsvalue (e.g.checkUpdates(force: true, preferDistAssets: false)after an earlier check). This makes the new runtime option ineffective within the same Updater instance. Track the previously-usedpreferDistAssetsand reload when it changes (or remove theisset($this->release)cache / include the preference in the cache key).
private function loadRelease(bool $preferDistAssets = true): void
{
if (isset($this->release)) {
return;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $filename = rtrim(substr($name, 0, 75 - strlen($suffix)), '-_') . $suffix; | ||
|
|
There was a problem hiding this comment.
$filename is derived from interpolated input and then passed into FileSystem::joinPaths($path, $filename). Because joinPaths normalizes .. segments, a name containing path separators (e.g. "../") can escape the configured backup directory. Sanitize the interpolated name to a safe basename (strip / and \, collapse .., and ideally restrict to a whitelist of filename characters) before joining, and consider rejecting/normalizing absolute paths.
| $filename = rtrim(substr($name, 0, 75 - strlen($suffix)), '-_') . $suffix; | |
| // Sanitize name to a safe filename: remove path separators and restrict characters | |
| $safeName = preg_replace('/[\/\\\\]+/', '-', $name); | |
| $safeName = preg_replace('/[^A-Za-z0-9._-]/', '-', $safeName); | |
| $filename = rtrim(substr($safeName, 0, 75 - strlen($suffix)), '-_') . $suffix; |
This pull request refactors how the
BackupperandUpdaterservices are instantiated and used throughout the application, moving from manual instantiation to dependency injection via the service container. It also enhances the backup filename generation to be more flexible and informative, and updates theUpdaterclass to accept runtime options for more granular control. These changes simplify controller and command code, improve maintainability, and increase the configurability of backup and update operations.Dependency Injection & Service Container Integration:
BackupperandUpdateracross controllers and commands to use the service container, removing manual construction and related helper methods. This centralizes configuration and makes dependency management cleaner and more consistent. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]Backup Filename and Options Improvements:
Backupperto use an interpolated, customizable format with variables like hostname, site, context, version, and a random string, making backup files more descriptive and unique. The date format in filenames was also updated for better readability.Backupper::backupmethod now accepts optionalnameandhostnameparameters for greater flexibility.Updater Service Enhancements:
Updaterclass to accept runtime options forforce,preferDistAssets, andcleanupAfterInstallin itscheckUpdatesandupdatemethods, allowing for more dynamic update behavior. [1] [2] [3] [4] [5]Codebase Simplification & Cleanup:
BackupperandUpdater, further streamlining the codebase. [1] [2] [3] [4]These changes collectively make the backup and update features more robust, maintainable, and user-friendly.