Skip to content

refactor: restructure upgrade keys#37

Open
yCodeTech wants to merge 9 commits intomasterfrom
refactor/restructure-upgrade-keys
Open

refactor: restructure upgrade keys#37
yCodeTech wants to merge 9 commits intomasterfrom
refactor/restructure-upgrade-keys

Conversation

@yCodeTech
Copy link
Owner

@yCodeTech yCodeTech commented Mar 25, 2026

This pull request refactors how upgrade state is tracked in the configuration, consolidating upgrade keys under a single upgrades array and improving configuration key management. The changes also add helper methods for manipulating nested configuration keys using Laravel's array helpers.

Configuration management improvements:

  • Added removeKey method in Configuration.php to remove nested configuration values using Laravel's Arr::forget helper, allowing for dot notation.

  • Changed updateKey method in Configuration.php to use Laravel's Arr::set helper, allowing for dot notation and more flexible configuration updates.

Upgrade state tracking refactor:

  • Consolidated upgrade keys (such as symlinks_upgraded and php_port_overrides_upgraded) under a new upgrades array in the configuration, with new names symlinks and nginx_site_php_port_overrides.

  • Added new helper methods isUpgraded and markAsUpgraded to access the new upgrades config format and improve upgrade tracking consistency.

  • Added a migration method (migrateSymlinksUpgradeKey) to move the legacy symlinks_upgraded key to the new upgrades.symlinks key and clean up the old key, ensuring backward compatibility and config cleanliness. This prevents the breaking change from being a breaking change.

    Note: The symlinks_upgraded is the only legacy key that needs to be migrated. The php_port_overrides_upgraded key wasn't released in a stable version, so it doesn't need migrating.

  • Replaced the shouldUpgradeNginxSitePhpPortOverrides and shouldUpgradeSymbolicLinks method calls with a direct call to isUpgraded method.

  • Removed the now unused shouldUpgradeNginxSitePhpPortOverrides and shouldUpgradeSymbolicLinks methods.

These changes make the upgrade process more robust and future proof and the configuration file easier to maintain.

- Added a new `Upgrader::isUpgraded` method to determine if the named upgrade has already been completed.

- Replaced the direct config access in the Upgrader methods `shouldUpgradeSymbolicLinks`  and `shouldUpgradeNginxSitePhpPortOverrides` to use the new `isUpgraded` method.

- Refactored `Configuration::updateKey` method to use Laravel's `Arr::set` method to set a value within an array instead of the direct array access. It enables usage of dot notation to easily access deeply nested array keys.
- Added a new `Upgrader::markAsUpgraded` method to mark an upgrade as completed, and add a key into Valet's config.

- Replaced the direct config `updateKey` in the Upgrader methods `upgradeSymbolicLinks`  and `upgradeNginxSitePhpPortOverrides` to use the new `markAsUpgraded` method.
@yCodeTech yCodeTech added the enhancement A quality of life enhancement label Mar 25, 2026
- Replaced the `shouldUpgradeNginxSitePhpPortOverrides` method call with a direct call to `isUpgraded` method for improved clarity and conciseness. The former method was only a light wrapper around `isUpgraded` method anyway.

- Removed the now unused `shouldUpgradeNginxSitePhpPortOverrides` method.
The new format allows for multiple one-time upgrade keys to be stored in an organised manner under the `upgrades` array. This stops valet's config from being polluted with many top-level `*_upgraded` config keys when new one-time upgrades are added in the future.

- Changed the `symlinks_upgraded` key to `symlinks`.

- Changed the `php_port_overrides_upgraded` key to `nginx_site_php_port_overrides`.

- Changed the config `get` and `updateKey` calls in `isUpgraded` and `markAsUpgraded` methods to use dot notation to get/update the specified upgrade key from the new top-level `upgrades`.
- Added `Upgrader::migrateSymlinksUpgradeKey` method to handle the transition from `symlinks_upgraded` to `symlinks`.

Note: The `symlinks_upgraded` is the only legacy key that needs to be migrated. The `php_port_overrides_upgraded` key wasn't released in a stable version, so it doesn't need migrating.

- Added `Configuration::removeKey` method to remove a specified key from the config.
- Changed the `hasNewKey` variable value in `migrateSymlinksUpgradeKey` method to use the `isUpgraded` method since it does the same job.
- Replace `shouldUpgradeSymbolicLinks` method with inline condition to check if symlinks have not been upgraded and if the sites directory is not empty.

- Removed the now unused `shouldUpgradeSymbolicLinks` method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement A quality of life enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant