mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 20:10:08 +02:00
✨ Add site isolation to ValetInteractor
This commit is contained in:
@ -91,7 +91,7 @@
|
|||||||
</CommandLineArgument>
|
</CommandLineArgument>
|
||||||
<CommandLineArgument
|
<CommandLineArgument
|
||||||
argument = "--configuration:~/.phpmon_fconf_working.json"
|
argument = "--configuration:~/.phpmon_fconf_working.json"
|
||||||
isEnabled = "YES">
|
isEnabled = "NO">
|
||||||
</CommandLineArgument>
|
</CommandLineArgument>
|
||||||
<CommandLineArgument
|
<CommandLineArgument
|
||||||
argument = "--configuration:~/.phpmon_fconf_broken.json"
|
argument = "--configuration:~/.phpmon_fconf_broken.json"
|
||||||
|
@ -18,7 +18,7 @@ class ServicesManager: ObservableObject {
|
|||||||
@Published var services: [String: ServiceWrapper] = [:]
|
@Published var services: [String: ServiceWrapper] = [:]
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
Log.info("Initializing ServicesManager")
|
Log.info("Initializing ServicesManager...")
|
||||||
|
|
||||||
formulae = [
|
formulae = [
|
||||||
Homebrew.Formulae.php,
|
Homebrew.Formulae.php,
|
||||||
|
@ -110,32 +110,41 @@ extension DomainListVC {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#warning("ValetInteractor needs to be used here instead of directly issuing commands to valet")
|
|
||||||
@objc func isolateSite(sender: PhpMenuItem) {
|
@objc func isolateSite(sender: PhpMenuItem) {
|
||||||
let command = "sudo \(Paths.valet) isolate php@\(sender.version) --site '\(self.selectedSite!.name)' && exit;"
|
guard let site = selectedSite else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
self.performAction(command: command) {
|
waitAndExecute {
|
||||||
self.selectedSite!.determineIsolated()
|
do {
|
||||||
self.selectedSite!.determineComposerPhpVersion()
|
// Instruct Valet to isolate a given PHP version
|
||||||
|
try await site.isolate(version: sender.version)
|
||||||
if self.selectedSite!.isolatedPhpVersion == nil {
|
// Reload the UI
|
||||||
BetterAlert()
|
self.reloadSelectedRow()
|
||||||
.withInformation(
|
} catch {
|
||||||
title: "domain_list.alerts_isolation_failed.title".localized,
|
// Notify the user about a failed command
|
||||||
subtitle: "domain_list.alerts_isolation_failed.subtitle".localized,
|
let error = error as! ValetInteractionError
|
||||||
description: "domain_list.alerts_isolation_failed.desc".localized(command)
|
self.notifyAboutFailedSiteIsolation(command: error.command)
|
||||||
)
|
|
||||||
.withPrimary(text: "OK")
|
|
||||||
.show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#warning("ValetInteractor needs to be used here instead of directly issuing commands to valet")
|
|
||||||
@objc func removeIsolatedSite() {
|
@objc func removeIsolatedSite() {
|
||||||
self.performAction(command: "sudo \(Paths.valet) unisolate --site '\(self.selectedSite!.name)' && exit;") {
|
guard let site = selectedSite else {
|
||||||
self.selectedSite!.isolatedPhpVersion = nil
|
return
|
||||||
self.selectedSite!.determineComposerPhpVersion()
|
}
|
||||||
|
|
||||||
|
waitAndExecute {
|
||||||
|
do {
|
||||||
|
// Instruct Valet to remove isolation
|
||||||
|
try await site.unisolate()
|
||||||
|
// Reload the UI
|
||||||
|
self.reloadSelectedRow()
|
||||||
|
} catch {
|
||||||
|
// Notify the user about a failed command
|
||||||
|
let error = error as! ValetInteractionError
|
||||||
|
self.notifyAboutFailedSiteIsolation(command: error.command)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,4 +223,15 @@ extension DomainListVC {
|
|||||||
.withPrimary(text: "OK")
|
.withPrimary(text: "OK")
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func notifyAboutFailedSiteIsolation(command: String) {
|
||||||
|
BetterAlert()
|
||||||
|
.withInformation(
|
||||||
|
title: "domain_list.alerts_isolation_failed.title".localized,
|
||||||
|
subtitle: "domain_list.alerts_isolation_failed.subtitle".localized,
|
||||||
|
description: "domain_list.alerts_isolation_failed.desc".localized(command)
|
||||||
|
)
|
||||||
|
.withPrimary(text: "OK")
|
||||||
|
.show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,8 +69,36 @@ class ValetInteractor {
|
|||||||
await Actions.restartNginx()
|
await Actions.restartNginx()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func isolate(site: ValetSite, version: PhpVersionNumber) async throws {
|
public func isolate(site: ValetSite, version: String) async throws {
|
||||||
// TODO
|
let command = "sudo \(Paths.valet) isolate php@\(version) --site '\(site.name)'"
|
||||||
|
|
||||||
|
// Run the command
|
||||||
|
await Shell.quiet(command)
|
||||||
|
|
||||||
|
// Check if the secured status has actually changed
|
||||||
|
site.determineIsolated()
|
||||||
|
site.determineComposerPhpVersion()
|
||||||
|
|
||||||
|
// If the version is not isolated, this failed
|
||||||
|
if site.isolatedPhpVersion == nil {
|
||||||
|
throw ValetInteractionError(command: command)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func unisolate(site: ValetSite) async throws {
|
||||||
|
let command = "sudo \(Paths.valet) unisolate --site '\(site.name)'"
|
||||||
|
|
||||||
|
// Run the command
|
||||||
|
await Shell.quiet(command)
|
||||||
|
|
||||||
|
// Check if the secured status has actually changed
|
||||||
|
site.determineIsolated()
|
||||||
|
site.determineComposerPhpVersion()
|
||||||
|
|
||||||
|
// If the version is somehow still isolated, this failed
|
||||||
|
if site.isolatedPhpVersion != nil {
|
||||||
|
throw ValetInteractionError(command: command)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func unlink(site: ValetSite) async throws {
|
public func unlink(site: ValetSite) async throws {
|
||||||
|
@ -269,10 +269,14 @@ class ValetSite: ValetListable {
|
|||||||
try await ValetInteractor.shared.toggleSecure(site: self)
|
try await ValetInteractor.shared.toggleSecure(site: self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isolate(version: PhpVersionNumber) async throws {
|
func isolate(version: String) async throws {
|
||||||
try await ValetInteractor.shared.isolate(site: self, version: version)
|
try await ValetInteractor.shared.isolate(site: self, version: version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func unisolate() async throws {
|
||||||
|
try await ValetInteractor.shared.unisolate(site: self)
|
||||||
|
}
|
||||||
|
|
||||||
func unlink() async {
|
func unlink() async {
|
||||||
try! await ValetInteractor.shared.unlink(site: self)
|
try! await ValetInteractor.shared.unlink(site: self)
|
||||||
}
|
}
|
||||||
|
@ -112,8 +112,8 @@
|
|||||||
"domain_list.tooltips.isolated" = "This domain is isolated and using PHP %@ instead of the globally linked PHP.";
|
"domain_list.tooltips.isolated" = "This domain is isolated and using PHP %@ instead of the globally linked PHP.";
|
||||||
"domain_list.tooltips.checkmark" = "This domain is being served with a version of PHP that is compatible with this requirement (PHP %@). Click on the PHP version next to this checkmark to find out more information about how this requirement was determined.";
|
"domain_list.tooltips.checkmark" = "This domain is being served with a version of PHP that is compatible with this requirement (PHP %@). Click on the PHP version next to this checkmark to find out more information about how this requirement was determined.";
|
||||||
|
|
||||||
"domain_list.alerts_isolation_failed.title" = "Oops! Site Not Isolated";
|
"domain_list.alerts_isolation_failed.title" = "Oops! Site Isolation Not Applied";
|
||||||
"domain_list.alerts_isolation_failed.subtitle" = "Something went wrong trying to isolate this site. If this is your default site but it is not linked, I recommend manually linking the site prior to setting up isolation.";
|
"domain_list.alerts_isolation_failed.subtitle" = "Something went wrong trying to change the isolation status for this site. If this is your default site but it is not linked, I recommend manually linking the site prior to setting up isolation.";
|
||||||
"domain_list.alerts_isolation_failed.desc" = "To find out what goes wrong, you can try running the command in your terminal manually: %@";
|
"domain_list.alerts_isolation_failed.desc" = "To find out what goes wrong, you can try running the command in your terminal manually: %@";
|
||||||
|
|
||||||
"domain_list.alerts_status_not_changed.title" = "Oops! SSL Status Not Changed";
|
"domain_list.alerts_status_not_changed.title" = "Oops! SSL Status Not Changed";
|
||||||
|
Reference in New Issue
Block a user