1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 03:50:08 +02:00

👌 Clean up switchToPhpVersion() and fixMyPhp()

This commit is contained in:
2020-12-19 18:38:00 +01:00
parent c7a0e25336
commit e73474e30c

View File

@ -51,29 +51,25 @@ class Actions {
Shell.user.run("sudo brew services restart nginx")
}
/**
Switching to a new PHP version involves:
- unlinking the current version
- stopping the active services
- linking the new desired version
Please note that depending on which version is installed,
the version that is switched to may or may not be identical to `php` (without @version).
*/
public static func switchToPhpVersion(version: String, availableVersions: [String]) {
availableVersions.forEach { (version) in
// Unlink the current version
Shell.user.run("brew unlink php@\(version)")
// Stop the services
if (version == App.shared.brewPhpVersion) {
Shell.user.run("sudo brew services stop php")
} else {
Shell.user.run("sudo brew services stop php@\(version)")
}
}
if (availableVersions.contains(App.shared.brewPhpVersion)) {
// Use the latest version as a default
Shell.user.run("brew link php@\(App.shared.brewPhpVersion) --overwrite --force")
if (version == App.shared.brewPhpVersion) {
// If said version was also requested, all we need to do is start the service
Shell.user.run("sudo brew services start php")
} else {
// Otherwise, link the correct php version + start the correct service
Shell.user.run("brew link php@\(version) --overwrite --force")
Shell.user.run("sudo brew services start php@\(version)")
}
availableVersions.forEach { (available) in
let formula = (available == App.shared.brewPhpVersion) ? "php" : "php@\(available)"
Shell.user.run("brew unlink \(formula)")
Shell.user.run("sudo brew services stop \(formula)")
}
let formula = (version == App.shared.brewPhpVersion) ? "php" : "php@\(version)"
Shell.user.run("brew link \(formula) --overwrite --force")
Shell.user.run("sudo brew services start \(formula)")
}
public static func openGenericPhpConfigFolder() {
@ -120,8 +116,11 @@ class Actions {
Shell.user.run(command)
}
// unlink all the crap and link the latest version
// this also restarts all services
/**
Detects all currently available PHP versions, and unlinks each and every one of them.
After this, the brew services are also stopped, the latest PHP version is linked, and php + nginx are restarted.
If this does not solve the issue, the user may need to install additional extensions and/or run `composer global update`.
*/
public static func fixMyPhp() {
let versions = self.detectPhpVersions()
versions.forEach { (version) in