From 6a921d8e3ed32161fafe34ad762b8f7d60925c30 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Wed, 24 May 2023 19:05:58 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Use=20PHP=20Guard=20when=20remov?= =?UTF-8?q?ing=20a=20PHP=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP Monitor.xcodeproj/project.pbxproj | 12 ++++++------ .../Homebrew/Commands/RemovePhpVersionCommand.swift | 9 +++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 78030cf..ed8e4a3 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -3352,7 +3352,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1240; + CURRENT_PROJECT_VERSION = 1245; DEAD_CODE_STRIPPING = YES; DEBUG = YES; DEVELOPMENT_TEAM = 8M54J5J787; @@ -3382,7 +3382,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1240; + CURRENT_PROJECT_VERSION = 1245; DEAD_CODE_STRIPPING = YES; DEBUG = NO; DEVELOPMENT_TEAM = 8M54J5J787; @@ -3620,7 +3620,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1240; + CURRENT_PROJECT_VERSION = 1245; DEAD_CODE_STRIPPING = YES; DEBUG = NO; DEVELOPMENT_TEAM = 8M54J5J787; @@ -3734,7 +3734,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1240; + CURRENT_PROJECT_VERSION = 1245; DEAD_CODE_STRIPPING = YES; DEBUG = YES; DEVELOPMENT_TEAM = 8M54J5J787; @@ -3848,7 +3848,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1240; + CURRENT_PROJECT_VERSION = 1245; DEAD_CODE_STRIPPING = YES; DEBUG = YES; DEVELOPMENT_TEAM = 8M54J5J787; @@ -4027,7 +4027,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1240; + CURRENT_PROJECT_VERSION = 1245; DEAD_CODE_STRIPPING = YES; DEBUG = NO; DEVELOPMENT_TEAM = 8M54J5J787; diff --git a/phpmon/Domain/Integrations/Homebrew/Commands/RemovePhpVersionCommand.swift b/phpmon/Domain/Integrations/Homebrew/Commands/RemovePhpVersionCommand.swift index c8eb40f..e1d3612 100644 --- a/phpmon/Domain/Integrations/Homebrew/Commands/RemovePhpVersionCommand.swift +++ b/phpmon/Domain/Integrations/Homebrew/Commands/RemovePhpVersionCommand.swift @@ -11,12 +11,14 @@ import Foundation class RemovePhpVersionCommand: BrewCommand { let formula: String let version: String + let phpGuard: PhpGuard init(formula: String) { self.version = formula .replacingOccurrences(of: "php@", with: "") .replacingOccurrences(of: "shivammathur/php/", with: "") self.formula = formula + self.phpGuard = PhpGuard() } func execute(onProgress: @escaping (BrewCommandProgress) -> Void) async throws { @@ -55,8 +57,15 @@ class RemovePhpVersionCommand: BrewCommand { if process.terminationStatus <= 0 { onProgress(.create(value: 0.95, title: progressTitle, description: "Reloading PHP versions...")) + await PhpEnvironments.detectPhpVersions() + await MainMenu.shared.refreshActiveInstallation() + + if let version = phpGuard.currentVersion { + await MainMenu.shared.switchToPhpVersionAndWait(version, silently: true) + } + onProgress(.create(value: 1, title: progressTitle, description: "The operation has succeeded.")) } else { throw BrewCommandError(error: "The command failed to run correctly.", log: loggedMessages)