1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2026-04-03 01:50:09 +02:00

Parallelize unlinking PHP versions

This commit is contained in:
2021-04-14 18:46:33 +02:00
parent 0c0e7fc87d
commit e83d507e79
3 changed files with 65 additions and 24 deletions

View File

@@ -218,6 +218,12 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
} }
} }
@objc func stopAllServices() {
waitAndExecute {
Actions.stopAllServices()
}
}
@objc func restartNginx() { @objc func restartNginx() {
waitAndExecute { waitAndExecute {
Actions.restartNginx() Actions.restartNginx()
@@ -289,12 +295,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
// Update the menu // Update the menu
update() update()
// Switch the PHP version let completion = {
Actions.switchToPhpVersion(
version: sender.version,
availableVersions: App.shared.availablePhpVersions
)
// Mark as no longer busy // Mark as no longer busy
App.shared.busy = false App.shared.busy = false
@@ -310,6 +311,14 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
) )
} }
} }
// Switch the PHP version
Actions.switchToPhpVersion(
version: sender.version,
availableVersions: App.shared.availablePhpVersions,
completed: completion
)
}
} }
@objc func openAbout() { @objc func openAbout() {

View File

@@ -78,6 +78,13 @@ class Actions {
brew("services restart dnsmasq", sudo: true) brew("services restart dnsmasq", sudo: true)
} }
public static func stopAllServices()
{
brew("services stop \(App.phpInstall!.formula)", sudo: true)
brew("services stop nginx", sudo: true)
brew("services stop dnsmasq", sudo: true)
}
/** /**
Switching to a new PHP version involves: Switching to a new PHP version involves:
- unlinking the current version - unlinking the current version
@@ -87,18 +94,42 @@ class Actions {
Please note that depending on which version is installed, 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). the version that is switched to may or may not be identical to `php` (without @version).
*/ */
public static func switchToPhpVersion(version: String, availableVersions: [String]) public static func switchToPhpVersion(
{ version: String,
availableVersions: [String],
completed: @escaping () -> Void
) {
print("Switching to \(version)")
let group = DispatchGroup()
group.enter()
var versionsDisabled: [String: Bool] = [:]
availableVersions.forEach { (available) in availableVersions.forEach { (available) in
let formula = (available == App.shared.brewPhpVersion) ? "php" : "php@\(available)" versionsDisabled[available] = false
brew("unlink \(formula)")
brew("services stop \(formula)", sudo: true)
} }
let formula = (version == App.shared.brewPhpVersion) ? "php" : "php@\(version)" availableVersions.forEach { (available) in
DispatchQueue.global(qos: .userInitiated).async {
let formula = (available == App.shared.brewPhpVersion)
? "php" : "php@\(available)"
brew("unlink \(formula)")
brew("services stop \(formula)", sudo: true)
versionsDisabled[available] = true
if !versionsDisabled.values.contains(false) {
group.leave()
}
}
}
group.notify(queue: .global(qos: .userInitiated)) {
let formula = (version == App.shared.brewPhpVersion) ? "php" : "php@\(version)"
brew("link \(formula) --overwrite --force") brew("link \(formula) --overwrite --force")
brew("services start \(formula)", sudo: true) brew("services start \(formula)", sudo: true)
completed()
}
} }
// MARK: - Finding Config Files // MARK: - Finding Config Files

View File

@@ -24,6 +24,7 @@
"mi_restart_dnsmasq" = "Restart service: dnsmasq"; "mi_restart_dnsmasq" = "Restart service: dnsmasq";
"mi_restart_specific" = "Restart specific service"; "mi_restart_specific" = "Restart specific service";
"mi_restart_all_services" = "Restart all services"; "mi_restart_all_services" = "Restart all services";
"mi_stop_all_services" = "Stop all services";
"mi_force_load_latest" = "Force load latest PHP version"; "mi_force_load_latest" = "Force load latest PHP version";
"mi_php_refresh" = "Refresh information"; "mi_php_refresh" = "Refresh information";