1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-11-07 05:10:06 +01:00

🏗 WIP: Keep track of and restore linked PHP version

This commit is contained in:
2023-04-26 19:49:22 +02:00
parent f9ee63ddf6
commit a21418a608

View File

@@ -38,12 +38,14 @@ class InstallPhpVersionCommand: BrewCommand {
\(Paths.brew) install \(formula) --force \(Paths.brew) install \(formula) --force
""" """
// #error("Must keep track of the active PHP version (if applicable)") // Keep track of the current PHP version prior to executing any operations
let phpGuard = PhpGuard()
// Try to fix permissions
do { do {
try await BrewPermissionFixer().fixPermissions() try await BrewPermissionFixer().fixPermissions()
} catch { } catch {
return throw BrewCommandError(error: "There was an issue fixing permissions.")
} }
let (process, _) = try! await Shell.attach( let (process, _) = try! await Shell.attach(
@@ -61,10 +63,21 @@ class InstallPhpVersionCommand: BrewCommand {
) )
if process.terminationStatus <= 0 { if process.terminationStatus <= 0 {
// Reload and restart PHP versions
onProgress(.create(value: 0.95, title: progressTitle, description: "Reloading PHP versions...")) onProgress(.create(value: 0.95, title: progressTitle, description: "Reloading PHP versions..."))
// Check which version of PHP are now installed
await PhpEnv.detectPhpVersions() await PhpEnv.detectPhpVersions()
// Keep track of the currently installed version
await MainMenu.shared.refreshActiveInstallation() await MainMenu.shared.refreshActiveInstallation()
// #error("Must restore active PHP installation (if applicable)")
// If a PHP version was active prior to running the operations, attempt to restore it
if let version = phpGuard.currentVersion {
await MainMenu.shared.switchToAnyPhpVersion(version)
}
// Let the UI know that the installation has been completed
onProgress(.create(value: 1, title: progressTitle, description: "The installation has succeeded.")) onProgress(.create(value: 1, title: progressTitle, description: "The installation has succeeded."))
} else { } else {
throw BrewCommandError(error: "The command failed to run correctly.") throw BrewCommandError(error: "The command failed to run correctly.")