1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-06 19:40:08 +02:00

Perform cleanup when removing extensions

This commit is contained in:
2023-11-26 22:03:25 +01:00
parent a7d5950aa0
commit 2fe3a4b7eb

View File

@ -26,6 +26,13 @@ class RemovePhpExtensionCommand: BrewCommand {
description: "phpman.steps.removing".localized("`\(phpExtension.name)`...")
))
// Keep track of the file that contains the information about the extension
let existing = PhpEnvironments.shared.cachedPhpInstallations[phpExtension.phpVersion]?.extensions.first(where: { ext in
ext.name == phpExtension.name
})
onProgress(.create(value: 1, title: getCommandTitle(), description: "phpman.steps.success".localized))
let command = """
export HOMEBREW_NO_INSTALL_UPGRADE=true; \
export HOMEBREW_NO_INSTALL_CLEANUP=true; \
@ -48,15 +55,35 @@ class RemovePhpExtensionCommand: BrewCommand {
if process.terminationStatus <= 0 {
onProgress(.create(value: 0.95, title: getCommandTitle(), description: "phpman.steps.reloading".localized))
if let ext = existing {
await performExtensionCleanup(for: ext)
}
await PhpEnvironments.detectPhpVersions()
await MainMenu.shared.refreshActiveInstallation()
#warning("Remaining config files should be cleaned up")
onProgress(.create(value: 1, title: getCommandTitle(), description: "phpman.steps.success".localized))
} else {
throw BrewCommandError(error: "phpman.steps.failure".localized, log: loggedMessages)
}
}
private func performExtensionCleanup(for ext: PhpExtension) async {
if ext.file.hasSuffix("20-\(ext.name).ini") {
// The extension's default configuration file can be removed
Log.info("The extension was found in a default extension .ini location. Purging that .ini file.")
do {
try FileSystem.remove(ext.file)
} catch {
Log.err("The file `\(ext.file)` could not be removed.")
}
} else {
// The extension's default configuration file cannot be removed, it should be disabled instead
Log.info("The extension was not found in a default location. Disabling the extension only.")
if ext.enabled {
await ext.toggle()
}
}
}
}